-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add identifier to addComponent callback (#268)
+ tabs to spaces
- Loading branch information
1 parent
f39457c
commit b080b46
Showing
1 changed file
with
27 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,36 @@ | ||
from fontTools.pens.pointPen import AbstractPointPen | ||
from warnings import warn | ||
|
||
|
||
class TransformPointPen(AbstractPointPen): | ||
|
||
"""PointPen that transforms all coordinates, and passes them to another | ||
PointPen. It also transforms the transformation given to addComponent(). | ||
""" | ||
"""PointPen that transforms all coordinates, and passes them to another | ||
PointPen. It also transforms the transformation given to addComponent(). | ||
""" | ||
|
||
def __init__(self, outPen, transformation): | ||
if not hasattr(transformation, "transformPoint"): | ||
from fontTools.misc.transform import Transform | ||
transformation = Transform(*transformation) | ||
self._transformation = transformation | ||
self._transformPoint = transformation.transformPoint | ||
self._outPen = outPen | ||
self._stack = [] | ||
def __init__(self, outPen, transformation): | ||
if not hasattr(transformation, "transformPoint"): | ||
from fontTools.misc.transform import Transform | ||
transformation = Transform(*transformation) | ||
self._transformation = transformation | ||
self._transformPoint = transformation.transformPoint | ||
self._outPen = outPen | ||
self._stack = [] | ||
|
||
def beginPath(self, identifier=None): | ||
self._outPen.beginPath(identifier=identifier) | ||
def beginPath(self, identifier=None): | ||
self._outPen.beginPath(identifier=identifier) | ||
|
||
def endPath(self): | ||
self._outPen.endPath() | ||
def endPath(self): | ||
self._outPen.endPath() | ||
|
||
def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs): | ||
pt = self._transformPoint(pt) | ||
self._outPen.addPoint(pt, segmentType, smooth, name, **kwargs) | ||
def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs): | ||
pt = self._transformPoint(pt) | ||
self._outPen.addPoint(pt, segmentType, smooth, name, **kwargs) | ||
|
||
def addComponent(self, glyphName, transformation): | ||
transformation = self._transformation.transform(transformation) | ||
self._outPen.addComponent(glyphName, transformation) | ||
def addComponent(self, glyphName, transformation, identifier=None): | ||
transformation = self._transformation.transform(transformation) | ||
try: | ||
self._outPen.addComponent(glyphName, transformation, identifier) | ||
except TypeError: | ||
self._outPen.addComponent(glyphName, transformation) | ||
warn("The addComponent method needs an identifier kwarg. The component's identifier value has been discarded.", DeprecationWarning) |