Skip to content

Commit

Permalink
warn when building COLRv0 font if gid1 is not blank
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Nov 8, 2024
1 parent eb06823 commit 6503a9c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Lib/ufo2ft/outlineCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/outlineCompiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6503a9c

Please sign in to comment.