<s> """<STR_LIT>""" <EOL> importErrors = [ ] <EOL> try : <EOL> import numpy <EOL> except : <EOL> importErrors . append ( "<STR_LIT>" ) <EOL> try : <EOL> import fontTools <EOL> except ImportError : <EOL> importErrors . append ( "<STR_LIT>" ) <EOL> try : <EOL> import woffTools <EOL> except ImportError : <EOL> importErrors . append ( "<STR_LIT>" ) <EOL> if importErrors : <EOL> import sys <EOL> print "<STR_LIT>" , "<STR_LIT:U+002CU+0020>" . join ( importErrors ) <EOL> sys . exit ( ) <EOL> import os <EOL> import optparse <EOL> import unicodedata <EOL> from woffTools import WOFFFont <EOL> from woffTools . tools . css import makeFontFaceRule , makeFontFaceFontFamily <EOL> from woffTools . tools . support import startHTML , finishHTML , findUniqueFileName <EOL> def writeFileInfo ( font , fontPath , writer ) : <EOL> writer . begintag ( "<STR_LIT>" , c_l_a_s_s = "<STR_LIT>" ) <EOL> writer . begintag ( "<STR_LIT>" , c_l_a_s_s = "<STR_LIT>" ) <EOL> writer . write ( "<STR_LIT>" ) <EOL> writer . endtag ( "<STR_LIT>" ) <EOL> writer . begintag ( "<STR_LIT>" , c_l_a_s_s = "<STR_LIT>" ) <EOL> writeFileInfoRow ( "<STR_LIT>" , os . path . basename ( fontPath ) , writer ) <EOL> writeFileInfoRow ( "<STR_LIT>" , os . path . dirname ( fontPath ) , writer ) <EOL> writeFileInfoRow ( "<STR_LIT>" , "<STR_LIT>" % ( font . majorVersion , font . minorVersion ) , writer ) <EOL> writer . endtag ( "<STR_LIT>" ) <EOL> writer . endtag ( "<STR_LIT>" ) <EOL> def writeFileInfoRow ( title , value , writer ) : <EOL> writer . begintag ( "<STR_LIT>" ) <EOL> writer . begintag ( "<STR_LIT>" , c_l_a_s_s = "<STR_LIT:title>" ) <EOL> writer . write ( title ) <EOL> writer . endtag ( "<STR_LIT>" ) <EOL> writer . begintag ( "<STR_LIT>" ) <EOL> writer . write ( value ) <EOL> writer . endtag ( "<STR_LIT>" ) <EOL> writer . endtag ( "<STR_LIT>" ) <EOL> def writeCharacterSet ( font , writer , pointSizes = [ <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , sampleText = None ) : <EOL> characterSet = makeCharacterSet ( font ) <EOL> for size in pointSizes : <EOL> writer . begintag ( "<STR_LIT>" , c_l_a_s_s = "<STR_LIT>" ) <EOL> writer . begintag ( "<STR_LIT>" , c_l_a_s_s = "<STR_LIT>" ) <EOL> writer . write ( "<STR_LIT>" % size ) <EOL> writer . endtag ( "<STR_LIT>" ) <EOL> writer . begintag ( "<STR_LIT:p>" , style = "<STR_LIT>" % size , c_l_a_s_s = "<STR_LIT>" ) <EOL> writer . write ( characterSet ) <EOL> writer . endtag ( "<STR_LIT:p>" ) <EOL> if sampleText : <EOL> writer . begintag ( "<STR_LIT:p>" , style = "<STR_LIT>" % size , c_l_a_s_s = "<STR_LIT>" ) <EOL> writer . write ( sampleText ) <EOL> writer . endtag ( "<STR_LIT:p>" ) <EOL> writer . endtag ( "<STR_LIT>" ) <EOL> def makeCharacterSet ( font ) : <EOL> cmap = font [ "<STR_LIT>" ] <EOL> table = cmap . getcmap ( <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> mapping = table . cmap <EOL> categorizedCharacters = { } <EOL> glyphNameToCharacter = { } <EOL> for value , glyphName in sorted ( mapping . items ( ) ) : <EOL> character = unichr ( value ) <EOL> if not character . strip ( ) : <EOL> continue <EOL> if glyphName not in glyphNameToCharacter : <EOL> glyphNameToCharacter [ glyphName ] = [ ] <EOL> glyphNameToCharacter [ glyphName ] . append ( character ) <EOL> sortedCharacters = [ ] <EOL> for glyphName in font . getGlyphOrder ( ) : <EOL> if glyphName in glyphNameToCharacter : <EOL> sortedCharacters += glyphNameToCharacter [ glyphName ] <EOL> return u"<STR_LIT>" . join ( sortedCharacters ) <EOL> def proofFont ( font , fontPath , sampleText = None ) : <EOL> """<STR_LIT>""" <EOL> title = "<STR_LIT>" % os . path . basename ( fontPath ) <EOL> cssReplacements = { <EOL> "<STR_LIT>" : makeFontFaceRule ( font , fontPath , doLocalSrc = False ) , <EOL> "<STR_LIT>" : makeFontFaceFontFamily ( font ) <EOL> } <EOL> writer = startHTML ( title = title , cssReplacements = cssReplacements ) <EOL> writeFileInfo ( font , fontPath , writer ) <EOL> writeCharacterSet ( font , writer , sampleText = sampleText ) <EOL> text = finishHTML ( writer ) <EOL> text = text . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return text <EOL> usage = "<STR_LIT>" <EOL> description = """<STR_LIT>""" <EOL> defaultSampleText = "<STR_LIT>" <EOL> def main ( ) : <EOL> parser = optparse . OptionParser ( usage = usage , description = description , version = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . set_defaults ( excludeTests = [ ] ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> outputDirectory = options . outputDirectory <EOL> if outputDirectory is not None and not os . path . exists ( outputDirectory ) : <EOL> print "<STR_LIT>" , outputDirectory <EOL> sys . exit ( ) <EOL> sampleText = defaultSampleText <EOL> if options . sampleTextFile : <EOL> if not os . path . exists ( options . sampleTextFile ) : <EOL> print "<STR_LIT>" , options . sampleTextFile <EOL> sys . exit ( ) <EOL> f = open ( options . sampleTextFile , "<STR_LIT:r>" ) <EOL> sampleText = f . read ( ) <EOL> f . close ( ) <EOL> for fontPath in args : <EOL> if not os . path . exists ( fontPath ) : <EOL> print "<STR_LIT>" , fontPath <EOL> sys . exit ( ) <EOL> else : <EOL> print "<STR_LIT>" % fontPath <EOL> fontPath = fontPath . decode ( "<STR_LIT:utf-8>" ) <EOL> font = WOFFFont ( fontPath ) <EOL> html = proofFont ( font , fontPath , sampleText = sampleText ) <EOL> if options . outputFileName is not None : <EOL> fileName = options . outputFileName <EOL> else : <EOL> fileName = os . path . splitext ( os . path . basename ( fontPath ) ) [ <NUM_LIT:0> ] <EOL> fileName += "<STR_LIT>" <EOL> if options . outputDirectory is not None : <EOL> directory = options . outputDirectory <EOL> else : <EOL> directory = os . path . dirname ( fontPath ) <EOL> path = os . path . join ( directory , fileName ) <EOL> path = findUniqueFileName ( path ) <EOL> f = open ( path , "<STR_LIT:wb>" ) <EOL> f . write ( html ) <EOL> f . close ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
