summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@figma.com>2019-05-27 21:32:39 +0300
committerRasmus Andersson <rasmus@figma.com>2019-05-27 21:32:39 +0300
commit8ef6dd8b9f4c2b35ccf1829dcaa2563607b1da7d (patch)
treeed88da882d53f43255087d0e8c46bb0489945d45
parenta4d3c0c2351a81313ff776301ec6c838217cc154 (diff)
downloadinter-8ef6dd8b9f4c2b35ccf1829dcaa2563607b1da7d.tar.xz
tooling: better handling of unexported glyphs
-rwxr-xr-xmisc/fontbuild24
-rwxr-xr-xmisc/tools/gen-glyphinfo.py7
2 files changed, 29 insertions, 2 deletions
diff --git a/misc/fontbuild b/misc/fontbuild
index f31b3ccb8..1d4a8d801 100755
--- a/misc/fontbuild
+++ b/misc/fontbuild
@@ -5,6 +5,7 @@ import sys, os
from os.path import dirname, basename, abspath, relpath, join as pjoin
sys.path.append(abspath(pjoin(dirname(__file__), 'tools')))
from common import BASEDIR, VENVDIR, getGitHash, getVersion, execproc
+from collections import OrderedDict
import argparse
import datetime
@@ -180,6 +181,7 @@ class VarFontProject(FontProject):
updateFontVersion(ufo)
isItalic = ufo.info.italicAngle != 0
ufoname = basename(ufo.path)
+
for g in ufo:
directives = findGlyphDirectives(g)
if g.components and composedGlyphIsNonTrivial(g, yAxisIsNonTrivial=isItalic):
@@ -581,11 +583,31 @@ class Main(object):
for layerName in delLayerNames:
del layers[layerName]
- # clear anchors
+ # process glyphs
+ stripGlyphs = []
+ glyphOrder = OrderedDict([(k,None) for k in font.lib['public.glyphOrder']])
+ componentRefs = font.componentReferences
for g in font:
+ if not g.lib.get('com.schriftgestaltung.Glyphs.Export', True):
+ del glyphOrder[g.name]
+ g.unicodes = []
+ if len(componentRefs.get(g.name, [])) == 0:
+ # unused
+ stripGlyphs.append(g.name)
g.clearAnchors()
del g.lib['com.schriftgestaltung.Glyphs.lastChange']
+ # update possibly modified glyphorder
+ font.lib['public.glyphOrder'] = list(glyphOrder)
+
+ # strip unused glyphs
+ for gname in stripGlyphs:
+ log.info(
+ 'Strip unused and unexported glyph "%s" from %s',
+ gname, ufo_path
+ )
+ del font[gname]
+
# write UFO file
self.log("write %s" % relpath(ufo_path, os.getcwd()))
font.save(ufo_path)
diff --git a/misc/tools/gen-glyphinfo.py b/misc/tools/gen-glyphinfo.py
index c6e4a9912..62c6dc82a 100755
--- a/misc/tools/gen-glyphinfo.py
+++ b/misc/tools/gen-glyphinfo.py
@@ -64,6 +64,11 @@ def main():
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:
@@ -74,7 +79,7 @@ def main():
if not g.bounds or g.bounds[3] == 0:
isEmpty = 1
- # name[, unicode[, unicodeName[, color]]]
+ # name, isEmpty, unicode, unicodeName, color
glyph = None
ucs = g.unicodes
if len(ucs):