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 add_ligature (font, codes): 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(codes) lig.Component = ["%04X" % int(codes[1],16)] lig.LigGlyph = glyph_name(codes) first = "%04X" % int(codes[0],16) try: ligatures[first].append(lig) except KeyError: ligatures[first] = [lig]
def add_ligature(font, codes): 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(codes) lig.Component = [glyph_name([code]) for code in codes[1:]] lig.LigGlyph = glyph_name(codes) first = "%04X" % int(codes[0], 16) 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