"""Builds glyphless.ttf: a TrueType font whose every glyph is empty and half an em wide, for the invisible text layer of the PDFs made from DjVu books (patches/pdf-text-and-links.patch embeds it). Text in that layer is drawn in render mode 3 (invisible), so the glyphs never show; the font only has to be valid, and the same width for every character so the page can scale each word to fit its box. Written for johnmcm.com (2026); public domain. Run with fontTools: python make_glyphless.py (writes glyphless.ttf beside this script) """ from pathlib import Path from fontTools.fontBuilder import FontBuilder from fontTools.pens.ttGlyphPen import TTGlyphPen UPM = 1000 ADVANCE = 500 def empty_glyph(): return TTGlyphPen(None).glyph() fb = FontBuilder(UPM, isTTF=True) fb.setupGlyphOrder(['.notdef', 'glyph']) # The PDF maps every character to glyph 1 itself (CIDToGIDMap), so no cmap # entries are needed beyond one, which some readers expect to exist. fb.setupCharacterMap({0x20: 'glyph'}) fb.setupGlyf({'.notdef': empty_glyph(), 'glyph': empty_glyph()}) fb.setupHorizontalMetrics({'.notdef': (ADVANCE, 0), 'glyph': (ADVANCE, 0)}) fb.setupHorizontalHeader(ascent=1000, descent=0) fb.setupNameTable({'familyName': 'GlyphLessFont', 'styleName': 'Regular'}) fb.setupOS2(sTypoAscender=1000, sTypoDescender=0, usWinAscent=1000, usWinDescent=0) fb.setupPost() fb.save(str(Path(__file__).with_name('glyphless.ttf')))