Merge pull request #3456 from fonttools/cu2qu-modified-ufo-glyphs
[cu2qu/ufo] return set of modified glyph names from fonts_to_quadratic
This commit is contained in:
commit
84ebc7d345
@ -250,7 +250,7 @@ def fonts_to_quadratic(
|
|||||||
compatibility. If this is not required, calling fonts_to_quadratic with one
|
compatibility. If this is not required, calling fonts_to_quadratic with one
|
||||||
font at a time may yield slightly more optimized results.
|
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
|
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
|
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:
|
elif max_err_em:
|
||||||
max_errors = [f.info.unitsPerEm * max_err_em for f in fonts]
|
max_errors = [f.info.unitsPerEm * max_err_em for f in fonts]
|
||||||
|
|
||||||
modified = False
|
modified = set()
|
||||||
glyph_errors = {}
|
glyph_errors = {}
|
||||||
for name in set().union(*(f.keys() for f in fonts)):
|
for name in set().union(*(f.keys() for f in fonts)):
|
||||||
glyphs = []
|
glyphs = []
|
||||||
@ -306,9 +306,10 @@ def fonts_to_quadratic(
|
|||||||
glyphs.append(font[name])
|
glyphs.append(font[name])
|
||||||
cur_max_errors.append(error)
|
cur_max_errors.append(error)
|
||||||
try:
|
try:
|
||||||
modified |= _glyphs_to_quadratic(
|
if _glyphs_to_quadratic(
|
||||||
glyphs, cur_max_errors, reverse_direction, stats, all_quadratic
|
glyphs, cur_max_errors, reverse_direction, stats, all_quadratic
|
||||||
)
|
):
|
||||||
|
modified.add(name)
|
||||||
except IncompatibleGlyphsError as exc:
|
except IncompatibleGlyphsError as exc:
|
||||||
logger.error(exc)
|
logger.error(exc)
|
||||||
glyph_errors[name] = exc
|
glyph_errors[name] = exc
|
||||||
@ -329,7 +330,6 @@ def fonts_to_quadratic(
|
|||||||
new_curve_type = "quadratic" if all_quadratic else "mixed"
|
new_curve_type = "quadratic" if all_quadratic else "mixed"
|
||||||
if curve_type != new_curve_type:
|
if curve_type != new_curve_type:
|
||||||
font.lib[CURVE_TYPE_LIB_KEY] = new_curve_type
|
font.lib[CURVE_TYPE_LIB_KEY] = new_curve_type
|
||||||
modified = True
|
|
||||||
return modified
|
return modified
|
||||||
|
|
||||||
|
|
||||||
@ -343,7 +343,7 @@ def glyph_to_quadratic(glyph, **kwargs):
|
|||||||
|
|
||||||
def font_to_quadratic(font, **kwargs):
|
def font_to_quadratic(font, **kwargs):
|
||||||
"""Convenience wrapper around fonts_to_quadratic, for just one font.
|
"""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)
|
return fonts_to_quadratic([font], **kwargs)
|
||||||
|
@ -35,8 +35,14 @@ def fonts():
|
|||||||
|
|
||||||
class FontsToQuadraticTest(object):
|
class FontsToQuadraticTest(object):
|
||||||
def test_modified(self, fonts):
|
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)
|
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 modified
|
||||||
|
assert len(modified) > 0
|
||||||
|
assert "B" in modified
|
||||||
|
|
||||||
def test_stats(self, fonts):
|
def test_stats(self, fonts):
|
||||||
stats = {}
|
stats = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user