# Generate embedded 1-bit bitmap fonts from a TrueType/OpenType font. # # FontForge's direct monochrome XBM export is too thin for this display, especially # at footer sizes. This exports antialiased BMP glyphs and packs 4-bit alpha. # # Run with FontForge, not python3: # fontforge -lang=py -script scripts/generate-fonts.py \ # '/Volumes/Drawer/Fonts/iAFonts/iA Writer Quattro/Static/iAWriterQuattroS-Regular.ttf' \ # src/ui/generated_fonts.rs import os import struct import sys import tempfile import fontforge SIZES = [ ("QUATTRO_SMALL", 24), ("QUATTRO_BODY", 30), ("QUATTRO_READER", 34), ("QUATTRO_TITLE", 38), ] CODEPOINTS = list(range(32, 127)) + [ 0x00A0, # no-break space 0x2018, # left single quotation mark 0x2019, # right single quotation mark 0x201C, # left double quotation mark 0x201D, # right double quotation mark 0x2013, # en dash 0x2014, # em dash 0x2026, # ellipsis ] def parse_bmp(path): with open(path, "rb") as file: data = file.read() if data[0:2] != b"BM": raise RuntimeError("not a BMP file: {}".format(path)) pixel_offset = struct.unpack_from("