"""Bake complete Latin glyphs from the bundled extended font (no synthetic marks).""" from pathlib import Path from PIL import ImageFont ROOT = Path(__file__).resolve().parent.parent font = ImageFont.truetype(str(ROOT / 'data/frames/undertale.otf'), 12) top = font.getbbox('A')[1] assert font.getmask('A', mode='1').getbbox() == (0, 0, 6, 9) lines = ['// Generated by scripts/generate-settings-latin-font.py from undertale.otf.', '// Full glyphs at 12 px; A has a 6 x 9 px visible body.', '#define SETTINGS_LATIN_CAPITAL_WIDTH 6.0f', '#define SETTINGS_LATIN_CAPITAL_HEIGHT 9.0f', 'typedef struct { uint16_t cp; int8_t x, y; uint8_t w, h; uint32_t rows[24]; } SettingsLatinGlyph;', 'static const SettingsLatinGlyph settingsLatinGlyphs[] = {'] for cp in list(range(0xC0, 0x100)) + [0x15E, 0x15F]: char = chr(cp) mask = font.getmask(char, mode='1') w, h = mask.size assert w <= 32 and h <= 24 bbox = font.getbbox(char) rows = [sum((1 << x) for x in range(w) if mask[y * w + x]) for y in range(h)] lines.append(' {%d, %d, %d, %d, %d, {%s}},' % (cp, bbox[0], bbox[1] - top, w, h, ','.join(hex(row) for row in rows))) lines.append('};') (ROOT / 'src/vita-probe/source/settings_latin_font.h').write_text('\n'.join(lines) + '\n')