Customizations framework¶
customizations
¶
Glyph customizations applied to Roboto Mono, in order.
To add one, write a Customization subclass in a new module (see base.py for the contract the build enforces) and append an instance to CUSTOMIZATIONS. These modules run inside FontForge's Python.
CUSTOMIZATIONS = (StraightComma(), Tittles(), StraightTailY(), TallerT(), LongerBrackets(), StraightTailA(), UprightAt(), FullPercentSlash(), SlabR(), FullCurrencyBars(), SpurG(), FlatTailQ(), DottedZero(), LargerDots(), FootedOne(), OpenSixNine(), FlatHooks(), FlatTerminalE())
module-attribute
¶
customizations.base
¶
The customization contract and the driver that enforces it.
Style
dataclass
¶
Per-style facts that customizations need, measured from the source font.
name
instance-attribute
¶
italic
instance-attribute
¶
em
instance-attribute
¶
slant
instance-attribute
¶
x_height
instance-attribute
¶
cap_height
instance-attribute
¶
ascender
instance-attribute
¶
descender
instance-attribute
¶
__init__(name, italic, em, slant, x_height, cap_height, ascender, descender)
¶
from_font(font, name, italic)
classmethod
¶
upright(x, y)
¶
Remove the italic slant from a point's x coordinate.
slanted(x, y)
¶
Apply the italic slant to a point drawn in upright coordinates.
Customization
¶
One self-contained change to the design of Roboto Mono glyphs.
Subclasses declare which glyphs they touch and implement redraw. The
driver checks the declaration against the font before and after:
redraws: glyphs whose own outlinesredrawreplaces. Each must change.inherits: composites that reference a redrawn glyph and should show the new design. Each must change.preserves: composites that reference a redrawn glyph but keep the upstream design. Their references to redrawn glyphs are decomposed first.
Every composite that references a redrawn glyph must appear in inherits
or preserves, so new upstream composites cannot change silently. Glyphs
that reach a redrawn glyph only through an inherited composite change
with it and are reported. Nothing else may change, advances included.
CustomizationError
¶
Bases: ValueError
apply_customizations(font, style, customizations)
¶
Apply customizations in order; return a manifest entry for each.
customizations.geometry
¶
Plane geometry on (x, y) tuples, independent of FontForge.
Line
dataclass
¶
The infinite line through points a and b.
a
instance-attribute
¶
b
instance-attribute
¶
__init__(a, b)
¶
x_at(y)
¶
shifted(dx)
¶
The parallel line moved horizontally by dx.
offset(point)
¶
Horizontal distance from the line to a point, positive to the right.
distance(point)
¶
Perpendicular distance from the line to a point.
crossing(p0, p1, p2)
¶
Parameter t where the quadratic curve p0, p1, p2 crosses the line.
The curve's ends must lie on opposite sides of the line.
intersection(other)
¶
lerp(a, b, t)
¶
quadratic(p0, p1, p2, t)
¶
The point at t on the quadratic Bézier curve p0, p1, p2.
rounded(point)
¶
turn(a, b, c)
¶
Degrees between the direction from a to b and from b to c.
ahead(a, b, c)
¶
Whether c lies ahead of b on the way from a to b.
segments(points)
¶
Split a closed quadratic outline into (start, control, end) indices.
points are (x, y, on_curve) tuples with at most one off-curve point
between on-curve ones, as FontForge reads TrueType outlines. control
is None for straight segments. The first segment starts at the first
on-curve point.
extent(points, direction)
¶
How far a closed quadratic outline (see segments) reaches along a
unit vector: the largest dot product of direction with its points.
bounds(points)
¶
Exact bounding box of a closed quadratic outline (see segments).
customizations.outline
¶
FontForge outline helpers shared by the glyph customizations.
flat_outline(font, name, cache=None)
¶
Contours of a glyph with references resolved, as hashable tuples.
Contours are sorted so that decomposing a reference compares equal.
snapshot(font)
¶
Flattened outline and advance of every glyph, for before/after comparison.
referencing(font, names)
¶
Glyphs that reference any of names directly.
contour(points, like)
¶
A closed contour through points, matching the order and direction of like.
Points may be fontforge.point objects or (x, y) tuples (on-curve).
implied(points)
¶
Flags for on-curve points midway between two handles.
TrueType leaves such points out, and FontForge reads them back.
mapped(points, function)
¶
fontforge points moved by function, (x, y) to (x, y), and rounded.
Points that TrueType leaves implied, midway between two handles, stay midway between the rounded handles.