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

splitAndInsertPointAtSegmentAndT doesn't handle quadric curves #360

Open
driehuis opened this issue Jun 6, 2021 · 3 comments
Open

splitAndInsertPointAtSegmentAndT doesn't handle quadric curves #360

driehuis opened this issue Jun 6, 2021 · 3 comments

Comments

@driehuis
Copy link

driehuis commented Jun 6, 2021

When editing glyphs in some fonts, trufont trips over "NotImplementedError: unknown segment type: qcurve".

Traceback (most recent call last):
File "/home/bert/.virtualenvs/trufont/lib/python3.8/site-packages/trufont/controls/glyphCanvasView.py", line 451, in mouseReleaseEvent
self._redirectEvent(event, self._currentTool.mouseReleaseEvent, True)
File "/home/bert/.virtualenvs/trufont/lib/python3.8/site-packages/trufont/controls/glyphCanvasView.py", line 527, in _redirectEvent
callback(event)
File "/home/bert/.virtualenvs/trufont/lib/python3.8/site-packages/trufont/drawingTools/knifeTool.py", line 135, in mouseReleaseEvent
contour.splitAndInsertPointAtSegmentAndT(index, t / prev)
File "/home/bert/.virtualenvs/trufont/lib/python3.8/site-packages/defcon/objects/contour.py", line 573, in splitAndInsertPointAtSegmentAndT
self._splitAndInsertAtSegmentAndT(segmentIndex, t, True)
File "/home/bert/.virtualenvs/trufont/lib/python3.8/site-packages/defcon/objects/contour.py", line 598, in _splitAndInsertAtSegmentAndT
raise NotImplementedError("unknown segment type: %s" % segmentType)
NotImplementedError: unknown segment type: qcurve.

The above crash can be reproduced reliably by opening https://github.com/playbeing/dinish/tree/master/sources/DinishCondensed/DinishCondensed-Regular.ufo with the v2.004 git tag, open small "o" in the glyph editor, selecting the knife tool, and cutting the "o" vertically to create a "c" out of the shape.

As a workaround, the font can be converted to OTF format, the glyph can then be edited in the OTF copy, then copied and pasted.

Using defcon 0.8.1 from pip, which seems to be up-to-date in git as far as this module is concerned.

I looked at contour.py, but I don't understand enough about quadratic and cubic curves to fill in the blanks. I was pretty good at math in high school, but every time I try to code with bezier curves my mind turns a blank :-)

@benkiel
Copy link
Member

benkiel commented Jun 7, 2021

Hey @driehuis, thank you for filing an issue! Looking at the traceback, it seems like this may be an issue with Trufont, not defcon. Seems like defcon is giving Trufont a qcurve and the contour.splitAndInsertPointAtSegmentAndT method in Trufont doesn't know how to deal with it. Have you also filed an issue with Trufont on this?

edit: I was 100% wrong above (see below). Needed another cup of coffee before writing!

@driehuis
Copy link
Author

driehuis commented Jun 7, 2021

I almost did file an issue against Trufont, but then it dawned on me that the exception is thrown from defcon/objects/contour.py:598, which reads:

            # XXX could be a quad. in that case, we could handle it.
            raise NotImplementedError("unknown segment type: %s" % segmentType)

contour.splitAndInsertPointAtSegmentAndT is also in this file.

I think that's solidly in defcon's yard, isn't it?

@benkiel
Copy link
Member

benkiel commented Jun 7, 2021

@driehuis Right, my bad — I searched for that method and it didn't turn up on first search. This is a known issue with that code (see #2), it doesn't handle splitting quadratic curves currently.

I'm changing the title of this issue to reflect that; though I don't know if this will get fixed anytime soon. Would be very happy to take a PR that does fix it, however.

@benkiel benkiel changed the title Crash in trufont when editing glyphs with qcurve splitAndInsertPointAtSegmentAndT doesn't handle quadric curves Jun 7, 2021
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

No branches or pull requests

2 participants