From c9dac4c4405d43978a4121d81e8fa9896e2450c6 Mon Sep 17 00:00:00 2001 From: Rasmus Andersson Date: Mon, 29 Mar 2021 09:14:46 -0700 Subject: tooling: fixes glyphinfo generator script. Some 3rd party library changed, causing output to no longer contain glyphs not explicitly ordered. Yay, dependencies. --- misc/tools/gen-glyphinfo.py | 97 +++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 39 deletions(-) (limited to 'misc') 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 = ' ' -- cgit v1.2.3