summaryrefslogtreecommitdiff
path: root/misc/gen-glyphorder.py
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2017-08-22 10:05:20 +0300
committerRasmus Andersson <rasmus@notion.se>2017-08-22 12:23:08 +0300
commit3b1fffade1473f20f2558733fbd218f4580fc7c3 (patch)
treeea4f80b43b08744d493bb86ab646444ec04ddc7f /misc/gen-glyphorder.py
downloadinter-3b1fffade1473f20f2558733fbd218f4580fc7c3.tar.xz
Initial public commitv1.0
Diffstat (limited to 'misc/gen-glyphorder.py')
-rwxr-xr-xmisc/gen-glyphorder.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/misc/gen-glyphorder.py b/misc/gen-glyphorder.py
new file mode 100755
index 000000000..0817e97b0
--- /dev/null
+++ b/misc/gen-glyphorder.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# encoding: utf8
+from __future__ import print_function
+import os, plistlib
+from collections import OrderedDict
+from argparse import ArgumentParser
+
+
+def parseGlyphComposition(composite):
+ c = composite.split("=")
+ d = c[1].split("/")
+ glyphName = d[0]
+ if len(d) == 1:
+ offset = [0, 0]
+ else:
+ offset = [int(i) for i in d[1].split(",")]
+ accentString = c[0]
+ accents = accentString.split("+")
+ baseName = accents.pop(0)
+ accentNames = [i.split(":") for i in accents]
+ return (glyphName, baseName, accentNames, offset)
+
+
+def loadGlyphCompositions(filename): # { glyphName => (baseName, accentNames, offset) }
+ compositions = OrderedDict()
+ with open(filename, 'r') as f:
+ for line in f:
+ line = line.strip()
+ if len(line) > 0 and line[0] != '#':
+ glyphName, baseName, accentNames, offset = parseGlyphComposition(line)
+ compositions[glyphName] = (baseName, accentNames, offset)
+ return compositions
+
+
+def main():
+ argparser = ArgumentParser(description='Generate glyph order list from UFO files')
+ argparser.add_argument('fontPaths', metavar='<ufofile>', type=str, nargs='+', help='UFO files')
+ args = argparser.parse_args()
+
+ glyphorderUnion = OrderedDict()
+
+ fontPaths = []
+ for fontPath in args.fontPaths:
+ if 'regular' or 'Regular' in fontPath:
+ fontPaths = [fontPath] + fontPaths
+ else:
+ fontPaths.append(fontPath)
+
+ for fontPath in fontPaths:
+ libPlist = plistlib.readPlist(os.path.join(fontPath, 'lib.plist'))
+ if 'public.glyphOrder' in libPlist:
+ for name in libPlist['public.glyphOrder']:
+ glyphorderUnion[name] = True
+
+ # incorporate src/diacritics.txt
+ # diacriticComps = loadGlyphCompositions('src/diacritics.txt')
+ # for glyphName in diacriticComps.iterkeys():
+ # glyphorderUnion[glyphName] = True
+
+ glyphorderUnionNames = glyphorderUnion.keys()
+ print('\n'.join(glyphorderUnionNames))
+
+
+if __name__ == '__main__':
+ main()