<s> '''<STR_LIT>''' <EOL> from TFSPoint import * <EOL> from TFSPath import * <EOL> class TFSGlyph ( object ) : <EOL> def __init__ ( self , rfglyph ) : <EOL> self . rfglyph = rfglyph <EOL> unicode = property ( lambda self : self . rfglyph . unicode ) <EOL> def getContours ( self , setSelected = False ) : <EOL> def rfPointToTFSPoint ( rfpoint ) : <EOL> fiPoint = TFSPoint ( rfpoint . x , rfpoint . y ) <EOL> if setSelected : <EOL> fiPoint . selected = rfpoint . selected <EOL> return fiPoint <EOL> paths = [ ] <EOL> for rfcontour in self . rfglyph : <EOL> segments = [ ] <EOL> lastPoint = rfPointToTFSPoint ( rfcontour [ - <NUM_LIT:1> ] . points [ - <NUM_LIT:1> ] ) <EOL> for rfsegment in rfcontour : <EOL> fiPoints = [ lastPoint , ] + [ rfPointToTFSPoint ( rfpoint ) for rfpoint in rfsegment . points ] <EOL> lastPoint = fiPoints [ - <NUM_LIT:1> ] <EOL> if ( len ( fiPoints ) == <NUM_LIT:2> ) and fiPoints [ <NUM_LIT:0> ] == fiPoints [ - <NUM_LIT:1> ] : <EOL> print '<STR_LIT>' + hex ( self . rfglyph . unicode ) <EOL> continue <EOL> rfendpoint = rfsegment . points [ - <NUM_LIT:1> ] <EOL> if rfendpoint . type == '<STR_LIT>' : <EOL> lastOnPoint = fiPoints [ <NUM_LIT:0> ] <EOL> offPoints = fiPoints [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> for index in xrange ( len ( offPoints ) - <NUM_LIT:1> ) : <EOL> offPoint0 = offPoints [ index + <NUM_LIT:0> ] <EOL> offPoint1 = offPoints [ index + <NUM_LIT:1> ] <EOL> impliedPoint = offPoint0 . midpoint ( offPoint1 ) <EOL> segments . append ( TFSSegment ( lastOnPoint , offPoint0 , impliedPoint ) ) <EOL> lastOnPoint = impliedPoint <EOL> segments . append ( TFSSegment ( lastOnPoint , offPoints [ - <NUM_LIT:1> ] , fiPoints [ - <NUM_LIT:1> ] ) ) <EOL> else : <EOL> segments . append ( TFSSegment ( * fiPoints ) ) <EOL> paths . append ( TFSPath ( True , * segments ) ) <EOL> return paths <EOL> def setContours ( self , paths ) : <EOL> self . rfglyph . clearContours ( ) <EOL> glyphPen = self . rfglyph . getPen ( ) <EOL> def formatScalar ( value ) : <EOL> return int ( round ( value ) ) <EOL> def formatPoint ( value ) : <EOL> result = ( formatScalar ( value . x ) , <EOL> formatScalar ( value . y ) , ) <EOL> return result <EOL> for path in paths : <EOL> firstPoint = path . segments [ <NUM_LIT:0> ] . points [ <NUM_LIT:0> ] <EOL> glyphPen . moveTo ( formatPoint ( firstPoint ) ) <EOL> for segment in path . segments : <EOL> if len ( segment . points ) == <NUM_LIT:4> : <EOL> p1 = segment . points [ <NUM_LIT:1> ] <EOL> p2 = segment . points [ <NUM_LIT:2> ] <EOL> p3 = segment . points [ <NUM_LIT:3> ] <EOL> glyphPen . curveTo ( formatPoint ( p1 ) , <EOL> formatPoint ( p2 ) , <EOL> formatPoint ( p3 ) ) <EOL> elif len ( segment . points ) == <NUM_LIT:3> : <EOL> p1 = segment . points [ <NUM_LIT:1> ] <EOL> p2 = segment . points [ <NUM_LIT:2> ] <EOL> glyphPen . curveTo ( formatPoint ( p1 ) , <EOL> formatPoint ( p2 ) ) <EOL> elif len ( segment . points ) == <NUM_LIT:2> : <EOL> p1 = segment . points [ <NUM_LIT:1> ] <EOL> glyphPen . lineTo ( formatPoint ( p1 ) ) <EOL> else : <EOL> raise Exception ( '<STR_LIT>' + str ( len ( segment . points ) ) ) <EOL> glyphPen . closePath ( ) <EOL> self . rfglyph . update ( ) <EOL> def updateDerivedFromGlyph ( self , codePoint , contours , srcGlyph ) : <EOL> opentype_multiplier = <NUM_LIT:1> <EOL> def formatOpentypeScalar ( value ) : <EOL> return int ( round ( opentype_multiplier * value ) ) <EOL> self . rfglyph . unicode = codePoint <EOL> self . rfglyph . width = formatOpentypeScalar ( srcGlyph . rfglyph . width ) <EOL> self . setContours ( contours ) </s>
