From e1bcfbfde2e6c310d94ef2ba177c79864d7dbe0b Mon Sep 17 00:00:00 2001 From: Rasmus Andersson Date: Sun, 26 May 2019 16:38:03 -0700 Subject: tooling: new version of gen-glyphinfo.py --- misc/tools/gen-glyphinfo.py | 102 ++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 66 deletions(-) (limited to 'misc') diff --git a/misc/tools/gen-glyphinfo.py b/misc/tools/gen-glyphinfo.py index 041fb5300..c6e4a9912 100755 --- a/misc/tools/gen-glyphinfo.py +++ b/misc/tools/gen-glyphinfo.py @@ -13,7 +13,6 @@ import time from argparse import ArgumentParser from collections import OrderedDict from configparser import RawConfigParser -# from robofab.objects.objectsRF import OpenFont from unicode_util import parseUnicodeDataFile from defcon import Font @@ -52,81 +51,52 @@ def main(): help='UnicodeData.txt file from http://www.unicode.org/') argparser.add_argument( - 'fontPaths', metavar='', type=str, nargs='+', help='UFO fonts to update') + 'fontPath', metavar='', type=str) args = argparser.parse_args() - - fontPaths = [] - for fontPath in args.fontPaths: - fontPath = fontPath.rstrip('/ ') - if 'regular' or 'Regular' in fontPath: - fontPaths = [fontPath] + fontPaths - else: - fontPaths.append(fontPath) - - fonts = [Font(fontPath) for fontPath in args.fontPaths] - + font = Font(args.fontPath) ucd = {} if args.ucdFile: ucd = parseUnicodeDataFile(args.ucdFile) glyphs = [] # contains final glyph data printed as JSON - visitedGlyphNames = set() - - for font in fonts: - glyphorder = font.lib['public.glyphOrder'] - for name in glyphorder: - if name in visitedGlyphNames: - continue - - if name not in font: - print( - "warning: %r in public.glyphOrder but doesn't exist in font" % name, - file=sys.stderr - ) - continue - - g = font[name] - - # 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) - - # mtime - mtime = None - if 'com.schriftgestaltung.Glyphs.lastChange' in g.lib: - datetimestr = g.lib['com.schriftgestaltung.Glyphs.lastChange'] - mtime = localDateTimeToUTCStr(datetimestr) - - # name[, 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 - - if color: - glyph = [name, uc, ucName, mtime, color] - elif mtime: - glyph = [name, uc, ucName, mtime] - elif ucName: - glyph = [name, uc, ucName] - else: - glyph = [name, uc] - else: + + for name in font.lib['public.glyphOrder']: + g = font[name] + + # 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[, 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, None, None, mtime, color] - elif mtime: - glyph = [name, None, None, mtime] + glyph = [name, isEmpty, ucstr, ucName, color] + elif ucName: + glyph = [name, isEmpty, ucstr, ucName] else: - glyph = [name] + glyph = [name, isEmpty, ucstr] + else: + if color: + glyph = [name, isEmpty, None, None, color] + else: + glyph = [name, isEmpty] - glyphs.append(glyph) - visitedGlyphNames.add(name) + glyphs.append(glyph) print('{"glyphs":[') prefix = ' ' -- cgit v1.2.3