Example #1
0
 def _processMathOne(self, copiedGlyph, otherGlyph, ptFunc, func):
     # width
     copiedGlyph.width = func(self.width, otherGlyph.width)
     # height
     copiedGlyph.height = func(self.height, otherGlyph.height)
     # contours
     copiedGlyph.contours = []
     if self.contours:
         copiedGlyph.contours = _processMathOneContours(self.contours, otherGlyph.contours, ptFunc)
     # components
     copiedGlyph.components = []
     if self.components:
         componentPairs = _pairComponents(self.components, otherGlyph.components)
         copiedGlyph.components = _processMathOneComponents(componentPairs, ptFunc)
     # anchors
     copiedGlyph.anchors = []
     if self.anchors:
         anchorTree1 = _anchorTree(self.anchors)
         anchorTree2 = _anchorTree(otherGlyph.anchors)
         anchorPairs = _pairAnchors(anchorTree1, anchorTree2)
         copiedGlyph.anchors = _processMathOneAnchors(anchorPairs, ptFunc)
     # guidelines
     copiedGlyph.guidelines = []
     if self.guidelines:
         guidelinePairs = _pairGuidelines(self.guidelines, otherGlyph.guidelines)
         copiedGlyph.guidelines = _processMathOneGuidelines(guidelinePairs, ptFunc, func)
     # image
     copiedGlyph.image = _expandImage(None)
     imagePair = _pairImages(self.image, otherGlyph.image)
     if imagePair:
         copiedGlyph.image = _processMathOneImage(imagePair, ptFunc)
 def _processMathOne(self, copiedInfo, otherInfo, ptFunc, func):
     # basic attributes
     for attr in _infoAttrs.keys():
         a = None
         b = None
         v = None
         if hasattr(copiedInfo, attr):
             a = getattr(copiedInfo, attr)
         if hasattr(otherInfo, attr):
             b = getattr(otherInfo, attr)
         if a is not None and b is not None:
             if isinstance(a, (list, tuple)):
                 v = self._processMathOneNumberList(a, b, func)
             else:
                 v = self._processMathOneNumber(a, b, func)
         elif a is not None and b is None:
             v = a
         elif b is not None and a is None:
             v = b
         if v is not None:
             setattr(copiedInfo, attr, v)
     # special attributes
     self._processPostscriptWeightName(copiedInfo)
     # guidelines
     copiedInfo.guidelines = []
     if self.guidelines:
         guidelinePairs = _pairGuidelines(self.guidelines, otherInfo.guidelines)
         copiedInfo.guidelines = _processMathOneGuidelines(guidelinePairs, ptFunc, func)
Example #3
0
 def _processMathOne(self, copiedGlyph, otherGlyph, ptFunc, func):
     # width
     copiedGlyph.width = func(self.width, otherGlyph.width)
     # height
     copiedGlyph.height = func(self.height, otherGlyph.height)
     # contours
     copiedGlyph.contours = []
     if self.contours:
         copiedGlyph.contours = _processMathOneContours(self.contours, otherGlyph.contours, ptFunc)
     # components
     copiedGlyph.components = []
     if self.components:
         componentPairs = _pairComponents(self.components, otherGlyph.components)
         copiedGlyph.components = _processMathOneComponents(componentPairs, ptFunc)
     # anchors
     copiedGlyph.anchors = []
     if self.anchors:
         anchorTree1 = _anchorTree(self.anchors)
         anchorTree2 = _anchorTree(otherGlyph.anchors)
         anchorPairs = _pairAnchors(anchorTree1, anchorTree2)
         copiedGlyph.anchors = _processMathOneAnchors(anchorPairs, ptFunc)
     # guidelines
     copiedGlyph.guidelines = []
     if self.guidelines:
         guidelinePairs = _pairGuidelines(self.guidelines, otherGlyph.guidelines)
         copiedGlyph.guidelines = _processMathOneGuidelines(guidelinePairs, ptFunc, func)
     # image
     copiedGlyph.image = _expandImage(None)
     imagePair = _pairImages(self.image, otherGlyph.image)
     if imagePair:
         copiedGlyph.image = _processMathOneImage(imagePair, ptFunc)
 def test_processMathOneGuidelines(self):
     guidelines = [
         (
             dict(x=1, y=3, angle=5, name="test", identifier="1", color="0,0,0,0"),
             dict(x=6, y=8, angle=10, name=None, identifier=None, color=None)
         )
     ]
     expected = [
         dict(x=7, y=11, angle=15, name="test", identifier="1", color="0,0,0,0")
     ]
     self.assertEqual(
         _processMathOneGuidelines(guidelines, addPt, add),
         expected
     )
 def test_processMathOneGuidelines(self):
     guidelines = [(dict(x=1,
                         y=3,
                         angle=5,
                         name="test",
                         identifier="1",
                         color="0,0,0,0"),
                    dict(x=6,
                         y=8,
                         angle=10,
                         name=None,
                         identifier=None,
                         color=None))]
     expected = [
         dict(x=7,
              y=11,
              angle=15,
              name="test",
              identifier="1",
              color="0,0,0,0")
     ]
     self.assertEqual(_processMathOneGuidelines(guidelines, addPt, add),
                      expected)
Example #6
0
 def _processMathOne(self, copiedInfo, otherInfo, ptFunc, func):
     # basic attributes
     for attr in _infoAttrs.keys():
         a = None
         b = None
         v = None
         if hasattr(copiedInfo, attr):
             a = getattr(copiedInfo, attr)
         if hasattr(otherInfo, attr):
             b = getattr(otherInfo, attr)
         if a is not None and b is not None:
             if isinstance(a, (list, tuple)):
                 v = self._processMathOneNumberList(a, b, func)
             else:
                 v = self._processMathOneNumber(a, b, func)
         # when one of the terms is undefined, we treat addition and subtraction
         # differently...
         # https://github.com/robotools/fontMath/issues/175
         # https://github.com/robotools/fontMath/issues/136
         elif a is not None and b is None:
             if func == add:
                 v = a
             else:
                 v = None if attr in _numberListAttrs else 0
         elif b is not None and a is None:
             if func is add:
                 v = b
             else:
                 v = None if attr in _numberListAttrs else 0
         setattr(copiedInfo, attr, v)
     # special attributes
     self._processPostscriptWeightName(copiedInfo)
     # guidelines
     copiedInfo.guidelines = []
     if self.guidelines:
         guidelinePairs = _pairGuidelines(self.guidelines, otherInfo.guidelines)
         copiedInfo.guidelines = _processMathOneGuidelines(guidelinePairs, ptFunc, func)