Changeset 1017
- Timestamp:
- 11/22/11 19:10:35 (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
packages/defcon/branches/ufo3/Lib/defcon/objects/component.py
r1016 r1017 1 1 import weakref 2 2 from warnings import warn 3 from fontTools.misc.transform import Transform 3 4 from defcon.objects.base import BaseObject 5 6 _defaultTransformation = (1, 0, 0, 1, 0, 0) 4 7 5 8 … … 28 31 self._dirty = False 29 32 self._baseGlyph = None 30 self._transformation = (1, 0, 0, 1, 0, 0)33 self._transformation = tuple(_defaultTransformation) 31 34 self._identifier = None 32 35 … … 66 69 glyph = property(_get_glyph, doc="The :class:`Glyph` that this component belongs to.") 67 70 71 # bounds 72 73 def _getBounds(self, boundsAttr): 74 layer = self.layer 75 if layer is None: 76 return None 77 if self.baseGlyph not in layer: 78 return None 79 glyph = layer[self.baseGlyph] 80 bounds = getattr(glyph, boundsAttr) 81 if bounds is None: 82 return None 83 if self.transformation == _defaultTransformation: 84 return bounds 85 xMin, yMin, xMax, yMax = bounds 86 t = Transform(*self.transformation) 87 points = [(xMin, yMin), (xMax, yMax)] 88 (xMin, yMin), (xMax, yMax) = t.transformPoints(points) 89 return xMin, yMin, xMax, yMax 90 68 91 def _get_bounds(self): 69 from robofab.pens.boundsPen import BoundsPen 70 glyph = self.glyph 71 if glyph is None: 72 return None 73 font = glyph.font 74 if font is None: 75 return None 76 pen = BoundsPen(font) 77 self.draw(pen) 78 return pen.bounds 92 return self._getBounds("bounds") 79 93 80 94 bounds = property(_get_bounds, doc="The bounds of the components's outline expressed as a tuple of form (xMin, yMin, xMax, yMax).") 81 95 82 96 def _get_controlPointBounds(self): 83 from fontTools.pens.boundsPen import ControlBoundsPen 84 glyph = self.glyph 85 if glyph is None: 86 return None 87 font = glyph.font 88 if font is None: 89 return None 90 pen = ControlBoundsPen(font) 91 self.draw(pen) 92 return pen.bounds 97 return self._getBounds("controlPointBounds") 93 98 94 99 controlPointBounds = property(_get_controlPointBounds, doc="The control bounds of all points in the components. This only measures the point positions, it does not measure curves. So, curves without points at the extrema will not be properly measured.") 100 101 # base glyph 95 102 96 103 def _set_baseGlyph(self, value): … … 106 113 107 114 baseGlyph = property(_get_baseGlyph, _set_baseGlyph, doc="The glyph that the components references. Setting this will post *Component.BaseGlyphChanged* and *Component.Changed* notifications.") 115 116 # transformation 108 117 109 118 def _set_transformation(self, value):
Note: See TracChangeset
for help on using the changeset viewer.
