def add_ligature (font, string): if 'GSUB' not in font: ligature_subst = otTables.LigatureSubst() ligature_subst.ligatures = {} lookup = otTables.Lookup() lookup.LookupType = 4 lookup.LookupFlag = 0 lookup.SubTableCount = 1 lookup.SubTable = [ligature_subst] font['GSUB'] = add_emoji_gsub.create_simple_gsub([lookup]) else: lookup = font['GSUB'].table.LookupList.Lookup[0] assert lookup.LookupType == 4 assert lookup.LookupFlag == 0 ligatures = lookup.SubTable[0].ligatures lig = otTables.Ligature() lig.CompCount = len(string) lig.Component = [glyph_name(ch) for ch in string[1:]] lig.LigGlyph = glyph_name(string) first = glyph_name(string[0]) try: ligatures[first].append(lig) except KeyError: ligatures[first] = [lig]
def get_gsub_ligature_lookup(font): """If the font does not have a GSUB table, create one with a ligature substitution lookup. If it does, ensure the first lookup is a properly initialized ligature substitution lookup. Return the lookup.""" # The template might include more lookups after lookup 0, if it has a # GSUB table. if 'GSUB' not in font: ligature_subst = otTables.LigatureSubst() ligature_subst.ligatures = {} lookup = otTables.Lookup() lookup.LookupType = 4 lookup.LookupFlag = 0 lookup.SubTableCount = 1 lookup.SubTable = [ligature_subst] font['GSUB'] = add_emoji_gsub.create_simple_gsub([lookup]) else: lookup = font['GSUB'].table.LookupList.Lookup[0] assert lookup.LookupFlag == 0 # importXML doesn't fully init GSUB structures, so help it out st = lookup.SubTable[0] if not hasattr(lookup, 'LookupType'): assert st.LookupType == 4 setattr(lookup, 'LookupType', 4) if not hasattr(st, 'ligatures'): setattr(st, 'ligatures', {}) return lookup
def add_ligature(font, string): if 'GSUB' not in font: ligature_subst = otTables.LigatureSubst() ligature_subst.ligatures = {} lookup = otTables.Lookup() lookup.LookupType = 4 lookup.LookupFlag = 0 lookup.SubTableCount = 1 lookup.SubTable = [ligature_subst] font['GSUB'] = add_emoji_gsub.create_simple_gsub([lookup]) else: lookup = font['GSUB'].table.LookupList.Lookup[0] assert lookup.LookupType == 4 assert lookup.LookupFlag == 0 ligatures = lookup.SubTable[0].ligatures lig = otTables.Ligature() lig.CompCount = len(string) lig.Component = [glyph_name(ch) for ch in string[1:]] lig.LigGlyph = glyph_name(string) first = glyph_name(string[0]) try: ligatures[first].append(lig) except KeyError: ligatures[first] = [lig]
def init_gsub(self): """Call this if you are going to add ligatures to the font. Creates a GSUB table if there isn't one already.""" if hasattr(self, 'ligatures'): return font = self.font if 'GSUB' not in font: ligature_subst = otTables.LigatureSubst() ligature_subst.ligatures = {} lookup = otTables.Lookup() lookup.LookupType = 4 lookup.LookupFlag = 0 lookup.SubTableCount = 1 lookup.SubTable = [ligature_subst] font['GSUB'] = add_emoji_gsub.create_simple_gsub([lookup]) else: lookup = font['GSUB'].table.LookupList.Lookup[0] assert lookup.LookupType == 4 assert lookup.LookupFlag == 0 self.ligatures = lookup.SubTable[0].ligatures