Changeset 1029
- Timestamp:
- 12/01/11 16:41:43 (18 months ago)
- Location:
- packages/defcon/branches/ufo3/Lib/defcon
- Files:
-
- 2 edited
-
objects/glyph.py (modified) (3 diffs)
-
pens/glyphObjectPointPen.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
packages/defcon/branches/ufo3/Lib/defcon/objects/glyph.py
r1026 r1029 5 5 from defcon.objects.point import Point 6 6 from defcon.objects.component import Component 7 from defcon.objects.component import _defaultTransformation as _defaultComponentTransformation 7 8 from defcon.objects.anchor import Anchor 8 9 from defcon.objects.lib import Lib … … 598 599 self.releaseHeldNotifications() 599 600 601 def decomposeComponent(self, component): 602 """ 603 Decompose **component**. This will preserve the identifiers 604 in the incoming contours and points unless there is a conflict. 605 In that case, the conflicting incoming identifier will be discarded. 606 607 This posts *Glyph.ComponentsChanged*, *Glyph.ContoursChanged* 608 and *Glyph.Changed* notifications. 609 """ 610 self.holdNotifications() 611 layer = self.layer 612 pen = self.getPointPen() 613 pointPen = self.getPointPen() 614 self._decomposeComponent(component, layer, pointPen) 615 self.releaseHeldNotifications() 616 self.postNotification(notification="Glyph.ContoursChanged") 617 618 def decomposeAllComponents(self): 619 """ 620 Decompose all components in this glyph. This will preserve the 621 identifiers in the incoming contours and points unless there is a 622 conflict. In that case, the conflicting incoming identifier will 623 be discarded. 624 625 This posts *Glyph.ComponentsChanged*, *Glyph.ContoursChanged* 626 and *Glyph.Changed* notifications. 627 """ 628 if not self.components: 629 return 630 self.holdNotifications() 631 layer = self.layer 632 pointPen = self.getPointPen() 633 for component in self.components: 634 self._decomposeComponent(component, layer, pointPen) 635 self.releaseHeldNotifications() 636 self.postNotification(notification="Glyph.ContoursChanged") 637 638 def _decomposeComponent(self, component, layer, pointPen): 639 from robofab.pens.adapterPens import TransformPointPen 640 pointPen.skipConflictingIdentifiers = True 641 baseGlyph = component.baseGlyph 642 if baseGlyph in layer: 643 baseGlyph = layer[baseGlyph] 644 if component.transformation == _defaultComponentTransformation: 645 baseGlyph.drawPoints(pointPen) 646 else: 647 transformPointPen = TransformPointPen(pointPen, component.transformation) 648 baseGlyph.drawPoints(transformPointPen) 649 self.removeComponent(component) 650 600 651 # ------- 601 652 # Anchors … … 1615 1666 """ 1616 1667 1668 def _testDecomposeComponents(): 1669 """ 1670 >>> from defcon import Font 1671 >>> font = Font() 1672 1673 >>> font.newGlyph("baseGlyph") 1674 >>> baseGlyph = font["baseGlyph"] 1675 >>> pointPen = baseGlyph.getPointPen() 1676 >>> pointPen.beginPath(identifier="contour1") 1677 >>> pointPen.addPoint((0, 0), "move", identifier="point1") 1678 >>> pointPen.addPoint((0, 100), "line") 1679 >>> pointPen.addPoint((100, 100), "line") 1680 >>> pointPen.addPoint((100, 0), "line") 1681 >>> pointPen.addPoint((0, 0), "line") 1682 >>> pointPen.endPath() 1683 1684 >>> font.newGlyph("referenceGlyph") 1685 >>> referenceGlyph = font["referenceGlyph"] 1686 >>> pointPen = referenceGlyph.getPointPen() 1687 >>> pointPen.addComponent("baseGlyph", (1, 0, 0, 1, 0, 0)) 1688 >>> len(referenceGlyph.components) 1689 1 1690 >>> len(referenceGlyph) 1691 0 1692 >>> referenceGlyph.decomposeAllComponents() 1693 >>> len(referenceGlyph.components) 1694 0 1695 >>> len(referenceGlyph) 1696 1 1697 >>> referenceGlyph[0].identifier 1698 'contour1' 1699 >>> referenceGlyph[0][0].identifier 1700 'point1' 1701 1702 >>> pointPen.addComponent("baseGlyph", (1, 0, 0, 1, 100, 100)) 1703 >>> len(referenceGlyph.components) 1704 1 1705 >>> len(referenceGlyph) 1706 1 1707 >>> component = referenceGlyph.components[0] 1708 >>> referenceGlyph.decomposeComponent(component) 1709 >>> len(referenceGlyph.components) 1710 0 1711 >>> len(referenceGlyph) 1712 2 1713 >>> referenceGlyph[0].identifier 1714 'contour1' 1715 >>> referenceGlyph[0][0].identifier 1716 'point1' 1717 >>> referenceGlyph[1].identifier 1718 >>> referenceGlyph[1][0].identifier 1719 """ 1720 1617 1721 def _testMove(): 1618 1722 """ -
packages/defcon/branches/ufo3/Lib/defcon/pens/glyphObjectPointPen.py
r1022 r1029 6 6 self._glyph = glyph 7 7 self._contour = None 8 self.skipConflictingIdentifiers = False 8 9 9 10 def beginPath(self, identifier=None, **kwargs): 10 11 self._contour = self._glyph.instantiateContour() 11 12 self._contour.disableNotifications() 12 self._contour.identifier = identifier 13 if identifier is not None: 14 if self.skipConflictingIdentifiers and identifier in self._glyph.identifiers: 15 pass 16 else: 17 self._contour.identifier = identifier 13 18 14 19 def endPath(self): … … 19 24 20 25 def addPoint(self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs): 26 if self.skipConflictingIdentifiers and identifier in self._glyph.identifiers: 27 identifier = None 21 28 self._contour.addPoint(pt, segmentType, smooth, name, identifier=identifier) 22 29 23 30 def addComponent(self, baseGlyphName, transformation, identifier=None, **kwargs): 31 if self.skipConflictingIdentifiers and identifier in self._glyph.identifiers: 32 identifier = None 24 33 component = self._glyph.componentClass() 25 34 component.baseGlyph = baseGlyphName
Note: See TracChangeset
for help on using the changeset viewer.
