@@ -70,7 +70,19 @@ class MathGlyph(object):
7070 same order as the original.
7171 """
7272
73- def __init__ (self , glyph ):
73+ def __init__ (self , glyph , scaleComponentTransform = True ):
74+ """Initialize a new MathGlyph object.
75+
76+ Args:
77+ glyph: Input defcon or defcon-like Glyph object to copy from. Set to None to
78+ to make an empty MathGlyph.
79+ scaleComponentTransform (bool): when performing multiplication or division, by
80+ default all elements of a component's affine transformation matrix are
81+ multiplied by the given scalar. If scaleComponentTransform is False, then
82+ only the component's xOffset and yOffset attributes are scaled, whereas the
83+ xScale, xyScale, yxScale and yScale attributes are kept unchanged.
84+ """
85+ self .scaleComponentTransform = scaleComponentTransform
7486 self .contours = []
7587 self .components = []
7688 if glyph is None :
@@ -220,7 +232,9 @@ def _processMathTwo(self, copiedGlyph, factor, ptFunc, func):
220232 # components
221233 copiedGlyph .components = []
222234 if self .components :
223- copiedGlyph .components = _processMathTwoComponents (self .components , factor , ptFunc )
235+ copiedGlyph .components = _processMathTwoComponents (
236+ self .components , factor , ptFunc , scaleComponentTransform = self .scaleComponentTransform
237+ )
224238 # anchors
225239 copiedGlyph .anchors = []
226240 if self .anchors :
@@ -689,11 +703,13 @@ def _processMathOneComponents(componentPairs, func):
689703 result .append (component )
690704 return result
691705
692- def _processMathTwoComponents (components , factor , func ):
706+ def _processMathTwoComponents (components , factor , func , scaleComponentTransform = True ):
693707 result = []
694708 for component in components :
695709 component = dict (component )
696- component ["transformation" ] = _processMathTwoTransformation (component ["transformation" ], factor , func )
710+ component ["transformation" ] = _processMathTwoTransformation (
711+ component ["transformation" ], factor , func , doScale = scaleComponentTransform
712+ )
697713 result .append (component )
698714 return result
699715
@@ -761,10 +777,11 @@ def _processMathOneTransformation(transformation1, transformation2, func):
761777 xOffset , yOffset = func ((xOffset1 , yOffset1 ), (xOffset2 , yOffset2 ))
762778 return (xScale , xyScale , yxScale , yScale , xOffset , yOffset )
763779
764- def _processMathTwoTransformation (transformation , factor , func ):
780+ def _processMathTwoTransformation (transformation , factor , func , doScale = True ):
765781 xScale , xyScale , yxScale , yScale , xOffset , yOffset = transformation
766- xScale , yScale = func ((xScale , yScale ), factor )
767- xyScale , yxScale = func ((xyScale , yxScale ), factor )
782+ if doScale :
783+ xScale , yScale = func ((xScale , yScale ), factor )
784+ xyScale , yxScale = func ((xyScale , yxScale ), factor )
768785 xOffset , yOffset = func ((xOffset , yOffset ), factor )
769786 return (xScale , xyScale , yxScale , yScale , xOffset , yOffset )
770787
0 commit comments