From 6503a9c67a5b2275858cdbdb2972c39ab10231c4 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 8 Nov 2024 13:11:30 +0100 Subject: [PATCH] warn when building COLRv0 font if gid1 is not blank --- Lib/ufo2ft/outlineCompiler.py | 20 +++++++++++++++++++- tests/outlineCompiler_test.py | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Lib/ufo2ft/outlineCompiler.py b/Lib/ufo2ft/outlineCompiler.py index d8816c62..067d3e7b 100644 --- a/Lib/ufo2ft/outlineCompiler.py +++ b/Lib/ufo2ft/outlineCompiler.py @@ -988,13 +988,31 @@ def setupTable_COLR(self): for glyphs, box in self.ufo.lib.get(COLR_CLIP_BOXES_KEY, ()) for glyphName in glyphs } - self.otf["COLR"] = buildCOLR( + colr = buildCOLR( layerInfo, glyphMap=glyphMap, clipBoxes=clipBoxes, allowLayerReuse=self.colrLayerReuse, ) + # Warn if there are any COLRv0 base glyphs and the gid1 isn't blank + # https://github.com/MicrosoftDocs/typography-issues/issues/346 + if (colr.version == 0 or colr.table.BaseGlyphRecordCount > 0) and len( + self.glyphOrder + ) > 1: + g1 = self.allGlyphs[self.glyphOrder[1]] + if len(g1) > 0 or len(g1.components) > 0: + logger.warning( + "COLRv0 might not render correctly on Windows because " + "the glyph at index 1 is not empty ('%s'). DirectWrite's " + "COLRv0 implementation in Windows 10 used to require glyph ID " + "1 to be blank, see: " + "https://github.com/MicrosoftDocs/typography-issues/issues/346", + g1.name, + ) + + self.otf["COLR"] = colr + def _computeCOLRClipBoxes(self): if ( "COLR" not in self.otf diff --git a/tests/outlineCompiler_test.py b/tests/outlineCompiler_test.py index 5755ce5d..7219794b 100644 --- a/tests/outlineCompiler_test.py +++ b/tests/outlineCompiler_test.py @@ -1009,6 +1009,21 @@ def test_colr_cpal_interpolatable_ttf(self, FontClass): "c": [("c.color2", 1), ("c.color1", 0)], } + def test_colr_cpal_gid1_not_blank(self, FontClass, caplog): + # https://github.com/MicrosoftDocs/typography-issues/issues/346 + testufo = FontClass(getpath("ColorTest.ufo")) + del testufo["space"] + + with caplog.at_level(logging.WARNING, logger="ufo2ft.outlineCompiler"): + ttf = compileTTF(testufo) + + assert ttf["COLR"].version == 0 + assert ttf.getGlyphOrder()[1] == "a" + assert ( + "COLRv0 might not render correctly on Windows because " + "the glyph at index 1 is not empty ('a')." + ) in caplog.text + @pytest.mark.parametrize("compileFunc", [compileTTF, compileOTF]) @pytest.mark.parametrize("manualClipBoxes", [True, False]) @pytest.mark.parametrize(