def add_gsub_to_font(fontfile): """Adds an empty GSUB table to a font.""" font = ttLib.TTFont(fontfile) gsub_table = ttLib.getTableClass('GSUB')('GSUB') gsub_table.table = otTables.GSUB() gsub_table.table.Version = 1.0 gsub_table.table.ScriptList = otTables.ScriptList() gsub_table.table.ScriptCount = 1 gsub_table.table.LookupList = otTables.LookupList() gsub_table.table.LookupList.LookupCount = 0 gsub_table.table.LookupList.Lookup = [] gsub_table.table.FeatureList = otTables.FeatureList() gsub_table.table.FeatureList.FeatureCount = 0 gsub_table.table.LookupList.FeatureRecord = [] script_record = otTables.ScriptRecord() script_record.ScriptTag = get_opentype_script_tag(fontfile) script_record.Script = otTables.Script() script_record.Script.LangSysCount = 0 script_record.Script.LangSysRecord = [] default_lang_sys = otTables.DefaultLangSys() default_lang_sys.FeatureIndex = [] default_lang_sys.FeatureCount = 0 default_lang_sys.LookupOrder = None default_lang_sys.ReqFeatureIndex = 65535 script_record.Script.DefaultLangSys = default_lang_sys gsub_table.table.ScriptList.ScriptRecord = [script_record] font['GSUB'] = gsub_table target_file = tempfile.gettempdir() + '/' + os.path.basename(fontfile) font.save(target_file) return target_file
def buildGSUB(): """Build a GSUB table from scratch.""" fontTable = newTable("GSUB") gsub = fontTable.table = ot.GSUB() gsub.Version = 0x00010001 # allow gsub.FeatureVariations gsub.ScriptList = ot.ScriptList() gsub.ScriptList.ScriptRecord = [] gsub.FeatureList = ot.FeatureList() gsub.FeatureList.FeatureRecord = [] gsub.LookupList = ot.LookupList() gsub.LookupList.Lookup = [] srec = ot.ScriptRecord() srec.ScriptTag = 'DFLT' srec.Script = ot.Script() srec.Script.DefaultLangSys = None srec.Script.LangSysRecord = [] langrec = ot.LangSysRecord() langrec.LangSys = ot.LangSys() langrec.LangSys.ReqFeatureIndex = 0xFFFF langrec.LangSys.FeatureIndex = [0] srec.Script.DefaultLangSys = langrec.LangSys gsub.ScriptList.ScriptRecord.append(srec) gsub.FeatureVariations = None return fontTable
def create_simple_gsub(lookups, script='DFLT', feature='ccmp'): """Create a simple GSUB table.""" gsub_class = ttLib.getTableClass('GSUB') gsub = gsub_class('GSUB') gsub.table = otTables.GSUB() gsub.table.Version = 1.0 gsub.table.ScriptList = create_script_list(script) gsub.table.FeatureList = create_feature_list(feature, len(lookups)) gsub.table.LookupList = create_lookup_list(lookups) return gsub