pens: skip the 'None' point for special quadratic contours without oncurves

Fixes https://github.com/trufont/trufont/issues/595
This commit is contained in:
Cosimo Lupo 2018-10-11 22:26:10 +01:00
parent f77981327e
commit 201b4926c1
2 changed files with 7 additions and 12 deletions

View File

@ -220,14 +220,13 @@ class Cu2QuPointPen(BasePointToSegmentPen):
for (pt, smooth, name, kwargs) in offcurves:
pen.addPoint(pt, None, smooth, name, **kwargs)
pt, smooth, name, kwargs = points[-1]
if kwargs is None:
# ufoLib BasePointToSegmentPen incorrectly sets kwargs to
# None for the special quadratic contour with no on-curves:
# https://github.com/unified-font-object/ufoLib/
# issues/11#issuecomment-429033328
# TODO(anthrotype) remove workaround once fixed upstream
kwargs = {}
pen.addPoint(pt, segment_type, smooth, name, **kwargs)
if pt is None:
# special quadratic contour with no on-curve points:
# we need to skip the "None" point. See also the Pen
# protocol's qCurveTo() method and fontTools.pens.basePen
pass
else:
pen.addPoint(pt, segment_type, smooth, name, **kwargs)
else:
# 'curve' segments must have been converted to 'qcurve' by now
raise AssertionError(

View File

@ -351,13 +351,10 @@ pen.endPath()""".splitlines())
Cu2QuPointPen will treat it as a special quadratic contour whose
first point has 'None' coordinates.
"""
# Also see BasePointToSegmentPen bug:
# https://github.com/unified-font-object/ufoLib/issues/11
self.maxDiff = None
pen = DummyPointPen()
quadpen = Cu2QuPointPen(pen, MAX_ERR)
quadpen.beginPath()
# quadpen.addPoint(None, segmentType="qcurve")
quadpen.addPoint((1, 1))
quadpen.addPoint((2, 2))
quadpen.addPoint((3, 3))
@ -368,7 +365,6 @@ pen.endPath()""".splitlines())
dedent(
"""\
pen.beginPath()
pen.addPoint(None, name=None, segmentType='qcurve', smooth=None)
pen.addPoint((1, 1), name=None, segmentType=None, smooth=False)
pen.addPoint((2, 2), name=None, segmentType=None, smooth=False)
pen.addPoint((3, 3), name=None, segmentType=None, smooth=False)