8000 [reverseContourPen] don't imply closing lineTo if == moveTo by anthrotype · Pull Request #1080 · fonttools/fonttools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[reverseContourPen] don't imply closing lineTo if == moveTo #1080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 24, 2017

Conversation

anthrotype
Copy link
Member

Currently, for closed paths, we are always dropping a lineTo segment that follows moveTo, because after reversing the contour this lineTo becomes the last segment, and in the Pen protocol a closePath always implies a line to the fist point.

This is OK when in the original contour the move point and the following lineTo's oncurve point (which will become the last point after reversal) do not overlap.
However, if they do overlap, we end up dropping the duplicate point.

This cu2qu issue exemplifies the problem: googlefonts/cu2qu#51

(Note that cu2qu actually uses the ReverseContourPointPen wrapped by ufoLib's converter pens, but
fontTools' ReverseContourPen works the same)

Now, with this patch, the ReverseContourPen will emit the last lineTo when it is the same as moveTo, thus keeping the duplicate points in this case.

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):

googlefonts/cu2qu#51

With this patch, the ReverseContourPen now emits the last lineTo
when it is the same as moveTo.
One way to work around googlefonts/cu2qu#51
when using the ufoLib's ReverseConturPointPen via the converter pens
would be to pass the outputImpliedClosingLine=True argument
(False by default) to the PointToSegmentPen.

This way, all the final lineTos are explicitly outputted, even when
they are redundant and could be implied (i.e. when they are not
duplicate points).

Note that this test is skipped by the CI, because ufoLib is not a
dependency of fonttools; you can run locally if you wish.
@anthrotype anthrotype merged commit 273ff46 into fonttools:master Oct 24, 2017
@anthrotype anthrotype deleted the reverse-pen-dupl-move branch October 24, 2017 20:15
anthrotype added a commit that referenced this pull request Oct 25, 2017
This test is not normally run. It is skipped when ufoLib is not importable,
as it's the case from the test runner's virtual environment.

The only reason it exists is so that I could check that the
ReverseContourPen I was writing behaves the same as using ufoLib's
ReverseContourPointPen when the latter is run through the
SegmentToPointPen and PointToSegmentPen converters.

The two methods for reversing contours now diverge since
#1080,
but only nominally because both produce effectively the same results.
The only difference is that, when using the point pens with
outputImpliedClosingLine=True, the closing lineTo is always there even
when it's redundant. In our implmentation, we only output the closing
lineTo when it is the same as moveTo (this was necessary in order to
fix googlefonts/cu2qu#51)
Nevertheless, the total number of points is the same in both cases.

Maybe this test should not be here, as it's testing functionalities
from a different package.

Closes #1081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0