80 | 80 |
multiplied by the given scalar. If scaleComponentTransform is False, then
|
81 | 81 |
only the component's xOffset and yOffset attributes are scaled, whereas the
|
82 | 82 |
xScale, xyScale, yxScale and yScale attributes are kept unchanged.
|
83 | |
strict (bool): when set to False, offcurve points will be added to all
|
|
83 |
strict (bool): when set to False, offcurve points will be added to all
|
84 | 84 |
straight segments to improve compatibility. Any offcurves that are
|
85 | 85 |
still on-point will be filtered when extracted. When set to True,
|
86 | |
no offcurves will be added or filtered.
|
|
86 |
no offcurves will be added or filtered.
|
87 | 87 |
"""
|
88 | 88 |
self.scaleComponentTransform = scaleComponentTransform
|
89 | 89 |
self.contours = []
|
|
431 | 431 |
self._points = []
|
432 | 432 |
|
433 | 433 |
def _flushContour(self):
|
|
434 |
# keep the point order and
|
|
435 |
# change the removed flag if the point should be removed
|
434 | 436 |
points = self._points
|
435 | |
prevOnCurve = None
|
436 | |
offCurves = []
|
437 | |
|
438 | |
pointsToDraw = []
|
439 | |
|
440 | |
# deal with the first point
|
441 | |
pt, segmentType, smooth, name, identifier = points[0]
|
442 | |
# if it is an offcurve, add it to the offcurve list
|
443 | |
if segmentType is None:
|
444 | |
offCurves.append((pt, segmentType, smooth, name, identifier))
|
445 | |
else:
|
446 | |
# potential redundancy
|
447 | |
if segmentType == "curve":
|
448 | |
# gather preceding off curves
|
449 | |
testOffCurves = []
|
450 | |
lastPoint = None
|
451 | |
for i in range(len(points)):
|
452 | |
i = -i - 1
|
453 | |
testPoint = points[i]
|
454 | |
testSegmentType = testPoint[1]
|
455 | |
if testSegmentType is not None:
|
456 | |
lastPoint = testPoint[0]
|
457 | |
break
|
458 | |
testOffCurves.append(testPoint[0])
|
459 | |
# if two offcurves exist we can test for redundancy
|
460 | |
if len(testOffCurves) == 2:
|
461 | |
if testOffCurves[1] == lastPoint and testOffCurves[0] == pt:
|
462 | |
segmentType = "line"
|
463 | |
# remove the last two points
|
464 | |
points = points[:-2]
|
465 | |
# add the point to the contour
|
466 | |
pointsToDraw.append((pt, segmentType, smooth, name, identifier))
|
467 | |
prevOnCurve = pt
|
468 | |
for pt, segmentType, smooth, name, identifier in points[1:]:
|
469 | |
# store offcurves
|
470 | |
if segmentType is None:
|
471 | |
offCurves.append((pt, segmentType, smooth, name, identifier))
|
472 | |
continue
|
473 | |
# curves are a potential redundancy
|
474 | |
elif segmentType == "curve":
|
475 | |
if len(offCurves) == 2:
|
476 | |
# test for redundancy
|
477 | |
if offCurves[0][0] == prevOnCurve and offCurves[1][0] == pt:
|
478 | |
offCurves = []
|
479 | |
segmentType = "line"
|
480 | |
# add all offcurves
|
481 | |
for offCurve in offCurves:
|
482 | |
pointsToDraw.append(offCurve)
|
483 | |
# add the on curve
|
484 | |
pointsToDraw.append((pt, segmentType, smooth, name, identifier))
|
485 | |
# reset the stored data
|
486 | |
prevOnCurve = pt
|
487 | |
offCurves = []
|
488 | |
# catch any remaining offcurves
|
489 | |
if len(offCurves) != 0:
|
490 | |
for offCurve in offCurves:
|
491 | |
pointsToDraw.append(offCurve)
|
492 | |
# draw to the pen
|
493 | |
for pt, segmentType, smooth, name, identifier in pointsToDraw:
|
494 | |
self._pen.addPoint(pt, segmentType, smooth=smooth, name=name, identifier=identifier)
|
|
437 |
for index, data in enumerate(points):
|
|
438 |
if data["segmentType"] == "curve":
|
|
439 |
prevOnCurve = points[index - 3]
|
|
440 |
prevOffCurve1 = points[index - 2]
|
|
441 |
prevOffCurve2 = points[index - 1]
|
|
442 |
# check if the curve is a super bezier
|
|
443 |
if prevOnCurve["segmentType"] is not None:
|
|
444 |
if prevOnCurve["pt"] == prevOffCurve1["pt"] and prevOffCurve2["pt"] == data["pt"]:
|
|
445 |
# the off curves are on top of the on curve point
|
|
446 |
# change the segmentType
|
|
447 |
data["segmentType"] = "line"
|
|
448 |
# flag the off curves to be removed
|
|
449 |
prevOffCurve1["removed"] = True
|
|
450 |
prevOffCurve2["removed"] = True
|
|
451 |
|
|
452 |
for data in points:
|
|
453 |
if not data["removed"]:
|
|
454 |
self._pen.addPoint(
|
|
455 |
data["pt"],
|
|
456 |
data["segmentType"],
|
|
457 |
smooth=data["smooth"],
|
|
458 |
name=data["name"],
|
|
459 |
identifier=data["identifier"]
|
|
460 |
)
|
495 | 461 |
|
496 | 462 |
def beginPath(self, identifier=None, **kwargs):
|
497 | 463 |
self._points = []
|
498 | 464 |
self._pen.beginPath(identifier=identifier)
|
499 | 465 |
|
500 | 466 |
def addPoint(self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs):
|
501 | |
self._points.append((pt, segmentType, smooth, name, identifier))
|
|
467 |
self._points.append(
|
|
468 |
dict(
|
|
469 |
pt=pt,
|
|
470 |
segmentType=segmentType,
|
|
471 |
smooth=smooth,
|
|
472 |
name=name,
|
|
473 |
identifier=identifier,
|
|
474 |
removed=False
|
|
475 |
)
|
|
476 |
)
|
502 | 477 |
|
503 | 478 |
def endPath(self):
|
504 | 479 |
self._flushContour()
|
|
506 | 481 |
|
507 | 482 |
def addComponent(self, baseGlyph, transformation, identifier=None, **kwargs):
|
508 | 483 |
self._pen.addComponent(baseGlyph, transformation, identifier)
|
|
484 |
|
509 | 485 |
|
510 | 486 |
# -------
|
511 | 487 |
# Support
|