[cu2qu/ufo] return set of modified glyph names from fonts_to_quadratic
In ufo2ft preProcessor, we need to know which specific glyphs were actually modified (converted to quadratic), in order to do other things while processing filters, not simply if the fonts were modified as a whole; thus, here I changed fonts_to_quadratic to return the set of modified glyph names instead of just True/False. The change is backward compatible because code that checks whether the returned value is True/False will continue to work since bool(set) is True for non-empty set, False for empty ones.
This commit is contained in:
parent
d7eed23e34
commit
f02813bd54
@ -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
|
||||
@ -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 = []
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
@ -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 = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user