Skip to content

Commit

Permalink
bool(glyph) is False for empty glyphs.. fix logic for notdefGlyph
Browse files Browse the repository at this point in the history
we should check 'if notdefGlyph is not None', otherwise 'if notdefGlyph' returns False for empty glyphs and we hit the else branch, leading to incompatible glyphs whose variations get ignored by varLib...
  • Loading branch information
anthrotype committed Aug 2, 2023
1 parent d4747ee commit c0e8aa1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Lib/ufo2ft/outlineCompiler.py
Expand Up @@ -262,7 +262,7 @@ def makeMissingRequiredGlyphs(font, glyphSet, sfntVersion, notdefGlyph=None):
return

reverseContour = sfntVersion == "\000\001\000\000"
if notdefGlyph:
if notdefGlyph is not None:
notdefGlyph = _copyGlyph(notdefGlyph, reverseContour=reverseContour)
else:
unitsPerEm = otRound(getAttrWithFallback(font.info, "unitsPerEm"))
Expand Down
13 changes: 10 additions & 3 deletions tests/integration_test.py
Expand Up @@ -7,6 +7,7 @@

import pytest
from fontTools.pens.boundsPen import BoundsPen
from fontTools.pens.transformPen import TransformPen
from fontTools.ttLib.tables._g_l_y_f import (
OVERLAP_COMPOUND,
flagCubic,
Expand Down Expand Up @@ -455,8 +456,10 @@ def test_compileTTF_glyf1_not_allQuadratic(self, testufo):
assert ttf["head"].glyphDataFormat == 1

@staticmethod
def drawCurvedContour(glyph):
def drawCurvedContour(glyph, transform=None):
pen = glyph.getPen()
if transform is not None:
pen = TransformPen(pen, transform)
pen.moveTo((500, 0))
pen.curveTo((500, 277.614), (388.072, 500), (250, 500))
pen.curveTo((111.928, 500), (0, 277.614), (0, 0))
Expand Down Expand Up @@ -497,9 +500,9 @@ def test_compileVariableTTF_notdefGlyph_with_curves(self, designspace):

# First we draw an additional contour containing cubic curves in the Regular
# and Bold's .notdef glyphs
for src_idx in (0, 2):
for src_idx, transform in ((0, (1, 0, 0, 1, 0, 0)), (2, (2, 0, 0, 2, 0, 0))):
notdef = designspace.sources[src_idx].font[".notdef"]
self.drawCurvedContour(notdef)
self.drawCurvedContour(notdef, transform)
assert ".notdef" not in designspace.sources[1].font.layers["Medium"]

# this must NOT fail!
Expand All @@ -508,6 +511,10 @@ def test_compileVariableTTF_notdefGlyph_with_curves(self, designspace):
# and because allQuadratic=True, we expect .notdef contains no cubic curves
assert not any(f & flagCubic for f in vf["glyf"][".notdef"].flags)

# ensure .notdef has variations and was NOT dropped as incompatible,
# varLib only warns: https://github.com/fonttools/fonttools/issues/2572
assert ".notdef" in vf["gvar"].variations


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

0 comments on commit c0e8aa1

Please sign in to comment.