Skip to content

Commit

Permalink
set head.glyphDataFormat=1 if not allQuadratic
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Jul 28, 2023
1 parent ea4d3eb commit fc1d8d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Lib/ufo2ft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ def compileTTF(ufo, **kwargs):
glyphSet = call_preprocessor(ufo, **kwargs)

logger.info("Building OpenType tables")
otf = call_outline_compiler(ufo, glyphSet, **kwargs)

otf = call_outline_compiler(
ufo, glyphSet, glyphDataFormat=(0 if kwargs["allQuadratic"] else 1), **kwargs
)

# Only the default layer is likely to have all glyphs used in feature code.
if kwargs["layerName"] is None:
Expand Down Expand Up @@ -333,6 +336,7 @@ def compileInterpolatableTTFs(ufos, **kwargs):
ufo,
glyphSet,
**kwargs,
glyphDataFormat=(0 if kwargs["allQuadratic"] else 1),
tables=SPARSE_TTF_MASTER_TABLES if layerName else None,
# we want to keep coordinates as floats in glyf masters so that fonttools
# can compute impliable on-curve points from unrounded coordinates before
Expand Down
4 changes: 3 additions & 1 deletion Lib/ufo2ft/outlineCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def setupTable_head(self):
)
head.fontDirectionHint = 2
head.indexToLocFormat = 0
head.glyphDataFormat = 0
head.glyphDataFormat = getattr(self, "glyphDataFormat", 0)

def setupTable_name(self):
"""
Expand Down Expand Up @@ -1440,6 +1440,7 @@ def __init__(
dropImpliedOnCurves=False,
autoUseMyMetrics=True,
roundCoordinates=True,
glyphDataFormat=0,
):
super().__init__(
font,
Expand All @@ -1454,6 +1455,7 @@ def __init__(
self.autoUseMyMetrics = autoUseMyMetrics
self.dropImpliedOnCurves = dropImpliedOnCurves
self.roundCoordinates = roundCoordinates
self.glyphDataFormat = glyphDataFormat

def compileGlyphs(self):
"""Compile and return the TrueType glyphs for this font."""
Expand Down
8 changes: 6 additions & 2 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,13 @@ def test_compile_overloaded_codepoints(self, FontClass, compileFunc):
):
_ = compileFunc(ufo)

def test_compileTTF_not_allQuadratic(self, testufo):
def test_compileTTF_glyf1_not_allQuadratic(self, testufo):
ttf = compileTTF(testufo, allQuadratic=False)
expectTTX(ttf, "TestFont-not-allQuadratic.ttx", tables=["glyf"])

def test_compileVariableTTF_not_allQuadratic(self, designspace):
assert ttf["head"].glyphDataFormat == 1

def test_compileVariableTTF_glyf1_not_allQuadratic(self, designspace):
base_master = designspace.findDefault()
assert base_master is not None
# add a glyph with some curveTo to exercise the cu2qu codepath
Expand All @@ -462,6 +464,8 @@ def test_compileVariableTTF_not_allQuadratic(self, designspace):
vf = compileVariableTTF(designspace, allQuadratic=False)
expectTTX(vf, "TestVariableFont-TTF-not-allQuadratic.ttx", tables=["glyf"])

assert vf["head"].glyphDataFormat == 1


if __name__ == "__main__":
sys.exit(pytest.main(sys.argv))

0 comments on commit fc1d8d3

Please sign in to comment.