Changeset 318


Ignore:
Timestamp:
01/15/09 02:31:17 (4 years ago)
Author:
tal
Message:
Removed the autoContourDirection method. It was an application specific thing that somehow made it into defcon. If this is needed by other apps, it can come back.
File:
1 edited

Legend:

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

    r314 r318  
    548548        return pen.getResult() 
    549549 
    550     def autoContourDirection(self, baseDirectionIsClockwise=False): 
    551         """ 
    552         Try to set the "proper" contour direction in the glyph. 
    553  
    554         Known Problems: 
    555  
    556         * Speed. This could be sped up by not testing every 
    557           point in overlapping contours, but that would 
    558           result in less accurate results. 
    559         * Contours with points that overlap, but lines 
    560           which intersect with the other contour. Consider 
    561           an "A" with the crossbar defined as a rectangle. 
    562         """ 
    563         baseDirection = baseDirectionIsClockwise 
    564         # if only one contour is present, set 
    565         # the default direction and return 
    566         contourCount = len(self._contours) 
    567         if contourCount < 2: 
    568             for contour in self._contours: 
    569                 contour.clockwise = baseDirection 
    570             return 
    571         # 
    572         countIter = xrange(contourCount) 
    573         intersections = {} 
    574         for index1 in countIter: 
    575             for index2 in countIter: 
    576                 # don't test the same contour with itself 
    577                 if index1 == index2: 
    578                     continue 
    579                 # test for intersection of the two contours 
    580                 bounds1 = self._contours[index1].bounds 
    581                 bounds2 = self._contours[index2].bounds 
    582                 intersects, position = arrayTools.sectRect(bounds1, bounds2) 
    583                 if intersects: 
    584                     # only flag the contours if they are complete overlaps 
    585                     combinedRect = arrayTools.unionRect(bounds1, bounds2) 
    586                     if combinedRect == bounds1 or combinedRect == bounds2: 
    587                         if index1 not in intersections: 
    588                             intersections[index1] = [] 
    589                         intersections[index1].append(index2) 
    590         for index in countIter: 
    591             direction = baseDirection 
    592             contour = self[index] 
    593             intersectingContours = intersections.get(index) 
    594             if intersectingContours: 
    595                 for otherContourIndex in intersectingContours: 
    596                     otherContour = self[otherContourIndex] 
    597                     foundPointOutside = False 
    598                     for point in contour: 
    599                         if not point.segmentType: 
    600                             continue 
    601                         pt = (point.x, point.y) 
    602                         if not otherContour.pointInside(pt): 
    603                             foundPointOutside = True 
    604                             break 
    605                     if foundPointOutside: 
    606                         continue 
    607                     direction += 1 
    608             contour.clockwise = direction % 2 
    609  
    610550    # --------------- 
    611551    # Representations 
     
    11141054    """ 
    11151055 
    1116 def _testAutoContourDirection(): 
    1117     """ 
    1118     >>> from defcon.test.testTools import getTestFontPath 
    1119     >>> from defcon.objects.font import Font 
    1120     >>> font = Font(getTestFontPath('TestContourDirection.ufo')) 
    1121     >>> glyph = font['TestContourDirection1'] 
    1122     >>> for contour in glyph: 
    1123     ...     contour.clockwise = True 
    1124     >>> glyph.autoContourDirection() 
    1125     >>> [contour.clockwise for contour in glyph] 
    1126     [False, True, False] 
    1127     >>> glyph = font['TestContourDirection2'] 
    1128     >>> for contour in glyph: 
    1129     ...     contour.clockwise = True 
    1130     >>> glyph.autoContourDirection() 
    1131     >>> [contour.clockwise for contour in glyph] 
    1132     [False, False, True] 
    1133     >>> glyph = font['TestContourDirection3'] 
    1134     >>> for contour in glyph: 
    1135     ...     contour.clockwise = True 
    1136     >>> glyph.autoContourDirection() 
    1137     >>> [contour.clockwise for contour in glyph] 
    1138     [False, True, True, True, True] 
    1139     >>> glyph = font['TestContourDirection4'] 
    1140     >>> for contour in glyph: 
    1141     ...     contour.clockwise = True 
    1142     >>> glyph.autoContourDirection() 
    1143     >>> [contour.clockwise for contour in glyph] 
    1144     [False, False, True] 
    1145     """ 
    1146  
    11471056if __name__ == "__main__": 
    11481057    import doctest 
Note: See TracChangeset for help on using the changeset viewer.