Skip to content
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

[glyf-1 cubic curves] Last cubic segment becomes quadratic #3189

Closed
justvanrossum opened this issue Jun 27, 2023 · 9 comments · Fixed by #3190
Closed

[glyf-1 cubic curves] Last cubic segment becomes quadratic #3189

justvanrossum opened this issue Jun 27, 2023 · 9 comments · Fixed by #3190

Comments

@justvanrossum
Copy link
Collaborator

justvanrossum commented Jun 27, 2023

This is happening when drawing a variable composite glyph from a TTGlyphSet onto a TTGlyphPointPen. All outlines are cubic in the source. The bug is either in the TTGlyphSet code or in TTGlyphPointPen. Or somewhere else. (I will dig deeper, and fix if I can.)

image
@behdad
Copy link
Member

behdad commented Jun 27, 2023

Thanks. Pretty sure it's in Glyph.draw().

@behdad
Copy link
Member

behdad commented Jun 27, 2023

Is this an on-curve-less outline?

@justvanrossum
Copy link
Collaborator Author

Is this an on-curve-less outline?

No, it's an ordinary mix of on-curve and off-curve points.

@behdad
Copy link
Member

behdad commented Jun 27, 2023

Is this an on-curve-less outline?

No, it's an ordinary mix of on-curve and off-curve points.

I can take a look if you send me a font.

@justvanrossum
Copy link
Collaborator Author

The bug is in TTGlyphPen and TTGlyphPointPen:

from fontTools.pens.ttGlyphPen import TTGlyphPen, TTGlyphPointPen
from fontTools.pens.recordingPen import RecordingPointPen

points = [
    ((0, 0), "curve"),
    ((0, 0), None),
    ((0, 0), None),
    ((0, 0), "curve"),
    ((0, 0), None),
    ((0, 0), None),
]

if True:
    pen = TTGlyphPointPen(None)
    pen.beginPath()
    for (x, y), segmentType in points:
        pen.addPoint((x, y), segmentType=segmentType)
    pen.endPath()
else:
    pen = TTGlyphPen(None)
    pen.moveTo((0, 0))
    pen.curveTo((0, 0), (0, 0), (0, 0))
    pen.curveTo((0, 0), (0, 0), (0, 0))
    pen.closePath()

glyph = pen.glyph()

rpen = RecordingPointPen()
glyph.drawPoints(rpen, None)

for m, args, kwargs in rpen.value:
    if args:
        pt, tp, *_ = args
        print(m, pt, tp)
    else:
        print(m)

In both cases, the output is:

beginPath
addPoint (0, 0) qcurve
addPoint (0, 0) None
addPoint (0, 0) None
addPoint (0, 0) curve
addPoint (0, 0) None
addPoint (0, 0) None
endPath

Where the first segmentType should be "curve" instead of "qcurve".

@justvanrossum
Copy link
Collaborator Author

Hm, maybe the bug is with glyph.drawPoints(): if I use glyph.draw() with RecordingPen the output seems fine.

@behdad
Copy link
Member

behdad commented Jun 27, 2023

Indeed:

            # Start with the appropriate segment type based on the final segment 
            segmentType = "line" if cFlags[-1] == 1 else "qcurve" 

@behdad
Copy link
Member

behdad commented Jun 27, 2023

Can you check with #3190

@justvanrossum
Copy link
Collaborator Author

Can you check with #3190

Yup, that fixes it, thanks!

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 a pull request may close this issue.

2 participants