Specify max error in em instead of font units

This should be more compatible between fonts with different UPM. In
fact, it should work within a single call with such fonts.

The default max error is now 0.0025 em, which is about 5 units for a
2048 UPM font.
This commit is contained in:
jamesgk 2015-11-20 12:04:16 -08:00
parent 8bbdb47cf5
commit e94071a2d8
2 changed files with 6 additions and 5 deletions

View File

@ -146,13 +146,13 @@ def curve_to_quadratic(p, max_n, max_err):
return spline
def curves_to_quadratic(curves, max_n, max_err):
def curves_to_quadratic(curves, max_n, max_errors):
"""Return quadratic splines approximating these cubic beziers."""
for n in range(1, max_n + 1):
splines = [cubic_approx_spline(c, n) for c in curves]
if (all(splines) and
max(curve_spline_dist(c, s)
for c, s in zip(curves, splines)) <= max_err):
all(curve_spline_dist(c, s) < max_err
for c, s, max_err in zip(curves, splines, max_errors))):
break
return splines

View File

@ -47,11 +47,12 @@ def fonts_to_quadratic(*fonts, **kwargs):
"""
max_n = kwargs.get('max_n', 10)
max_err = kwargs.get('max_err', 5)
max_err = kwargs.get('max_err', 0.0025)
max_errors = [f.info.unitsPerEm * max_err for f in fonts]
report = {}
for glyph in FontCollection(fonts):
glyph_to_quadratic(glyph, max_n, max_err, report)
glyph_to_quadratic(glyph, max_n, max_errors, report)
spline_lengths = report.keys()
spline_lengths.sort()