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

AngledMarginPen._curveToOne fails #45

Open
LettError opened this issue May 31, 2024 · 4 comments
Open

AngledMarginPen._curveToOne fails #45

LettError opened this issue May 31, 2024 · 4 comments

Comments

@LettError
Copy link
Member

LettError commented May 31, 2024

Calling AngledMarginPen with a round shape (see example) causes a traceback.

This is a short script that gets to the problem right away. First self._start and self.currentPoint to are initialised to None.

Then _moveTo sets self._start and self.currentPoint to a point. Off to a good start!

Let's add a curve point with _curveToOne.

So_curveToOne calls _addMoveTo which sets self.currentPoint back to None. Oh no!

Following _curveToOne calls getCubicPoint with currentPoint as argument and getCubicPoint tries to split it.

I'm not sure what the _addMoveTo mechanism tries to achieve?

    amp = AngledMarginPen({}, 685, -20)
    amp._moveTo((320, 742))
    amp._curveToOne((345, 742), (358, 725), (352, 696))

Traceback (most recent call last):
  File "angledMarginPen.py", line 166, in <module>
  File "angledMarginPen.py", line 164, in testCurveIssue
  File "angledMarginPen.py", line 59, in _curveToOne
  File "angledMarginPen.py", line 28, in _getAngled
TypeError: 'NoneType' object is not subscriptable

If you don't trust the example calling private methods, this is a longer version if you want to see curveTo rather than _curveTo.

from fontParts.fontshell import RGlyph
testGlyph = RGlyph()
testGlyph.name = "testGlyph"
testGlyph.width = 685
pen = testGlyph.getPen()
pen.moveTo((320, 742))
pen.curveTo((345, 742), (358, 725), (352, 696))
pen.curveTo((347, 673), (328, 665), (310, 665))
pen.curveTo((287, 665), (273, 684), (280, 709))
pen.curveTo((285, 731), (303, 742), (320, 742))
pen.closePath()

amp = AngledMarginPen({}, 685, -20)
testGlyph.draw(amp)


Traceback (most recent call last):
  File "angledMarginPen.py", line 171, in <module>
  File "angledMarginPen.py", line 166, in testCurveIssue
  File "/Users/erik/code/fontParts/Lib/fontParts/base/glyph.py", line 630, in draw
  File "/Users/erik/code/fontParts/Lib/fontParts/base/contour.py", line 172, in draw
  File "/Users/erik/code/fontParts/Lib/fontParts/base/contour.py", line 180, in _draw
  File "/Users/erik/code/fontParts/Lib/fontParts/base/contour.py", line 188, in drawPoints
  File "/Users/erik/code/fontParts/Lib/fontParts/base/contour.py", line 213, in _drawPoints
  File "/Applications/RoboFont_4.5b.app/Contents/Resources/lib/python3.12/fontTools/pens/pointPen.py", line 173, in endPath
  File "/Applications/RoboFont_4.5b.app/Contents/Resources/lib/python3.12/fontTools/pens/pointPen.py", line 250, in _flushContour
  File "/Applications/RoboFont_4.5b.app/Contents/Resources/lib/python3.12/fontTools/pens/basePen.py", line 339, in curveTo
  File "angledMarginPen.py", line 59, in _curveToOne
  File "angledMarginPen.py", line 28, in _getAngled
TypeError: 'NoneType' object is not subscriptable
@justvanrossum
Copy link
Contributor

I'm trying to understand the intention of the code, but I can't figure it out.

_curveToOne() calls self._addMoveTo(), which sets self.currentPoint to None, but _curveToOne() then uses self.currentPoint for a call to getCubicPoint(), which fails on this None point it is receiving.

@LettError
Copy link
Member Author

Could _addMoveTo be for open paths?

@typemytype
Copy link
Member

I guess pens behaved differently a long time ago... so finally after 13 years it breaks... https://github.com/robotools/robofab/blob/master/Lib/robofab/pens/angledMarginPen.py

will fix that pen!

typemytype added a commit that referenced this issue May 31, 2024
@LettError
Copy link
Member Author

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

No branches or pull requests

3 participants