Files
harfbuzz/test/api/fonts/generate-glyf-default-instance-bounds.py
Behdad Esfahbod 51c6d7676c [subset] Recompute glyph headers when instancing at default (#6436)
A partial TrueType instance can round a child's points and its
component offset independently. A later full instance at the remaining
axes' defaults recalculates bounds but leaves the source glyph header
unchanged, so it can disagree with the stored component geometry and
with the updated global bounds.

Compile glyphs through the owned-byte path for default pins as well,
and free those buffers on both serialization and failure paths.

Add a generated regression where partial instancing stores child xMax
11 and component offset 1, then default instancing must write xMax 12.
The assertion fails before the fix. The full Meson suite passes with
272 tests successful and one skipped; OTS accepts the source fixture.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-22 12:55:36 -06:00

44 lines
1.6 KiB
Python

"""Generate independently rounded child points and component offsets."""
from pathlib import Path
from fontTools.fontBuilder import FontBuilder
from fontTools.pens.ttGlyphPen import TTGlyphPen
from fontTools.ttLib import newTable
from fontTools.ttLib.tables.TupleVariation import TupleVariation
builder = FontBuilder(1000, isTTF=True)
builder.font.recalcTimestamp = False
builder.font["head"].created = builder.font["head"].modified = 2082844800
names = [".notdef", "child", "composite"]
builder.setupGlyphOrder(names)
builder.setupCharacterMap({65: "composite"})
pen = TTGlyphPen(None)
empty = pen.glyph()
pen = TTGlyphPen(None)
pen.moveTo((0, 0))
pen.lineTo((10, 0))
pen.lineTo((0, 10))
pen.closePath()
child = pen.glyph()
pen = TTGlyphPen({"child": child})
pen.addComponent("child", (1, 0, 0, 1, 0, 0))
builder.setupGlyf({".notdef": empty, "child": child, "composite": pen.glyph()})
builder.setupHorizontalMetrics({name: (500, 0) for name in names})
builder.setupHorizontalHeader(ascent=800, descent=-200)
builder.setupNameTable({"familyName": "Default instance bounds", "styleName": "Regular"})
builder.setupOS2()
builder.setupPost()
builder.setupFvar([("wght", 0, 0, 1, "Weight"), ("wdth", 0, 0, 1, "Width")], [])
gvar = newTable("gvar")
gvar.version = 1
gvar.reserved = 0
gvar.variations = {
".notdef": [],
"child": [
TupleVariation({"wght": (0, 1, 1)}, [(0, 0), (1, 0), (0, 0)] + [(0, 0)] * 4)
],
"composite": [TupleVariation({"wght": (0, 1, 1)}, [(1, 0)] + [(0, 0)] * 4)],
}
builder.font["gvar"] = gvar
builder.save(Path(__file__).with_name("glyf-default-instance-bounds.ttf"))