summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@figma.com>2019-05-27 02:38:03 +0300
committerRasmus Andersson <rasmus@figma.com>2019-05-27 02:38:03 +0300
commite1bcfbfde2e6c310d94ef2ba177c79864d7dbe0b (patch)
tree21e90b614af15414976fd34dda64e799e7f04d1d /misc
parentd41fc8a01c2af07ac51fd9b17aa87214fb636336 (diff)
downloadinter-e1bcfbfde2e6c310d94ef2ba177c79864d7dbe0b.tar.xz
tooling: new version of gen-glyphinfo.py
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/tools/gen-glyphinfo.py102
1 files changed, 36 insertions, 66 deletions
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='<ufofile>', type=str, nargs='+', help='UFO fonts to update')
+ 'fontPath', metavar='<ufofile>', 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 = ' '