<s> '''<STR_LIT>''' <EOL> import os <EOL> import sys <EOL> from robofab . world import CurrentGlyph , CurrentFont <EOL> import RFUtils <EOL> RFUtils . hackPathIfNecessary ( ) <EOL> from tfs . common . TFSPath import TFSPath <EOL> from tfs . common . TFSSegment import TFSSegment <EOL> from tfs . common . TFSPoint import TFSPoint <EOL> from tfs . common . TFSGlyph import TFSGlyph <EOL> def processGlyph ( glyph , glyphName , paths ) : <EOL> newPaths = [ ] <EOL> for path in paths : <EOL> newSegments = [ ] <EOL> for segment in path . segments : <EOL> if len ( segment . points ) == <NUM_LIT:4> : <EOL> p0 , p1 , p2 , p3 = segment . points <EOL> if p0 == p1 and p2 == p3 : <EOL> print '<STR_LIT>' , glyphName <EOL> segment = TFSSegment ( p0 , p3 ) <EOL> newSegments . append ( segment ) <EOL> newPaths . append ( TFSPath ( True , * newSegments ) ) <EOL> return newPaths <EOL> def cleanupGlyphContours ( glyph ) : <EOL> glyph = TFSGlyph ( glyph ) <EOL> glyphName = hex ( glyph . unicode ) if glyph . unicode is not None else '<STR_LIT>' <EOL> paths = glyph . getContours ( setSelected = True ) <EOL> paths = processGlyph ( glyph , glyphName , paths ) <EOL> glyph . setContours ( paths ) <EOL> def cleanupFontContours ( font ) : <EOL> glyphs = [ glyph for glyph in font ] <EOL> glyphs . sort ( lambda g0 , g1 : cmp ( g0 . unicode , g1 . unicode ) ) <EOL> for index , glyph in enumerate ( glyphs ) : <EOL> glyphName = hex ( glyph . unicode ) if glyph . unicode is not None else '<STR_LIT>' <EOL> print '<STR_LIT:U+0020>' . join ( [ '<STR_LIT>' , <EOL> str ( index ) , <EOL> '<STR_LIT:/>' , <EOL> str ( len ( glyphs ) ) , <EOL> '<STR_LIT>' , <EOL> glyphName ] ) <EOL> cleanupGlyphContours ( glyph ) <EOL> font . update ( ) <EOL> def cleanupCurrentFontContours ( ) : <EOL> font = CurrentFont ( ) <EOL> if font is None : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> cleanupFontContours ( font ) <EOL> def cleanupCurrentGlyphContours ( ) : <EOL> glyph = CurrentGlyph ( ) <EOL> if glyph is None : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> cleanupGlyphContours ( glyph ) </s>
