예제 #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)
예제 #2
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)
예제 #3
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)
         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)
 def test_pairGuidelines_name(self):
     guidelines1 = [
         dict(name="foo", identifier="1", x=1, y=2, angle=1),
         dict(name="bar", identifier="2", x=1, y=2, angle=2),
     ]
     guidelines2 = [
         dict(name="bar", identifier="3", x=3, y=4, angle=3),
         dict(name="foo", identifier="4", x=3, y=4, angle=4)
     ]
     expected = [(dict(name="foo", identifier="1", x=1, y=2, angle=1),
                  dict(name="foo", identifier="4", x=3, y=4, angle=4)),
                 (dict(name="bar", identifier="2", x=1, y=2, angle=2),
                  dict(name="bar", identifier="3", x=3, y=4, angle=3))]
     self.assertEqual(_pairGuidelines(guidelines1, guidelines2), expected)
 def test_pairGuidelines_identifier_x_y_angle(self):
     guidelines1 = [
         dict(name="foo", identifier="1", x=1, y=2, angle=1),
         dict(name="bar", identifier="2", x=3, y=4, angle=2),
     ]
     guidelines2 = [
         dict(name="xxx", identifier="2", x=3, y=4, angle=2),
         dict(name="yyy", identifier="1", x=1, y=2, angle=1)
     ]
     expected = [(dict(name="foo", identifier="1", x=1, y=2, angle=1),
                  dict(name="yyy", identifier="1", x=1, y=2, angle=1)),
                 (dict(name="bar", identifier="2", x=3, y=4, angle=2),
                  dict(name="xxx", identifier="2", x=3, y=4, angle=2))]
     self.assertEqual(_pairGuidelines(guidelines1, guidelines2), expected)
예제 #6
0
 def test_pairGuidelines_name_x_y_angle(self):
     guidelines1 = [
         dict(name="foo", identifier="1", x=1, y=2, angle=1),
         dict(name="foo", identifier="2", x=3, y=4, angle=2),
     ]
     guidelines2 = [
         dict(name="foo", identifier="3", x=3, y=4, angle=2),
         dict(name="foo", identifier="4", x=1, y=2, angle=1)
     ]
     expected = [
         (
             dict(name="foo", identifier="1", x=1, y=2, angle=1),
             dict(name="foo", identifier="4", x=1, y=2, angle=1)
         ),
         (
             dict(name="foo", identifier="2", x=3, y=4, angle=2),
             dict(name="foo", identifier="3", x=3, y=4, angle=2)
         )
     ]
     self.assertEqual(
         _pairGuidelines(guidelines1, guidelines2),
         expected
     )
예제 #7
0
 def test_pairGuidelines_identifier(self):
     guidelines1 = [
         dict(name="foo", identifier="1", x=1, y=2, angle=1),
         dict(name="bar", identifier="2", x=1, y=2, angle=2),
     ]
     guidelines2 = [
         dict(name="xxx", identifier="2", x=3, y=4, angle=3),
         dict(name="yyy", identifier="1", x=3, y=4, angle=4)
     ]
     expected = [
         (
             dict(name="foo", identifier="1", x=1, y=2, angle=1),
             dict(name="yyy", identifier="1", x=3, y=4, angle=4)
         ),
         (
             dict(name="bar", identifier="2", x=1, y=2, angle=2),
             dict(name="xxx", identifier="2", x=3, y=4, angle=3)
         )
     ]
     self.assertEqual(
         _pairGuidelines(guidelines1, guidelines2),
         expected
     )
예제 #8
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)