defcon icon indicating copy to clipboard operation
defcon copied to clipboard

splitAndInsertPointAtSegmentAndT doesn't handle quadric curves

Open driehuis opened this issue 3 years ago • 3 comments

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

driehuis avatar Jun 06 '21 14:06 driehuis

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!

benkiel avatar Jun 07 '21 14:06 benkiel

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?

driehuis avatar Jun 07 '21 15:06 driehuis

@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 avatar Jun 07 '21 15:06 benkiel