Created
March 21, 2015 00:54
-
-
Save dperelman/81fb4d94124178f35966 to your computer and use it in GitHub Desktop.
List ligatures in .ttx file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# This takes in just the ligatures section of a .ttx file: | |
# USAGE: sed -n '/<LigatureSubst /,/<\/LigatureSubst>/p' FOO.ttx \ | |
# | ./ligature_xml_to_list.py | |
from __future__ import print_function | |
import lxml.etree | |
import sys | |
try: | |
import fontTools.agl | |
def map_glyph(c): | |
res = fontTools.agl.AGL2UV.get(c, None) | |
if res is not None: | |
return unichr(res) | |
else: | |
return c | |
except ImportError: | |
print('WARNING: Package fonttools not found.', file=sys.stderr) | |
# Don't have fonttools package. | |
# TODO: 5 ---> five etc. | |
glyph_mappings = { | |
'space': ' ', | |
} | |
def map_glyph(c): | |
return glyph_mappings.get(c, c) | |
tree = lxml.etree.parse(sys.stdin) | |
print('\n'.join(sorted([''.join(map(map_glyph, | |
[ligSet.attrib['glyph']] | |
+ lig.attrib['components'].split(','))) | |
for ligSet in tree.iterfind('LigatureSet') | |
for lig in ligSet.iterfind('Ligature') | |
]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment