<s> kFontInstanceFileName = "<STR_LIT>" <EOL> kInstancesDataFileName = "<STR_LIT>" <EOL> __copyright__ = __license__ = """<STR_LIT>""" <EOL> __usage__ = """<STR_LIT>""" <EOL> __help__ = __usage__ + """<STR_LIT>""" <EOL> __doc__ = """<STR_LIT>""" <EOL> import os , sys , time , copy , re , math , shutil <EOL> from subprocess import Popen , PIPE <EOL> from robofab . world import NewFont , OpenFont <EOL> from robofab . objects import objectsBase <EOL> fdkExtrasDir = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> pyScriptsDir = os . path . dirname ( fdkExtrasDir ) <EOL> pyModulesDir = os . path . join ( os . path . dirname ( pyScriptsDir ) , "<STR_LIT>" ) <EOL> if pyModulesDir not in sys . path : <EOL> sys . path . append ( pyModulesDir ) <EOL> try : <EOL> import WriteFeaturesKernFDK , WriteFeaturesMarkFDK <EOL> except ImportError : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> print "<STR_LIT>" , os . path . abspath ( os . getcwd ( ) ) <EOL> print "<STR_LIT>" , <EOL> print "<STR_LIT>" . join ( sys . path ) <EOL> print <EOL> raise <EOL> kFieldsKey = "<STR_LIT>" <EOL> kFamilyName = "<STR_LIT>" <EOL> kFontName = "<STR_LIT>" <EOL> kFullName = "<STR_LIT>" <EOL> kWeight = "<STR_LIT>" <EOL> kCoordsKey = "<STR_LIT>" <EOL> kIsBoldKey = "<STR_LIT>" <EOL> kForceBold = "<STR_LIT>" <EOL> kIsItalicKey = "<STR_LIT>" <EOL> kExceptionSuffixes = "<STR_LIT>" <EOL> kExtraGlyphs = "<STR_LIT>" <EOL> kMasters = "<STR_LIT>" <EOL> kFixedFieldKeys = { <EOL> <NUM_LIT:0> : kFamilyName , <EOL> <NUM_LIT:1> : kFontName , <EOL> <NUM_LIT:2> : kFullName , <EOL> <NUM_LIT:3> : kWeight , <EOL> <NUM_LIT:4> : kCoordsKey , <EOL> <NUM_LIT:5> : kIsBoldKey , <EOL> } <EOL> kNumFixedFields = len ( kFixedFieldKeys ) <EOL> kBlueScale = "<STR_LIT>" <EOL> kBlueShift = "<STR_LIT>" <EOL> kBlueFuzz = "<STR_LIT>" <EOL> kBlueValues = "<STR_LIT>" <EOL> kOtherBlues = "<STR_LIT>" <EOL> kFamilyBlues = "<STR_LIT>" <EOL> kFamilyOtherBlues = "<STR_LIT>" <EOL> kStdHW = "<STR_LIT>" <EOL> kStdVW = "<STR_LIT>" <EOL> kStemSnapH = "<STR_LIT>" <EOL> kStemSnapV = "<STR_LIT>" <EOL> kHintingKeys = [ kBlueScale , kBlueShift , kBlueFuzz , kBlueValues , kOtherBlues , kFamilyBlues , kFamilyOtherBlues , kStdHW , kStdVW , kStemSnapH , kStemSnapV ] <EOL> kAlignmentZonesKeys = [ kBlueValues , kOtherBlues , kFamilyBlues , kFamilyOtherBlues ] <EOL> kTopAlignZonesKeys = [ kBlueValues , kFamilyBlues ] <EOL> kMaxTopZonesSize = <NUM_LIT> <EOL> kBotAlignZonesKeys = [ kOtherBlues , kFamilyOtherBlues ] <EOL> kMaxBotZonesSize = <NUM_LIT:10> <EOL> kStdStemsKeys = [ kStdHW , kStdVW ] <EOL> kMaxStdStemsSize = <NUM_LIT:1> <EOL> kStemSnapKeys = [ kStemSnapH , kStemSnapV ] <EOL> kMaxStemSnapSize = <NUM_LIT:12> <EOL> def validateArrayValues ( arrayList , valuesMustBePositive ) : <EOL> for i in range ( len ( arrayList ) ) : <EOL> try : <EOL> arrayList [ i ] = eval ( arrayList [ i ] ) <EOL> except ( NameError , SyntaxError ) : <EOL> return <EOL> if valuesMustBePositive : <EOL> if arrayList [ i ] < <NUM_LIT:0> : <EOL> return <EOL> return arrayList <EOL> def readInstanceFile ( instancesFilePath ) : <EOL> f = open ( instancesFilePath , "<STR_LIT>" ) <EOL> data = f . read ( ) <EOL> f . close ( ) <EOL> lines = data . splitlines ( ) <EOL> i = <NUM_LIT:0> <EOL> parseError = <NUM_LIT:0> <EOL> keyDict = copy . copy ( kFixedFieldKeys ) <EOL> numKeys = kNumFixedFields <EOL> numLines = len ( lines ) <EOL> instancesList = [ ] <EOL> for i in range ( numLines ) : <EOL> line = lines [ i ] <EOL> line2 = line . strip ( ) <EOL> if not line2 : <EOL> continue <EOL> commentIndex = line . find ( '<STR_LIT:#>' ) <EOL> if commentIndex >= <NUM_LIT:0> : <EOL> if line . startswith ( kFieldsKey ) : <EOL> if instancesList : <EOL> print >> sys . stderr , "<STR_LIT>" % kFieldsKey <EOL> raise <EOL> line = line [ len ( kFieldsKey ) : ] <EOL> line = line . strip ( ) <EOL> keys = line . split ( '<STR_LIT:\t>' ) <EOL> keys = map ( lambda name : name . strip ( ) , keys ) <EOL> numKeys = len ( keys ) <EOL> k = kNumFixedFields <EOL> while k < numKeys : <EOL> keyDict [ k ] = keys [ k ] <EOL> k += <NUM_LIT:1> <EOL> continue <EOL> else : <EOL> line = line [ : commentIndex ] <EOL> continue <EOL> fields = line . split ( '<STR_LIT:\t>' ) <EOL> fields = map ( lambda datum : datum . strip ( ) , fields ) <EOL> numFields = len ( fields ) <EOL> if ( numFields != numKeys ) : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , numFields , numKeys ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> instanceDict = { } <EOL> for k in range ( numFields ) : <EOL> key = keyDict [ k ] <EOL> field = fields [ k ] <EOL> if not field : <EOL> continue <EOL> if field in [ "<STR_LIT>" , "<STR_LIT:None>" , "<STR_LIT>" ] : <EOL> continue <EOL> if key == kFontName : <EOL> value = field <EOL> if key == kMasters : <EOL> value = eval ( field ) <EOL> elif key in [ kExtraGlyphs , kExceptionSuffixes ] : <EOL> value = eval ( field ) <EOL> elif key in [ kIsBoldKey , kIsItalicKey , kCoordsKey ] : <EOL> try : <EOL> value = eval ( field ) <EOL> if key == kIsBoldKey : <EOL> instanceDict [ key ] = value <EOL> key = kForceBold <EOL> if value == <NUM_LIT:1> : <EOL> value = "<STR_LIT:true>" <EOL> else : <EOL> value = "<STR_LIT:false>" <EOL> elif key == kIsItalicKey : <EOL> if value == <NUM_LIT:1> : <EOL> value = "<STR_LIT:true>" <EOL> else : <EOL> value = "<STR_LIT:false>" <EOL> elif key == kCoordsKey : <EOL> if type ( value ) == type ( <NUM_LIT:0> ) : <EOL> value = ( value , ) <EOL> except ( NameError , SyntaxError ) : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , key ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> elif field [ <NUM_LIT:0> ] in [ "<STR_LIT:[>" , "<STR_LIT:{>" ] : <EOL> value = field [ <NUM_LIT:1> : - <NUM_LIT:1> ] . split ( ) <EOL> if key in kAlignmentZonesKeys : <EOL> if len ( value ) % <NUM_LIT:2> != <NUM_LIT:0> : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , key ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> if key in kTopAlignZonesKeys : <EOL> if len ( value ) > kMaxTopZonesSize : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , key , kMaxTopZonesSize ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> else : <EOL> newArray = validateArrayValues ( value , False ) <EOL> if newArray : <EOL> value = newArray <EOL> else : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , key ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> currentArray = value [ : ] <EOL> value . sort ( ) <EOL> if currentArray != value : <EOL> print "<STR_LIT>" % ( i + <NUM_LIT:1> , key ) <EOL> if key in kBotAlignZonesKeys : <EOL> if len ( value ) > kMaxBotZonesSize : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , key , kMaxBotZonesSize ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> else : <EOL> newArray = validateArrayValues ( value , False ) <EOL> if newArray : <EOL> value = newArray <EOL> else : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , key ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> currentArray = value [ : ] <EOL> value . sort ( ) <EOL> if currentArray != value : <EOL> print "<STR_LIT>" % ( i + <NUM_LIT:1> , key ) <EOL> if key in kStdStemsKeys : <EOL> if len ( value ) > kMaxStdStemsSize : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , key , kMaxStdStemsSize ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> else : <EOL> newArray = validateArrayValues ( value , True ) <EOL> if newArray : <EOL> value = newArray <EOL> else : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , key ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> if key in kStemSnapKeys : <EOL> if len ( value ) > kMaxStemSnapSize : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , key , kMaxStemSnapSize ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> else : <EOL> newArray = validateArrayValues ( value , True ) <EOL> if newArray : <EOL> value = newArray <EOL> else : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , key ) <EOL> parseError = <NUM_LIT:1> <EOL> continue <EOL> currentArray = value [ : ] <EOL> value . sort ( ) <EOL> if currentArray != value : <EOL> print "<STR_LIT>" % ( i + <NUM_LIT:1> , key ) <EOL> else : <EOL> if re . match ( r"<STR_LIT>" , field ) : <EOL> value = field <EOL> else : <EOL> value = field <EOL> instanceDict [ key ] = value <EOL> if ( kStdHW in instanceDict and kStemSnapH not in instanceDict ) or ( kStdHW not in instanceDict and kStemSnapH in instanceDict ) : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , kStdHW , kStemSnapH ) <EOL> parseError = <NUM_LIT:1> <EOL> elif ( kStdHW in instanceDict and kStemSnapH in instanceDict ) : <EOL> if instanceDict [ kStemSnapH ] [ <NUM_LIT:0> ] != instanceDict [ kStdHW ] [ <NUM_LIT:0> ] : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , kStemSnapH , kStdHW ) <EOL> parseError = <NUM_LIT:1> <EOL> if ( kStdVW in instanceDict and kStemSnapV not in instanceDict ) or ( kStdVW not in instanceDict and kStemSnapV in instanceDict ) : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , kStdVW , kStemSnapV ) <EOL> parseError = <NUM_LIT:1> <EOL> elif ( kStdVW in instanceDict and kStemSnapV in instanceDict ) : <EOL> if instanceDict [ kStemSnapV ] [ <NUM_LIT:0> ] != instanceDict [ kStdVW ] [ <NUM_LIT:0> ] : <EOL> print >> sys . stderr , "<STR_LIT>" % ( i + <NUM_LIT:1> , kStemSnapV , kStdVW ) <EOL> parseError = <NUM_LIT:1> <EOL> instancesList . append ( instanceDict ) <EOL> if parseError or len ( instancesList ) == <NUM_LIT:0> : <EOL> raise <EOL> return instancesList <EOL> def makeFaceFolder ( root , folder ) : <EOL> facePath = os . path . join ( root , folder ) <EOL> if not os . path . exists ( facePath ) : <EOL> os . makedirs ( facePath ) <EOL> return facePath <EOL> def makeInstance ( counter , ufoMasters , instanceInfo , outputDirPath , options ) : <EOL> if len ( ufoMasters ) == <NUM_LIT:2> : <EOL> '<STR_LIT>' <EOL> pass <EOL> else : <EOL> '<STR_LIT>' <EOL> ufoMasters = [ master for master in ufoMasters if os . path . basename ( master . path ) in instanceInfo . get ( kMasters ) ] <EOL> try : <EOL> faceName = instanceInfo [ kFontName ] . split ( '<STR_LIT:->' ) [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> faceName = '<STR_LIT>' <EOL> print <EOL> print "<STR_LIT>" % ( faceName , counter [ <NUM_LIT:0> ] , counter [ <NUM_LIT:1> ] ) <EOL> interpolationFactor = instanceInfo [ kCoordsKey ] [ <NUM_LIT:0> ] / <NUM_LIT> <EOL> glyphOrder = ufoMasters [ <NUM_LIT:0> ] . lib [ "<STR_LIT>" ] <EOL> ufoInstance = NewFont ( ) <EOL> ufoInstance . interpolate ( interpolationFactor , ufoMasters [ <NUM_LIT:0> ] , ufoMasters [ <NUM_LIT:1> ] ) <EOL> ufoInstance . round ( ) <EOL> if len ( ufoMasters [ <NUM_LIT:0> ] . kerning ) : <EOL> ufoInstance . kerning . interpolate ( ufoMasters [ <NUM_LIT:0> ] . kerning , ufoMasters [ <NUM_LIT:1> ] . kerning , interpolationFactor ) <EOL> ufoInstance . kerning . round ( <NUM_LIT:1> ) <EOL> for glyphName in glyphOrder : <EOL> ufoInstance [ glyphName ] . unicode = ufoMasters [ <NUM_LIT:0> ] [ glyphName ] . unicode <EOL> if len ( ufoMasters [ <NUM_LIT:0> ] [ glyphName ] ) != len ( ufoInstance [ glyphName ] ) : <EOL> print "<STR_LIT>" % glyphName <EOL> styleName = instanceInfo [ kFullName ] . replace ( instanceInfo [ kFamilyName ] , '<STR_LIT>' ) . strip ( ) <EOL> ufoInstance . info . styleName = styleName <EOL> ufoInstance . info . familyName = instanceInfo [ kFamilyName ] <EOL> ufoInstance . info . postscriptFontName = instanceInfo [ kFontName ] <EOL> ufoInstance . info . postscriptFullName = instanceInfo [ kFullName ] <EOL> ufoInstance . info . postscriptWeightName = instanceInfo [ kWeight ] <EOL> ufoInstance . info . postscriptForceBold = True if instanceInfo [ kIsBoldKey ] else False <EOL> ufoInstance . lib = ufoMasters [ <NUM_LIT:0> ] . lib <EOL> ufoInstance . groups = ufoMasters [ <NUM_LIT:0> ] . groups <EOL> ufoInstance . info . copyright = ufoMasters [ <NUM_LIT:0> ] . info . copyright <EOL> ufoInstance . info . trademark = ufoMasters [ <NUM_LIT:0> ] . info . trademark <EOL> ufoInstance . info . unitsPerEm = ufoMasters [ <NUM_LIT:0> ] . info . unitsPerEm <EOL> ufoInstance . info . versionMajor = ufoMasters [ <NUM_LIT:0> ] . info . versionMajor <EOL> ufoInstance . info . versionMinor = ufoMasters [ <NUM_LIT:0> ] . info . versionMinor <EOL> ufoInstance . info . postscriptIsFixedPitch = ufoMasters [ <NUM_LIT:0> ] . info . postscriptIsFixedPitch <EOL> if ufoMasters [ <NUM_LIT:0> ] . info . ascender and ufoMasters [ <NUM_LIT:1> ] . info . ascender : <EOL> ufoInstance . info . ascender = int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . ascender , ufoMasters [ <NUM_LIT:1> ] . info . ascender , interpolationFactor ) ) ) <EOL> if ufoMasters [ <NUM_LIT:0> ] . info . descender and ufoMasters [ <NUM_LIT:1> ] . info . descender : <EOL> ufoInstance . info . descender = int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . descender , ufoMasters [ <NUM_LIT:1> ] . info . descender , interpolationFactor ) ) ) <EOL> if ufoMasters [ <NUM_LIT:0> ] . info . capHeight and ufoMasters [ <NUM_LIT:1> ] . info . capHeight : <EOL> ufoInstance . info . capHeight = int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . capHeight , ufoMasters [ <NUM_LIT:1> ] . info . capHeight , interpolationFactor ) ) ) <EOL> if ufoMasters [ <NUM_LIT:0> ] . info . xHeight and ufoMasters [ <NUM_LIT:1> ] . info . xHeight : <EOL> ufoInstance . info . xHeight = int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . xHeight , ufoMasters [ <NUM_LIT:1> ] . info . xHeight , interpolationFactor ) ) ) <EOL> if ( ufoMasters [ <NUM_LIT:0> ] . info . italicAngle != None ) and ( ufoMasters [ <NUM_LIT:1> ] . info . italicAngle != None ) : <EOL> ufoInstance . info . italicAngle = int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . italicAngle , ufoMasters [ <NUM_LIT:1> ] . info . italicAngle , interpolationFactor ) ) ) <EOL> if ufoMasters [ <NUM_LIT:0> ] . info . postscriptUnderlinePosition and ufoMasters [ <NUM_LIT:1> ] . info . postscriptUnderlinePosition : <EOL> ufoInstance . info . postscriptUnderlinePosition = int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptUnderlinePosition , ufoMasters [ <NUM_LIT:1> ] . info . postscriptUnderlinePosition , interpolationFactor ) ) ) <EOL> if ufoMasters [ <NUM_LIT:0> ] . info . postscriptUnderlineThickness and ufoMasters [ <NUM_LIT:1> ] . info . postscriptUnderlineThickness : <EOL> ufoInstance . info . postscriptUnderlineThickness = int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptUnderlineThickness , ufoMasters [ <NUM_LIT:1> ] . info . postscriptUnderlineThickness , interpolationFactor ) ) ) <EOL> if ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptBlueFuzz != None ) and ( ufoMasters [ <NUM_LIT:1> ] . info . postscriptBlueFuzz != None ) : <EOL> ufoInstance . info . postscriptBlueFuzz = int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptBlueFuzz , ufoMasters [ <NUM_LIT:1> ] . info . postscriptBlueFuzz , interpolationFactor ) ) ) <EOL> if ufoMasters [ <NUM_LIT:0> ] . info . postscriptBlueScale and ufoMasters [ <NUM_LIT:1> ] . info . postscriptBlueScale : <EOL> ufoInstance . info . postscriptBlueScale = objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptBlueScale , ufoMasters [ <NUM_LIT:1> ] . info . postscriptBlueScale , interpolationFactor ) <EOL> if ufoMasters [ <NUM_LIT:0> ] . info . postscriptBlueShift and ufoMasters [ <NUM_LIT:1> ] . info . postscriptBlueShift : <EOL> ufoInstance . info . postscriptBlueShift = int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptBlueShift , ufoMasters [ <NUM_LIT:1> ] . info . postscriptBlueShift , interpolationFactor ) ) ) <EOL> if len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptBlueValues ) == len ( ufoMasters [ <NUM_LIT:1> ] . info . postscriptBlueValues ) : <EOL> ufoMasters [ <NUM_LIT:0> ] . info . postscriptBlueValues . sort ( ) <EOL> ufoMasters [ <NUM_LIT:1> ] . info . postscriptBlueValues . sort ( ) <EOL> tempArray = [ ] <EOL> for i in range ( len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptBlueValues ) ) : <EOL> tempArray . append ( int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptBlueValues [ i ] , ufoMasters [ <NUM_LIT:1> ] . info . postscriptBlueValues [ i ] , interpolationFactor ) ) ) ) <EOL> ufoInstance . info . postscriptBlueValues = tempArray <EOL> if len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptOtherBlues ) == len ( ufoMasters [ <NUM_LIT:1> ] . info . postscriptOtherBlues ) : <EOL> ufoMasters [ <NUM_LIT:0> ] . info . postscriptOtherBlues . sort ( ) <EOL> ufoMasters [ <NUM_LIT:1> ] . info . postscriptOtherBlues . sort ( ) <EOL> tempArray = [ ] <EOL> for i in range ( len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptOtherBlues ) ) : <EOL> tempArray . append ( int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptOtherBlues [ i ] , ufoMasters [ <NUM_LIT:1> ] . info . postscriptOtherBlues [ i ] , interpolationFactor ) ) ) ) <EOL> ufoInstance . info . postscriptOtherBlues = tempArray <EOL> if len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptFamilyBlues ) == len ( ufoMasters [ <NUM_LIT:1> ] . info . postscriptFamilyBlues ) : <EOL> ufoMasters [ <NUM_LIT:0> ] . info . postscriptFamilyBlues . sort ( ) <EOL> ufoMasters [ <NUM_LIT:1> ] . info . postscriptFamilyBlues . sort ( ) <EOL> tempArray = [ ] <EOL> for i in range ( len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptFamilyBlues ) ) : <EOL> tempArray . append ( int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptFamilyBlues [ i ] , ufoMasters [ <NUM_LIT:1> ] . info . postscriptFamilyBlues [ i ] , interpolationFactor ) ) ) ) <EOL> ufoInstance . info . postscriptFamilyBlues = tempArray <EOL> if len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptFamilyOtherBlues ) == len ( ufoMasters [ <NUM_LIT:1> ] . info . postscriptFamilyOtherBlues ) : <EOL> ufoMasters [ <NUM_LIT:0> ] . info . postscriptFamilyOtherBlues . sort ( ) <EOL> ufoMasters [ <NUM_LIT:1> ] . info . postscriptFamilyOtherBlues . sort ( ) <EOL> tempArray = [ ] <EOL> for i in range ( len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptFamilyOtherBlues ) ) : <EOL> tempArray . append ( int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptFamilyOtherBlues [ i ] , ufoMasters [ <NUM_LIT:1> ] . info . postscriptFamilyOtherBlues [ i ] , interpolationFactor ) ) ) ) <EOL> ufoInstance . info . postscriptFamilyOtherBlues = tempArray <EOL> if len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptStemSnapH ) == len ( ufoMasters [ <NUM_LIT:1> ] . info . postscriptStemSnapH ) : <EOL> ufoMasters [ <NUM_LIT:0> ] . info . postscriptStemSnapH . sort ( ) <EOL> ufoMasters [ <NUM_LIT:1> ] . info . postscriptStemSnapH . sort ( ) <EOL> tempArray = [ ] <EOL> for i in range ( len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptStemSnapH ) ) : <EOL> tempArray . append ( int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptStemSnapH [ i ] , ufoMasters [ <NUM_LIT:1> ] . info . postscriptStemSnapH [ i ] , interpolationFactor ) ) ) ) <EOL> ufoInstance . info . postscriptStemSnapH = tempArray <EOL> if len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptStemSnapV ) == len ( ufoMasters [ <NUM_LIT:1> ] . info . postscriptStemSnapV ) : <EOL> ufoMasters [ <NUM_LIT:0> ] . info . postscriptStemSnapV . sort ( ) <EOL> ufoMasters [ <NUM_LIT:1> ] . info . postscriptStemSnapV . sort ( ) <EOL> tempArray = [ ] <EOL> for i in range ( len ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptStemSnapV ) ) : <EOL> tempArray . append ( int ( round ( objectsBase . _interpolate ( ufoMasters [ <NUM_LIT:0> ] . info . postscriptStemSnapV [ i ] , ufoMasters [ <NUM_LIT:1> ] . info . postscriptStemSnapV [ i ] , interpolationFactor ) ) ) ) <EOL> ufoInstance . info . postscriptStemSnapV = tempArray <EOL> faceFolder = makeFaceFolder ( outputDirPath , faceName ) <EOL> ufoPath = os . path . join ( faceFolder , kFontInstanceFileName ) <EOL> if not options . noUFOs : <EOL> print '<STR_LIT>' % kFontInstanceFileName <EOL> while os . path . exists ( ufoPath ) : <EOL> shutil . rmtree ( ufoPath ) <EOL> ufoInstance . save ( ufoPath ) <EOL> if options . genKernFeature : <EOL> print "<STR_LIT>" <EOL> WriteFeaturesKernFDK . KernDataClass ( ufoInstance , faceFolder , options . minKern , options . writeTrimmed , options . writeSubtables ) <EOL> if options . genMarkFeature : <EOL> if options . genMkmkFeature : <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" <EOL> WriteFeaturesMarkFDK . MarkDataClass ( ufoInstance , faceFolder , options . trimCasingTags , options . genMkmkFeature , options . writeClassesFile , options . indianScriptsFormat ) <EOL> if options . flatten : <EOL> print '<STR_LIT>' <EOL> if os . name == "<STR_LIT>" : <EOL> coTool = '<STR_LIT>' <EOL> else : <EOL> coTool = '<STR_LIT>' <EOL> cmd = '<STR_LIT>' % ( coTool , ufoPath ) <EOL> popen = Popen ( cmd , shell = True , stdout = PIPE ) <EOL> popenout , popenerr = popen . communicate ( ) <EOL> if options . verboseMode : <EOL> if popenout : <EOL> print popenout <EOL> if popenerr : <EOL> print popenerr <EOL> if options . autohint : <EOL> print '<STR_LIT>' <EOL> cmd = '<STR_LIT>' % ufoPath <EOL> popen = Popen ( cmd , shell = True , stdout = PIPE ) <EOL> popenout , popenerr = popen . communicate ( ) <EOL> if options . verboseMode : <EOL> if popenout : <EOL> print popenout <EOL> if popenerr : <EOL> print popenerr <EOL> class Options : <EOL> def __init__ ( self ) : <EOL> self . verboseMode = False <EOL> self . genKernFeature = False <EOL> self . genMarkFeature = False <EOL> self . genMkmkFeature = False <EOL> self . writeClassesFile = False <EOL> self . indianScriptsFormat = False <EOL> self . noUFOs = False <EOL> self . minKern = <NUM_LIT:3> <EOL> self . writeTrimmed = False <EOL> self . writeSubtables = False <EOL> self . trimCasingTags = False <EOL> self . autohint = False <EOL> self . flatten = False <EOL> def getOptions ( baseFolderPath ) : <EOL> options = Options ( ) <EOL> options . inputPath = baseFolderPath <EOL> i = <NUM_LIT:1> <EOL> numOptions = len ( sys . argv ) <EOL> while i < numOptions : <EOL> arg = sys . argv [ i ] <EOL> if arg == "<STR_LIT>" : <EOL> print __help__ <EOL> raise <EOL> elif arg == "<STR_LIT>" : <EOL> print __usage__ <EOL> raise <EOL> elif arg == "<STR_LIT>" : <EOL> print __doc__ <EOL> raise <EOL> elif arg == "<STR_LIT>" : <EOL> options . verboseMode = True <EOL> elif arg == "<STR_LIT>" : <EOL> i += <NUM_LIT:1> <EOL> try : <EOL> outputPath = sys . argv [ i ] <EOL> except IndexError : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> raise <EOL> if outputPath [ <NUM_LIT:0> ] == "<STR_LIT:->" : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> raise <EOL> options . outputPath = outputPath <EOL> elif arg == "<STR_LIT>" : <EOL> i += <NUM_LIT:1> <EOL> try : <EOL> minimum = sys . argv [ i ] <EOL> except IndexError : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> raise <EOL> if minimum [ <NUM_LIT:0> ] == "<STR_LIT:->" : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> raise <EOL> try : <EOL> options . minKern = int ( minimum ) <EOL> except : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> raise <EOL> elif arg == "<STR_LIT>" : <EOL> options . genKernFeature = True <EOL> elif arg == "<STR_LIT>" : <EOL> options . genMarkFeature = True <EOL> elif arg == "<STR_LIT>" : <EOL> options . noUFOs = True <EOL> elif arg == "<STR_LIT>" : <EOL> options . writeTrimmed = True <EOL> elif arg == "<STR_LIT>" : <EOL> options . writeSubtables = True <EOL> elif arg == "<STR_LIT>" : <EOL> options . genMkmkFeature = True <EOL> elif arg == "<STR_LIT>" : <EOL> options . writeClassesFile = True <EOL> elif arg == "<STR_LIT>" : <EOL> options . indianScriptsFormat = True <EOL> elif arg == "<STR_LIT>" : <EOL> options . trimCasingTags = True <EOL> elif arg == "<STR_LIT>" : <EOL> options . autohint = True <EOL> elif arg == "<STR_LIT>" : <EOL> options . flatten = True <EOL> elif arg [ <NUM_LIT:0> ] == "<STR_LIT:->" : <EOL> print >> sys . stderr , "<STR_LIT>" % arg <EOL> raise <EOL> i += <NUM_LIT:1> <EOL> if options . genMkmkFeature and not options . genMarkFeature : <EOL> options . genMarkFeature = True <EOL> return options <EOL> def getFontPaths ( path ) : <EOL> fontsList = [ ] <EOL> instancesFile = None <EOL> for file in os . listdir ( path ) : <EOL> if file [ - <NUM_LIT:4> : ] . lower ( ) in [ "<STR_LIT>" ] : <EOL> fontsList . append ( os . path . join ( path , file ) ) <EOL> elif file [ - len ( kInstancesDataFileName ) : ] == kInstancesDataFileName : <EOL> instancesFile = os . path . join ( path , file ) <EOL> return fontsList , instancesFile <EOL> def run ( ) : <EOL> if len ( sys . argv [ <NUM_LIT:1> : ] ) and sys . argv [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] != '<STR_LIT:->' : <EOL> baseFolderPath = sys . argv [ <NUM_LIT:1> ] <EOL> if baseFolderPath [ - <NUM_LIT:1> ] == '<STR_LIT:/>' : <EOL> baseFolderPath = baseFolderPath [ : - <NUM_LIT:1> ] <EOL> if not os . path . isdir ( baseFolderPath ) : <EOL> print >> sys . stderr , "<STR_LIT>" % baseFolderPath <EOL> return <EOL> else : <EOL> baseFolderPath = os . getcwd ( ) <EOL> try : <EOL> options = getOptions ( baseFolderPath ) <EOL> except : <EOL> return <EOL> fontPathsList , instancesFilePath = getFontPaths ( baseFolderPath ) <EOL> if not len ( fontPathsList ) : <EOL> print >> sys . stderr , "<STR_LIT>" % baseFolderPath <EOL> return <EOL> if not instancesFilePath : <EOL> print >> sys . stderr , "<STR_LIT>" % ( kInstancesDataFileName , baseFolderPath ) <EOL> return <EOL> print "<STR_LIT>" % kInstancesDataFileName <EOL> try : <EOL> instancesList = readInstanceFile ( instancesFilePath ) <EOL> except : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> return <EOL> masterIndexes = [ ] <EOL> for ufoPath in fontPathsList : <EOL> fileNameNoExtension , fileExtension = os . path . splitext ( ufoPath ) <EOL> masterNumber = fileNameNoExtension . split ( '<STR_LIT:_>' ) [ - <NUM_LIT:1> ] <EOL> if masterNumber . isdigit ( ) : <EOL> masterIndexes . append ( int ( masterNumber ) ) <EOL> if masterIndexes != range ( len ( fontPathsList ) ) : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> return <EOL> axisNum = int ( math . log ( len ( masterIndexes ) , <NUM_LIT:2> ) ) <EOL> for i in range ( len ( instancesList ) ) : <EOL> instanceDict = instancesList [ i ] <EOL> axisVal = instanceDict [ kCoordsKey ] <EOL> if axisNum != len ( axisVal ) : <EOL> print '<STR_LIT>' % ( kCoordsKey , instanceDict [ kFontName ] , kInstancesDataFileName ) <EOL> return <EOL> try : <EOL> outputDirPath = options . outputPath <EOL> if not os . path . isdir ( outputDirPath ) : <EOL> print >> sys . stderr , "<STR_LIT>" % outputDirPath <EOL> return <EOL> except AttributeError : <EOL> outputDirPath = baseFolderPath <EOL> t1 = time . time ( ) <EOL> print "<STR_LIT>" % len ( fontPathsList ) <EOL> ufoMasters = [ OpenFont ( ufoPath ) for ufoPath in fontPathsList ] <EOL> totalInstances = len ( instancesList ) <EOL> print "<STR_LIT>" % totalInstances <EOL> for i in range ( totalInstances ) : <EOL> makeInstance ( ( i + <NUM_LIT:1> , totalInstances ) , ufoMasters , instancesList [ i ] , outputDirPath , options ) <EOL> t2 = time . time ( ) <EOL> elapsedSeconds = t2 - t1 <EOL> if ( elapsedSeconds / <NUM_LIT> ) < <NUM_LIT:1> : <EOL> print '<STR_LIT>' % elapsedSeconds <EOL> else : <EOL> print '<STR_LIT>' % ( elapsedSeconds / <NUM_LIT> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> run ( ) </s>
