Skip to content

Commit 00e4e2c

Browse files
authored
Merge pull request #57 from madig/raise-on-unsupported-segmenttype
Raise new UnsupportedContourError on unsupported segment type
2 parents b7d9fc9 + 8a4d0ec commit 00e4e2c

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

Lib/booleanOperations/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ class BooleanOperationsError(Exception):
55
"""Base BooleanOperations exception"""
66

77

8+
class UnsupportedContourError(BooleanOperationsError):
9+
"""Raised when asked to perform an operation on an unsupported curve type."""
10+
11+
812
class InvalidContourError(BooleanOperationsError):
913
"""Raised when any input contour is invalid"""
1014

Lib/booleanOperations/flatten.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from fontTools.misc import bezierTools
44
from fontTools.pens.basePen import decomposeQuadraticSegment
55
import pyclipper
6-
from .exceptions import OpenContourError
6+
from .exceptions import OpenContourError, UnsupportedContourError
77

88
"""
99
To Do:
@@ -434,7 +434,7 @@ def _convertPointsToSegments(points, willBeReversed=False):
434434
# off curve, hold.
435435
if point.segmentType is None:
436436
offCurves.append(point)
437-
else:
437+
elif point.segmentType in {"curve", "line"}:
438438
segment = InputSegment(
439439
points=offCurves + [point],
440440
previousOnCurve=previousOnCurve,
@@ -443,6 +443,11 @@ def _convertPointsToSegments(points, willBeReversed=False):
443443
segments.append(segment)
444444
offCurves = []
445445
previousOnCurve = point.coordinates
446+
else:
447+
raise UnsupportedContourError(
448+
"Trying to perform operation on unsupported segment type.",
449+
point.segmentType
450+
)
446451
assert not offCurves
447452
return segments
448453

tests/test_BooleanGlyph.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import unittest
66

7+
import pytest
78
from fontPens.digestPointPen import DigestPointPen
89

910
import defcon
@@ -78,6 +79,20 @@ def _addGlyphTests():
7879

7980
_addGlyphTests()
8081

82+
def test_unsupported_qcurve():
83+
font = defcon.Font()
84+
g = font.newGlyph("test")
85+
p = g.getPointPen()
86+
p.beginPath()
87+
p.addPoint((0, 0), segmentType="line")
88+
p.addPoint((100, 0), segmentType="line")
89+
p.addPoint((100, 100), segmentType="line")
90+
p.addPoint((50, 100))
91+
p.addPoint((0, 100), segmentType="qcurve")
92+
p.endPath()
93+
94+
with pytest.raises(booleanOperations.exceptions.UnsupportedContourError):
95+
booleanOperations.union(g, None)
8196

8297
if __name__ == '__main__':
8398
sys.exit(unittest.main())

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ deps =
77
fontPens
88
pytest
99
-rrequirements.txt
10+
download = True
1011
commands =
1112
# pass to pytest any extra positional arguments after `tox -- ...`
1213
pytest {posargs}

0 commit comments

Comments
 (0)