Skip to content

Commit

Permalink
add identifier to addComponent callback (#268)
Browse files Browse the repository at this point in the history
+ tabs to spaces
  • Loading branch information
typemytype authored and benkiel committed Nov 18, 2019
1 parent f39457c commit b080b46
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions Lib/defcon/pens/transformPointPen.py
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)

0 comments on commit b080b46

Please sign in to comment.