From fc1d8d3f5d23c3d50c133794281274476beeb0d3 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 28 Jul 2023 16:28:32 +0100 Subject: [PATCH] set head.glyphDataFormat=1 if not allQuadratic --- Lib/ufo2ft/__init__.py | 6 +++++- Lib/ufo2ft/outlineCompiler.py | 4 +++- tests/integration_test.py | 8 ++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Lib/ufo2ft/__init__.py b/Lib/ufo2ft/__init__.py index 048862a2c..7ac1e5434 100644 --- a/Lib/ufo2ft/__init__.py +++ b/Lib/ufo2ft/__init__.py @@ -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: @@ -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 diff --git a/Lib/ufo2ft/outlineCompiler.py b/Lib/ufo2ft/outlineCompiler.py index 14b7bfed4..28771a0bc 100644 --- a/Lib/ufo2ft/outlineCompiler.py +++ b/Lib/ufo2ft/outlineCompiler.py @@ -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): """ @@ -1440,6 +1440,7 @@ def __init__( dropImpliedOnCurves=False, autoUseMyMetrics=True, roundCoordinates=True, + glyphDataFormat=0, ): super().__init__( font, @@ -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.""" diff --git a/tests/integration_test.py b/tests/integration_test.py index ed10b374f..06bc90a67 100644 --- a/tests/integration_test.py +++ b/tests/integration_test.py @@ -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 @@ -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))