summaryrefslogtreecommitdiff
path: root/misc/tools/gen-glyphinfo.py
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2021-03-29 19:14:46 +0300
committerRasmus Andersson <rasmus@notion.se>2021-03-29 19:14:46 +0300
commitc9dac4c4405d43978a4121d81e8fa9896e2450c6 (patch)
treeddfae9e3e342e5c3b81f88b1fcc98261b1f912d6 /misc/tools/gen-glyphinfo.py
parent4232cde195fb7f846ca60d742abf6180af84b1f6 (diff)
downloadinter-c9dac4c4405d43978a4121d81e8fa9896e2450c6.tar.xz
tooling: fixes glyphinfo generator script. Some 3rd party library changed, causing output to no longer contain glyphs not explicitly ordered. Yay, dependencies.
Diffstat (limited to 'misc/tools/gen-glyphinfo.py')
-rwxr-xr-xmisc/tools/gen-glyphinfo.py97
1 files changed, 58 insertions, 39 deletions
diff --git a/misc/tools/gen-glyphinfo.py b/misc/tools/gen-glyphinfo.py
index 62c6dc82a..c39d6ebd3 100755
--- a/misc/tools/gen-glyphinfo.py
+++ b/misc/tools/gen-glyphinfo.py
@@ -41,6 +41,50 @@ def localDateTimeToUTCStr(localstr, pattern='%Y/%m/%d %H:%M:%S'):
return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime(ts))
+def processGlyph(g, ucd, seenGlyphnames):
+ name = g.name
+ if name in seenGlyphnames:
+ return None
+ seenGlyphnames.add(name)
+
+ # not exported?
+ if 'com.schriftgestaltung.Glyphs.Export' in g.lib:
+ if not g.lib['com.schriftgestaltung.Glyphs.Export']:
+ return None
+
+ # color
+ color = None
+ if 'public.markColor' in g.lib:
+ rgba = [float(c.strip()) for c in g.lib['public.markColor'].strip().split(',')]
+ color = rgbaToCSSColor(*rgba)
+
+ isEmpty = 0
+ if not g.bounds or g.bounds[3] == 0:
+ isEmpty = 1
+
+ # name, isEmpty, unicode, unicodeName, color
+ glyph = None
+ ucs = g.unicodes
+ if len(ucs):
+ for uc in ucs:
+ ucName = unicodeName(ucd.get(uc))
+ # if not ucName and uc >= 0xE000 and uc <= 0xF8FF:
+ # ucName = '[private use %04X]' % uc
+ ucstr = '%04X' % uc
+ if color:
+ glyph = [name, isEmpty, ucstr, ucName, color]
+ elif ucName:
+ glyph = [name, isEmpty, ucstr, ucName]
+ else:
+ glyph = [name, isEmpty, ucstr]
+ else:
+ if color:
+ glyph = [name, isEmpty, None, None, color]
+ else:
+ glyph = [name, isEmpty]
+
+ return glyph
+
def main():
argparser = ArgumentParser(
@@ -60,48 +104,23 @@ def main():
ucd = parseUnicodeDataFile(args.ucdFile)
glyphs = [] # contains final glyph data printed as JSON
+ seenGlyphnames = set()
for name in font.lib['public.glyphOrder']:
g = font[name]
-
- # not exported?
- if 'com.schriftgestaltung.Glyphs.Export' in g.lib:
- if not g.lib['com.schriftgestaltung.Glyphs.Export']:
- continue
-
- # color
- color = None
- if 'public.markColor' in g.lib:
- rgba = [float(c.strip()) for c in g.lib['public.markColor'].strip().split(',')]
- color = rgbaToCSSColor(*rgba)
-
- isEmpty = 0
- if not g.bounds or g.bounds[3] == 0:
- isEmpty = 1
-
- # name, isEmpty, unicode, unicodeName, color
- glyph = None
- ucs = g.unicodes
- if len(ucs):
- for uc in ucs:
- ucName = unicodeName(ucd.get(uc))
- # if not ucName and uc >= 0xE000 and uc <= 0xF8FF:
- # ucName = '[private use %04X]' % uc
-
- ucstr = '%04X' % uc
- if color:
- glyph = [name, isEmpty, ucstr, ucName, color]
- elif ucName:
- glyph = [name, isEmpty, ucstr, ucName]
- else:
- glyph = [name, isEmpty, ucstr]
- else:
- if color:
- glyph = [name, isEmpty, None, None, color]
- else:
- glyph = [name, isEmpty]
-
- glyphs.append(glyph)
+ glyph = processGlyph(g, ucd, seenGlyphnames)
+ if glyph is not None:
+ glyphs.append(glyph)
+
+ unorderedGlyphs = []
+ for g in font:
+ glyph = processGlyph(g, ucd, seenGlyphnames)
+ if glyph is not None:
+ unorderedGlyphs.append(glyph)
+
+ if unorderedGlyphs:
+ # sort by unicode
+ glyphs = glyphs + sorted(unorderedGlyphs, key=lambda g: g[2])
print('{"glyphs":[')
prefix = ' '