Return a report of conversion

This commit is contained in:
jamesgk 2015-10-01 17:14:58 -07:00
parent a23b97e79c
commit 72fef95dfd

View File

@ -193,7 +193,7 @@ def convertCollectionToQuadratic(p0, p1, p2, p3, max_n, max_err):
return splines return splines
def cubicSegmentToQuadratic(c,sid, max_n, max_err): def cubicSegmentToQuadratic(c, sid, max_n, max_err, report):
segment = c[sid] segment = c[sid]
if (segment.type != "curve"): if (segment.type != "curve"):
@ -206,6 +206,12 @@ def cubicSegmentToQuadratic(c,sid, max_n, max_err):
segment.points[1],segment.points[2], segment.points[1],segment.points[2],
max_n, max_err) max_n, max_err)
if isinstance(points[0][0], float): # just one spline
n = str(len(points))
else: # collection of splines
n = str(len(points[0]))
report[n] = report.get(n, 0) + 1
try: try:
return segment.asQuadratic([p[1:] for p in points]) return segment.asQuadratic([p[1:] for p in points])
except AttributeError: except AttributeError:
@ -213,7 +219,8 @@ def cubicSegmentToQuadratic(c,sid, max_n, max_err):
return RSegment( return RSegment(
'qcurve', [[int(i) for i in p] for p in points[1:]], segment.smooth) 'qcurve', [[int(i) for i in p] for p in points[1:]], segment.smooth)
def glyphCurvesToQuadratic(g, max_n, max_err):
def glyphCurvesToQuadratic(g, max_n, max_err, report):
for c in g: for c in g:
segments = [] segments = []
@ -239,11 +246,18 @@ def fonts_to_quadratic(fonts, compatible=False, max_n=10, max_err=5):
which should be slightly more optimized. which should be slightly more optimized.
""" """
report = {}
if compatible: if compatible:
fonts = [FontCollection(fonts)] fonts = [FontCollection(fonts)]
for font in fonts: for font in fonts:
for glyph in font: for glyph in font:
glyphCurvesToQuadratic(glyph, max_n, max_err) glyphCurvesToQuadratic(glyph, max_n, max_err, report)
spline_lengths = report.keys()
spline_lengths.sort()
return (
'>>> New spline lengths:\n' +
'\n'.join('%s: %d' % (l, report[l]) for l in spline_lengths))
class FontCollection: class FontCollection: