Changeset 1059


Ignore:
Timestamp:
12/15/11 19:48:00 (17 months ago)
Author:
tal
Message:
Added support for decomposing nested components. This should close ticket #12.
Location:
packages/defcon/branches/ufo3/Lib/defcon
Files:
1 added
1 edited

Legend:

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

    r1057 r1059  
    66from defcon.objects.point import Point 
    77from defcon.objects.component import Component 
    8 from defcon.objects.component import _defaultTransformation as _defaultComponentTransformation 
    98from defcon.objects.anchor import Anchor 
    109from defcon.objects.lib import Lib 
     
    1312from defcon.objects.color import Color 
    1413from defcon.tools.representations import glyphBoundsRepresentationFactory, glyphControlPointBoundsRepresentationFactory 
     14from defcon.pens.decomposeComponentPointPen import DecomposeComponentPointPen 
    1515 
    1616def addRepresentationFactory(name, factory): 
     
    634634        self.holdNotifications() 
    635635        layer = self.layer 
    636         pointPen = self.getPointPen() 
     636        pointPen = DecomposeComponentPointPen(self, layer) 
    637637        self._decomposeComponent(component, layer, pointPen) 
    638638        self.releaseHeldNotifications() 
     
    653653        self.holdNotifications() 
    654654        layer = self.layer 
    655         pointPen = self.getPointPen() 
     655        pointPen = DecomposeComponentPointPen(self, layer) 
    656656        for component in self.components: 
    657657            self._decomposeComponent(component, layer, pointPen) 
     
    660660 
    661661    def _decomposeComponent(self, component, layer, pointPen): 
    662         from robofab.pens.adapterPens import TransformPointPen 
    663662        pointPen.skipConflictingIdentifiers = True 
    664         baseGlyph = component.baseGlyph 
    665         if baseGlyph in layer: 
    666             baseGlyph = layer[baseGlyph] 
    667             if component.transformation == _defaultComponentTransformation: 
    668                 baseGlyph.drawPoints(pointPen) 
    669             else: 
    670                 transformPointPen = TransformPointPen(pointPen, component.transformation) 
    671                 baseGlyph.drawPoints(transformPointPen) 
     663        component.drawPoints(pointPen) 
    672664        self.removeComponent(component) 
    673665 
     
    17541746    >>> referenceGlyph[1].identifier 
    17551747    >>> referenceGlyph[1][0].identifier 
     1748 
     1749    >>> from defcon import Font 
     1750    >>> font = Font() 
     1751 
     1752    # nested components 
     1753 
     1754    >>> font.newGlyph("baseGlyph") 
     1755    >>> baseGlyph = font["baseGlyph"] 
     1756    >>> pointPen = baseGlyph.getPointPen() 
     1757    >>> pointPen.beginPath(identifier="contour1") 
     1758    >>> pointPen.addPoint((0, 0), "move", identifier="point1") 
     1759    >>> pointPen.addPoint((0, 100), "line") 
     1760    >>> pointPen.addPoint((100, 100), "line") 
     1761    >>> pointPen.addPoint((100, 0), "line") 
     1762    >>> pointPen.addPoint((0, 0), "line") 
     1763    >>> pointPen.endPath() 
     1764 
     1765    >>> font.newGlyph("referenceGlyph1") 
     1766    >>> referenceGlyph1 = font["referenceGlyph1"] 
     1767    >>> pointPen = referenceGlyph1.getPointPen() 
     1768    >>> pointPen.addComponent("baseGlyph", (1, 0, 0, 1, 3, 6)) 
     1769    >>> font.newGlyph("referenceGlyph2") 
     1770    >>> referenceGlyph2 = font["referenceGlyph2"] 
     1771    >>> pointPen = referenceGlyph2.getPointPen() 
     1772    >>> pointPen.addComponent("referenceGlyph1", (1, 0, 0, 1, 10, 20))  
     1773    >>> referenceGlyph2.decomposeAllComponents() 
     1774    >>> len(referenceGlyph2.components) 
     1775    0 
     1776    >>> len(referenceGlyph1.components) 
     1777    1 
     1778    >>> len(referenceGlyph2) 
     1779    1 
     1780    >>> referenceGlyph2.bounds 
     1781    (13, 26, 113, 126) 
    17561782    """ 
    17571783 
Note: See TracChangeset for help on using the changeset viewer.