From 8ef6dd8b9f4c2b35ccf1829dcaa2563607b1da7d Mon Sep 17 00:00:00 2001 From: Rasmus Andersson Date: Mon, 27 May 2019 11:32:39 -0700 Subject: tooling: better handling of unexported glyphs --- misc/fontbuild | 24 +++++++++++++++++++++++- misc/tools/gen-glyphinfo.py | 7 ++++++- 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): -- cgit v1.2.3