Skip to content

Commit

Permalink
tooling: better handling of unexported glyphs
Browse files Browse the repository at this point in the history
  • Loading branch information
rsms committed May 27, 2019
1 parent a4d3c0c commit 8ef6dd8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
24 changes: 23 additions & 1 deletion misc/fontbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion misc/tools/gen-glyphinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 8ef6dd8

Please sign in to comment.