Skip to content

Commit

Permalink
Merge pull request #3456 from fonttools/cu2qu-modified-ufo-glyphs
Browse files Browse the repository at this point in the history
[cu2qu/ufo] return set of modified glyph names from fonts_to_quadratic
  • Loading branch information
anthrotype committed Mar 4, 2024
2 parents d7eed23 + f02813b commit 84ebc7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Lib/fontTools/cu2qu/ufo.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def fonts_to_quadratic(
compatibility. If this is not required, calling fonts_to_quadratic with one
font at a time may yield slightly more optimized results.
Return True if fonts were modified, else return False.
Return the set of modified glyph names if any, else return an empty set.
By default, cu2qu stores the curve type in the fonts' lib, under a private
key "com.github.googlei18n.cu2qu.curve_type", and will not try to convert
Expand Down Expand Up @@ -296,7 +296,7 @@ def fonts_to_quadratic(
elif max_err_em:
max_errors = [f.info.unitsPerEm * max_err_em for f in fonts]

modified = False
modified = set()
glyph_errors = {}
for name in set().union(*(f.keys() for f in fonts)):
glyphs = []
Expand All @@ -306,9 +306,10 @@ def fonts_to_quadratic(
glyphs.append(font[name])
cur_max_errors.append(error)
try:
modified |= _glyphs_to_quadratic(
if _glyphs_to_quadratic(
glyphs, cur_max_errors, reverse_direction, stats, all_quadratic
)
):
modified.add(name)
except IncompatibleGlyphsError as exc:
logger.error(exc)
glyph_errors[name] = exc
Expand All @@ -329,7 +330,6 @@ def fonts_to_quadratic(
new_curve_type = "quadratic" if all_quadratic else "mixed"
if curve_type != new_curve_type:
font.lib[CURVE_TYPE_LIB_KEY] = new_curve_type
modified = True
return modified


Expand All @@ -343,7 +343,7 @@ def glyph_to_quadratic(glyph, **kwargs):

def font_to_quadratic(font, **kwargs):
"""Convenience wrapper around fonts_to_quadratic, for just one font.
Return True if the font was modified, else return False.
Return the set of modified glyph names if any, else return empty set.
"""

return fonts_to_quadratic([font], **kwargs)
6 changes: 6 additions & 0 deletions Tests/cu2qu/ufo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ def fonts():

class FontsToQuadraticTest(object):
def test_modified(self, fonts):
# previously this method returned True/False, now it returns a set of modified
# glyph names.
modified = fonts_to_quadratic(fonts)
# the first assertion continues to work whether the return value is a bool/set
# so the change is backward compatible
assert modified
assert len(modified) > 0
assert "B" in modified

def test_stats(self, fonts):
stats = {}
Expand Down

0 comments on commit 84ebc7d

Please sign in to comment.