# # Copyright 2026 Aarav Ravindra Kharade # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import os from PIL import Image, ImageDraw, ImageFont def generate_c_data(font_size, char_width, char_height, data_name): try: font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", font_size) except: font = ImageFont.load_default() chars = [chr(i) for i in range(32, 127)] c_data = f"const unsigned char ArkFontRobotoBold_{data_name}[] = {{\n " vals = [] for c in chars: img = Image.new('L', (char_width, char_height), color=0) draw = ImageDraw.Draw(img) # Use a fixed baseline x = char_width * 0.1 y = char_height * 0.8 draw.text((x, y), c, font=font, anchor="ls", fill=255) for py in range(char_height): for px in range(char_width): pixel = img.getpixel((px, py)) vals.append(str(pixel)) # Format array c_data += ", ".join(vals) c_data += "\n};\n" return c_data c_out = "" c_out += generate_c_data(28, 32, 36, "data") c_out += "\n" c_out += generate_c_data(56, 64, 72, "data2x") c_out += "\n" c_out += generate_c_data(84, 96, 108, "data3x") c_out += "\n" c_out += generate_c_data(112, 128, 144, "data4x") c_out += "\n" c_out += generate_c_data(168, 192, 216, "data6x") with open("arkrt/ArkGraphics/ArkFontRobotoBoldData.c", "w") as f: f.write(c_out) swift_out = """// // Copyright 2026 Aarav // @_silgen_name("ArkFontRobotoBold_data") public var ArkFontRobotoBold_data_sym: UInt8 @_silgen_name("ArkFontRobotoBold_data2x") public var ArkFontRobotoBold_data2x_sym: UInt8 @_silgen_name("ArkFontRobotoBold_data3x") public var ArkFontRobotoBold_data3x_sym: UInt8 @_silgen_name("ArkFontRobotoBold_data4x") public var ArkFontRobotoBold_data4x_sym: UInt8 @_silgen_name("ArkFontRobotoBold_data6x") public var ArkFontRobotoBold_data6x_sym: UInt8 public struct ArkFontRobotoBold { public static let charWidth = 32 public static let charHeight = 36 public static let charWidth2x = 64 public static let charHeight2x = 72 public static let charWidth3x = 96 public static let charHeight3x = 108 public static let charWidth4x = 128 public static let charHeight4x = 144 public static let charWidth6x = 192 public static let charHeight6x = 216 public static var data: UnsafePointer { return withUnsafePointer(to: &ArkFontRobotoBold_data_sym) { $0 } } public static var data2x: UnsafePointer { return withUnsafePointer(to: &ArkFontRobotoBold_data2x_sym) { $0 } } public static var data3x: UnsafePointer { return withUnsafePointer(to: &ArkFontRobotoBold_data3x_sym) { $0 } } public static var data4x: UnsafePointer { return withUnsafePointer(to: &ArkFontRobotoBold_data4x_sym) { $0 } } public static var data6x: UnsafePointer { return withUnsafePointer(to: &ArkFontRobotoBold_data6x_sym) { $0 } } } """ with open("arkrt/ArkGraphics/ArkFontRobotoBold.swift", "w") as f: f.write(swift_out) print("Generated arkrt/ArkGraphics/ArkFontRobotoBold.swift and ArkFontRobotoBoldData.c successfully!")