Changeset 1017


Ignore:
Timestamp:
11/22/11 19:10:35 (18 months ago)
Author:
tal
Message:
Recent change from the trunk.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • packages/defcon/branches/ufo3/Lib/defcon/objects/component.py

    r1016 r1017  
    11import weakref 
    22from warnings import warn 
     3from fontTools.misc.transform import Transform 
    34from defcon.objects.base import BaseObject 
     5 
     6_defaultTransformation = (1, 0, 0, 1, 0, 0) 
    47 
    58 
     
    2831        self._dirty = False 
    2932        self._baseGlyph = None 
    30         self._transformation = (1, 0, 0, 1, 0, 0) 
     33        self._transformation = tuple(_defaultTransformation) 
    3134        self._identifier = None 
    3235 
     
    6669    glyph = property(_get_glyph, doc="The :class:`Glyph` that this component belongs to.") 
    6770 
     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 
    6891    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") 
    7993 
    8094    bounds = property(_get_bounds, doc="The bounds of the components's outline expressed as a tuple of form (xMin, yMin, xMax, yMax).") 
    8195 
    8296    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") 
    9398 
    9499    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 
    95102 
    96103    def _set_baseGlyph(self, value): 
     
    106113 
    107114    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 
    108117 
    109118    def _set_transformation(self, value): 
Note: See TracChangeset for help on using the changeset viewer.