Adding a glyph customization¶
Glyph customizations live in scripts/customizations/. Each customization is a
self-contained subclass of
Customization
in its own module, registered in CUSTOMIZATIONS in
scripts/customizations/__init__.py.
Subclass contract¶
from .base import Customization
class ExampleCustomization(Customization):
name = "example"
summary = "What changes and why"
redraws = ("l",) # glyphs whose outlines redraw() replaces
inherits = () # composites using them that should follow
preserves = () # composites using them that keep the old design
def redraw(self, font, style):
# Edit font["l"]; style has em, slant, x_height, cap_height,
# ascender, descender, upright(), and slanted().
...
Add an instance of your subclass to CUSTOMIZATIONS in
scripts/customizations/__init__.py.
What the build enforces¶
apply_customizations()
snapshots the entire font before and after each customization and raises
CustomizationError on any violation:
- Every glyph in
redraws,inherits, andpreservesmust exist in the font. - Every composite that directly references a glyph in
redrawsmust be classified in eitherinheritsorpreserves. Unclassified composites fail the build so upstream composites never change silently. - Every glyph in
preserveshas its references toredrawsunlinked beforeredraw()runs and must remain outline-identical afterward. - Every glyph in
redrawsandinheritsmust actually change. - No glyph outside
redraws,inherits, and their transitive composite dependents may change, and no glyph's advance width may change.
The driver records each customization's changed and preserved glyph lists
in the style's JSON manifest, which make check verifies again against the
final hinted TTF.
Shared helpers¶
Two helper modules cover most outline operations:
customizations.outline- FontForge helpers for reading single contours (single_contour), rebuilding closed contours while asserting contour direction (contour), mapping and rounding points while keeping TrueType-implied midpoints intact (mapped,implied), and replacing a glyph's foreground layer (replace_contours).customizations.geometry- Pure-Python plane geometry on(x, y)tuples: infinite lines, offsets, distances, line-line and line-quadratic intersections (Line), linear and quadratic Bézier evaluation (lerp,quadratic), turn angles (turn,ahead), and exact quadratic contour bounds and directional extents (segments,bounds,extent).
Design guidelines¶
- Measure, do not hard-code. Derive geometry from upstream outlines and
per-style
Stylemetrics (x_height,cap_height,ascender,descender,slant,em) and read cell width fromfont["space"].width. One rule should cover every weight and italic. - Work in upright coordinates. Use
style.upright(x, y)when measuring andstyle.slanted(x, y)when placing points so italics follow Roboto Mono's 10-degree slant automatically. - Assert upstream structure. Raise
ValueErrorif an expected contour count, straight edge, or corner is missing instead of silently producing broken geometry. - Preserve contour direction. Always construct rebuilt contours with
contour(..., like=original), which verifies clockwise/counter-clockwise orientation. - Document and verify. Add the glyph specification to the appropriate page
under
docs/customizations/, add its module todocs/reference/glyph_modules.md, updateAGENTS.md, and run: