[reverseContourPen] don't imply closing lineTo when same as moveTo
Previously, for closed paths, we were always dropping a lineTo segment that followed moveTo, because after reversing the contour this lineTo would become the last segment, and in the Pen protocol a closePath always implies a line to the fist point. This is OK when the move point and the following lineTo oncurve point (which becomes last after reversal) don't overlap. However, if they do, we ended up dropping the duplicate point. This cu2qu issue exemplify the problem (cu2qu actually uses the ReverseContourPointPen wrapped by ufoLib's converter pens, but fontTools' ReverseContourPen does exactly the same): https://github.com/googlei18n/cu2qu/issues/51 With this patch, the ReverseContourPen now emits the last lineTo when it is the same as moveTo.
This commit is contained in:
parent
0a22639ed3
commit
e201ea9891
@ -68,10 +68,16 @@ def reversedContour(contour):
|
||||
contour[-1] = (lastType,
|
||||
tuple(lastPts[:-1]) + (firstOnCurve,))
|
||||
|
||||
if len(contour) > 1:
|
||||
secondType, secondPts = contour[0]
|
||||
else:
|
||||
# contour has only two points, the second and last are the same
|
||||
secondType, secondPts = lastType, lastPts
|
||||
# if a lineTo follows the initial moveTo, after reversing it
|
||||
# will be implied by the closePath, so we don't emit one
|
||||
secondType, secondPts = contour[0]
|
||||
if secondType == "lineTo":
|
||||
# will be implied by the closePath, so we don't emit one;
|
||||
# unless the lineTo and moveTo overlap, in which case we keep the
|
||||
# duplicate points
|
||||
if secondType == "lineTo" and firstPts != secondPts:
|
||||
del contour[0]
|
||||
if contour:
|
||||
contour[-1] = (lastType,
|
||||
|
Loading…
x
Reference in New Issue
Block a user