Files
SirHumza--orbisRPC/scripts/genfont.py
T
SirHumza e26d25c47a installer: custom SDL2 reskin + remaster landing
- ui.c: fullscreen Discord-blurple cards, embedded bitmap font,
  pad X-to-continue, progress bar; IME token entry kept as overlay
- scripts/genfont.py + installer/font.h: build-time rasterized font
- Makefile: -lSDL2 -lSDL2main -lScePigletv2VSH -lSceAudioOut -lSceVideoOut,
  font.h regen rule; drop stock -lSceMsgDialog
- daemon: gateway state machine, status.json heartbeat, gen supersede,
  no-exit token wait; updater removed per direction
- installer: config preserve on reinstall, honest stage logging,
  token-save verification, daemon liveness on done screen
2026-09-27 15:21:00 +02:00

88 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""Rasterize an embedded bitmap font for the installer UI (no TTF on PS4).
Reads a system font with PIL, renders printable ASCII at a fixed pixel
size, and emits installer/font.h: 8-bit alpha glyphs, fixed height,
variable advance. Rerun: python3 scripts/genfont.py
"""
import os
import sys
SIZE = 30
FIRST, LAST = 32, 126
CANDIDATES = [
"/System/Library/Fonts/Helvetica.ttc",
"/System/Library/Fonts/Supplemental/Arial.ttf",
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
]
try:
from PIL import Image, ImageDraw, ImageFont
except ImportError:
sys.exit("PIL required: pip install pillow")
def pick_font():
for p in CANDIDATES:
if os.path.exists(p):
return p
sys.exit("no usable system font found")
def main():
path = pick_font()
out = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
"installer", "font.h")
glyphs = []
max_h = 0
for code in range(FIRST, LAST + 1):
fnt = ImageFont.truetype(path, SIZE, index=0)
ch = chr(code)
tmp = Image.new("L", (SIZE * 3, SIZE * 3), 0)
d = ImageDraw.Draw(tmp)
d.text((SIZE, SIZE), ch, font=fnt, fill=255, anchor="lm")
bb = tmp.getbbox()
if bb is None: # space and friends: blank, advance from font
adv_w = max(1, int(fnt.getlength(ch)))
glyphs.append((adv_w, []))
continue
l, t, r, b = bb
w = max(1, r - l)
h = max(1, b - t)
max_h = max(max_h, h)
crop = [list(tmp.crop((l, yy, r, yy + 1)).getdata())
for yy in range(t, b)]
glyphs.append((w, crop))
H = max_h
blob = bytearray()
adv, off = [], []
for w, crop in glyphs:
off.append(len(blob))
adv.append(w)
# pad crop rows to (H x w), top-aligned
for y in range(H):
src = crop[y] if y < len(crop) else [0] * w
src = (list(src) + [0] * w)[:w]
blob.extend(src)
with open(out, "w") as f:
f.write("/* font.h - GENERATED by scripts/genfont.py. Do not edit. */\n")
f.write("#ifndef INSTALLER_FONT_H\n#define INSTALLER_FONT_H\n")
f.write("#include <stdint.h>\n")
f.write("#define FONT_H %d\n#define FONT_FIRST %d\n#define FONT_COUNT %d\n"
% (H, FIRST, LAST - FIRST + 1))
f.write("static const uint8_t font_adv[FONT_COUNT] = {%s};\n"
% ",".join(str(a) for a in adv))
f.write("static const unsigned font_off[FONT_COUNT] = {%s};\n"
% ",".join(str(o) for o in off))
f.write("static const uint8_t font_px[%d] = {" % len(blob))
for i in range(0, len(blob), 16):
f.write("\n")
f.write(",".join(str(v) for v in blob[i:i + 16]) + ",")
f.write("\n};\n#endif\n")
print("wrote %s (%d glyphs, H=%d, %d bytes)" % (out, len(glyphs), H, len(blob)))
main()