def round(self, digits=None): """round the geometry.""" copiedGlyph = self.copyWithoutMathSubObjects() # misc copiedGlyph.width = _roundNumber(self.width, digits) copiedGlyph.height = _roundNumber(self.height, digits) # contours copiedGlyph.contours = [] if self.contours: copiedGlyph.contours = _roundContours(self.contours, digits) # components copiedGlyph.components = [] if self.components: copiedGlyph.components = _roundComponents(self.components, digits) # guidelines copiedGlyph.guidelines = [] if self.guidelines: copiedGlyph.guidelines = _roundGuidelines(self.guidelines, digits) # anchors copiedGlyph.anchors = [] if self.anchors: copiedGlyph.anchors = _roundAnchors(self.anchors, digits) # image copiedGlyph.image = None if self.image: copiedGlyph.image = _roundImage(self.image, digits) return copiedGlyph
def round(self, digits=None): excludeFromRounding = ['postscriptBlueScale', 'italicAngle'] copiedInfo = self.copy() # basic attributes for attr, (formatter, factorIndex) in _infoAttrs.items(): if attr in excludeFromRounding: continue if hasattr(copiedInfo, attr): v = getattr(copiedInfo, attr) if v is not None: if factorIndex == 3: v = int(round(v)) else: if isinstance(v, (list, tuple)): v = [_roundNumber(a, digits) for a in v] else: v = _roundNumber(v, digits) else: v = None setattr(copiedInfo, attr, v) # special attributes self._processPostscriptWeightName(copiedInfo) # guidelines copiedInfo.guidelines = [] if self.guidelines: copiedInfo.guidelines = _roundGuidelines(self.guidelines, digits) return copiedInfo
def test_roundGuidelines(self): guidelines = [ dict(x=1.99, y=3.01, angle=5, name="test", identifier="1", color="0,0,0,0") ] expected = [ dict(x=2, y=3, angle=5, name="test", identifier="1", color="0,0,0,0") ] result = _roundGuidelines(guidelines) self.assertEqual(result, expected)