Changeset 88
- Timestamp:
- 05/30/08 04:47:54 (4 years ago)
- Files:
-
- trunk/Lib/robofab/pens/marginPen.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Lib/robofab/pens/marginPen.py
r87 r88 19 19 def __init__(self, glyphSet, height): 20 20 BasePen.__init__(self, glyphSet) 21 22 21 self.height = height 23 22 self.hits = {} 24 23 self.filterDoubles = True 25 24 self.contourIndex = None 25 self.startPt = None 26 26 27 27 def _moveTo(self, pt): 28 28 self.currentPt = pt 29 self.startPt = pt 29 30 if self.contourIndex is None: 30 31 self.contourIndex = 0 … … 50 51 if not self.contourIndex in self.hits: 51 52 self.hits[self.contourIndex] = [] 52 53 53 self.hits[self.contourIndex].append(pt[0]) 54 54 self.currentPt = pt … … 56 56 def _curveToOne(self, pt1, pt2, pt3): 57 57 hits = splitCubic(self.currentPt, pt1, pt2, pt3, self.height, True) 58 if len(hits)==2: 58 for i in range(len(hits)-1): 59 # a number of intersections is possible. Just take the 60 # last point of each segment. 59 61 if not self.contourIndex in self.hits: 60 62 self.hits[self.contourIndex] = [] 61 self.hits[self.contourIndex].append(round(hits[ 0][-1][0], 4))62 elif pt3[1] == self.height:63 self.hits[self.contourIndex].append(round(hits[i][-1][0], 4)) 64 if pt3[1] == self.height: 63 65 # it could happen 64 66 if not self.contourIndex in self.hits: … … 68 70 69 71 def _closePath(self): 70 self.currentPt = None 72 if self.currentPt != self.startPt: 73 self._lineTo(self.startPt) 74 self.currentPt = self.startPt = None 71 75 72 76 def _endPath(self): 73 77 self.currentPt = None 78 79 def addComponent(self, baseGlyph, transformation): 80 if self.glyphSet is None: 81 return 82 if baseGlyph in self.glyphSet: 83 glyph = self.glyphSet[baseGlyph] 84 if glyph is not None: 85 glyph.draw(self) 74 86 75 87 def getMargins(self): … … 78 90 for index, pts in self.hits.items(): 79 91 allHits.extend(pts) 80 unique = list(Set(allHits)) 81 unique.sort() 82 if unique: 83 return min(unique), max(unique) 92 if allHits: 93 return min(allHits), max(allHits) 84 94 return None 85 95 … … 93 103 return allHits 94 104 95 def addComponent(self, baseGlyph, transformation):96 if self.glyphSet is None:97 return98 if baseGlyph in self.glyphSet:99 glyph = self.glyphSet[baseGlyph]100 if glyph is not None:101 glyph.draw(self)102 105 103 106 … … 108 111 g = CurrentGlyph() 109 112 110 pt = ( 100, 249)113 pt = (74, 216) 111 114 pen = MarginPen(f, pt[1]) 112 115 g.draw(pen) 113 116 print 'glyph margins', pen.getMargins() 114 115 117 print pen.getContourMargins()
