summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2020-08-19 03:57:25 +0300
committerRasmus Andersson <rasmus@notion.se>2020-08-19 03:57:25 +0300
commitd76268cf8d778c709ce2e714a36e17d0d23effa9 (patch)
tree0f0a31da1ce5aba1ef64af37660a54ca0c06e4bb /misc
parentcb3d2853b9234b2764124cbc6113f779d419331e (diff)
downloadinter-d76268cf8d778c709ce2e714a36e17d0d23effa9.tar.xz
tooling: upgrade libs, rename VF fext otf -> ttf, add STAT table patch
- upgrades 3rd party libraries used by the toolchain - upgrades fontbuild code to adjust changes to library APIs - renames VF font filename extensions to .ttf - adds better STAT table patch to improve metadata on Windows
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/fontbuild54
-rw-r--r--misc/fontbuildlib/builder.py4
-rw-r--r--misc/fontbuildlib/info.py3
-rw-r--r--misc/fontbuildlib/stat.py34
-rwxr-xr-xmisc/googlefonts/build.sh4
-rwxr-xr-xmisc/makezip.sh16
-rw-r--r--misc/tools/font_names.py2
7 files changed, 82 insertions, 35 deletions
diff --git a/misc/fontbuild b/misc/fontbuild
index 0bc87a599..761513d7a 100755
--- a/misc/fontbuild
+++ b/misc/fontbuild
@@ -45,7 +45,6 @@ def collapseFontStyleName(font):
setFontInfo(font, font.info.openTypeOS2WeightClass)
-
class Main(object):
def __init__(self):
@@ -256,37 +255,25 @@ class Main(object):
if layer != defaultLayer:
delLayerNames.add(layer.name)
for layerName in delLayerNames:
- del layers[layerName]
+ del(layers[layerName])
# 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]
+ if g.name in glyphOrder:
+ del(glyphOrder[g.name])
g.unicodes = []
- if len(componentRefs.get(g.name, [])) == 0:
- # unused
- stripGlyphs.append(g.name)
g.clearAnchors()
if 'com.schriftgestaltung.Glyphs.lastChange' in g.lib:
- del g.lib['com.schriftgestaltung.Glyphs.lastChange']
+ 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)
+ font.save(ufo_path, overwrite=True, validate=False)
def _genSubsetDesignSpace(self, designspace, tag, filename):
@@ -365,6 +352,27 @@ class Main(object):
))
font = glyphsLib.GSFont(glyphsfile)
+ # remove archive layers and backgrounds
+ masterLayerIDs = set()
+ for master in font.masters:
+ masterLayerIDs.add(master.id)
+ for glyph in font.glyphs:
+ for layer in list(glyph.layers): # list to accumulate iterator since we del()
+ # remove background images from all layers
+ layer.backgroundImage = None
+ lname = layer.name
+ lid = layer.layerId
+ if lname[0] != '_' and (lid in masterLayerIDs or lname.find('{') != -1):
+ # Keep only layers which are masters or bracket layers.
+ # Next, clear background to speed up UFO generation.
+ layer.background.paths = []
+ layer.background.components = []
+ layer.background.anchors = []
+ layer.background.hints = []
+ layer.background.guides = []
+ else:
+ del(glyph.layers[lid])
+
# generate designspace from glyphs project
designspace = glyphsLib.to_designspace(
font,
@@ -385,8 +393,8 @@ class Main(object):
# TODO: Only write out-of-date UFOs
procs = []
for source in designspace.sources:
- # source : fontTools.designspaceLib.SourceDescriptor
- # source.font : defcon.objects.font.Font
+ # source : fontTools.designspaceLib.SourceDescriptor
+ # source.font : ufoLib2.objects.font.Font
ufo_path = pjoin(master_dir, source.filename)
# no need to also set the relative 'filename' attribute as that
# will be auto-updated on writing the designspace document
@@ -415,6 +423,10 @@ class Main(object):
source.path = ufo_path
weight = int(source.location['Weight'])
+ # serial
+ # self._glyphsyncWriteUFO(source.font, weight, ufo_path)
+
+ # parallel
p = Process(
target=self._glyphsyncWriteUFO,
args=(source.font, weight, ufo_path)
@@ -513,7 +525,7 @@ class Main(object):
italicAngle = font.lib.get(italicAngleKey)
if italicAngle != None:
italicAngle = float(italicAngle)
- del font.lib[italicAngleKey]
+ del(font.lib[italicAngleKey])
font.info.italicAngle = italicAngle
# clear anchors
diff --git a/misc/fontbuildlib/builder.py b/misc/fontbuildlib/builder.py
index b4a53df1b..da769769c 100644
--- a/misc/fontbuildlib/builder.py
+++ b/misc/fontbuildlib/builder.py
@@ -7,6 +7,7 @@ from fontTools.designspaceLib import DesignSpaceDocument
from .name import getFamilyName, setFullName
from .info import updateFontVersion
from .glyph import findGlyphDirectives, composedGlyphIsTrivial, decomposeGlyphs
+from .stat import rebuildStatTable
log = logging.getLogger(__name__)
@@ -81,6 +82,9 @@ class FontBuilder:
# record is still computed by fonttools, so we override it here.
setFullName(font, getFamilyName(font))
+ # rebuild STAT table to correct VF instance information
+ rebuildStatTable(font, designspace)
+
log.debug("writing %s", outputFilename)
font.save(outputFilename)
diff --git a/misc/fontbuildlib/info.py b/misc/fontbuildlib/info.py
index c4236f600..f8949f1e6 100644
--- a/misc/fontbuildlib/info.py
+++ b/misc/fontbuildlib/info.py
@@ -19,11 +19,8 @@ def updateFontVersion(font, dummy, isVF):
buildtag = "src"
print("warning: getGitHash() failed: %r" % buildtagErrs, file=sys.stderr)
versionMajor, versionMinor = [int(num) for num in version.split(".")]
- font.info.version = version
font.info.versionMajor = versionMajor
font.info.versionMinor = versionMinor
- font.info.woffMajorVersion = versionMajor
- font.info.woffMinorVersion = versionMinor
font.info.year = now.year
font.info.openTypeNameVersion = "Version %d.%03d;git-%s" % (versionMajor, versionMinor, buildtag)
psFamily = re.sub(r'\s', '', font.info.familyName)
diff --git a/misc/fontbuildlib/stat.py b/misc/fontbuildlib/stat.py
new file mode 100644
index 000000000..9ba28300c
--- /dev/null
+++ b/misc/fontbuildlib/stat.py
@@ -0,0 +1,34 @@
+# from fontTools.designspaceLib import DesignSpaceDocument
+# from fontTools.ttLib.tables import otTables as ot
+# from fontTools.ttLib import ttFont
+from fontTools.otlLib.builder import buildStatTable
+
+def rebuildStatTable(font, designspace):
+ if not 'fvar' in font:
+ raise Exception('missing fvar table in font')
+
+ axes = [dict(tag=a.axisTag, name=a.axisNameID) for a in font['fvar'].axes]
+ # axes = []
+ # for a in statTable.DesignAxisRecord.Axis:
+ # axes.append({ 'tag': a.AxisTag, 'name': a.AxisNameID, 'ordering': a.AxisOrdering })
+
+ axisNameToTag = dict()
+ for axis in designspace.axes:
+ axisNameToTag[axis.name] = axis.tag
+
+ locations = []
+ for instance in designspace.instances:
+ location = dict()
+ for axisName, value in instance.location.items():
+ tag = axisNameToTag[axisName]
+ location[tag] = value
+ locations.append({ 'name': instance.styleName, 'location': location })
+
+ buildStatTable(font, axes, locations)
+
+
+# font = ttFont.TTFont("build/fonts/var/Inter.var.ttf")
+# designspace = DesignSpaceDocument.fromfile('build/ufo/inter.designspace')
+# rebuildStatTable(font, designspace)
+# print("write build/tmp/Inter.var-patched.ttf")
+# font.save("build/tmp/Inter.var-patched.ttf")
diff --git a/misc/googlefonts/build.sh b/misc/googlefonts/build.sh
index cfee2f49f..d46259a29 100755
--- a/misc/googlefonts/build.sh
+++ b/misc/googlefonts/build.sh
@@ -24,11 +24,11 @@ if $CLEAN; then
fi
# compile multi-axis variable font
-make build/fonts/var/Inter.var.otf
+make build/fonts/var/Inter.var.ttf
# change file type to TTF and change style names to Google Fonts standard.
rm -rf build/googlefonts
mkdir -p build/googlefonts
misc/fontbuild rename --google-style \
- build/fonts/var/Inter.var.otf \
+ build/fonts/var/Inter.var.ttf \
-o build/googlefonts/Inter.var.ttf
diff --git a/misc/makezip.sh b/misc/makezip.sh
index f1562846f..ba0ed6ed5 100755
--- a/misc/makezip.sh
+++ b/misc/makezip.sh
@@ -89,7 +89,7 @@ mkdir -p \
if $OPT_TEXT; then
# Inter Desktop
cp $FONTDIR/const/Inter-*.otf "$ZIPDIR/Inter Desktop/" &
- cp $FONTDIR/var/Inter-V.var.otf "$ZIPDIR/Inter Desktop/Inter-V.otf" &
+ cp $FONTDIR/var/Inter-V.var.ttf "$ZIPDIR/Inter Desktop/Inter-V.ttf" &
# Inter Hinted for Windows
cp "misc/dist/about hinted fonts.txt" "$ZIPDIR/Inter Hinted for Windows/" &
@@ -98,9 +98,9 @@ if $OPT_TEXT; then
cp misc/dist/inter.css "$ZIPDIR/Inter Hinted for Windows/Web/" &
# Inter Variable
- cp $FONTDIR/var/Inter.var.otf "$ZIPDIR/Inter Variable/Inter.otf" &
- cp $FONTDIR/var/Inter-roman.var.otf "$ZIPDIR/Inter Variable/Single axis/Inter-roman.otf" &
- cp $FONTDIR/var/Inter-italic.var.otf "$ZIPDIR/Inter Variable/Single axis/Inter-italic.otf" &
+ cp $FONTDIR/var/Inter.var.ttf "$ZIPDIR/Inter Variable/Inter.ttf" &
+ cp $FONTDIR/var/Inter-roman.var.ttf "$ZIPDIR/Inter Variable/Single axis/Inter-roman.ttf" &
+ cp $FONTDIR/var/Inter-italic.var.ttf "$ZIPDIR/Inter Variable/Single axis/Inter-italic.ttf" &
# Inter Web
cp $FONTDIR/const/Inter-*.woff* "$ZIPDIR/Inter Web/" &
@@ -113,7 +113,7 @@ fi
if $OPT_DISPLAY; then
# Inter Desktop
cp $FONTDIR/const/InterDisplay-*.otf "$ZIPDIR/Inter Desktop/" &
- cp $FONTDIR/var/InterDisplay-V.var.otf "$ZIPDIR/Inter Desktop/InterDisplay-V.otf" &
+ cp $FONTDIR/var/InterDisplay-V.var.ttf "$ZIPDIR/Inter Desktop/InterDisplay-V.ttf" &
# Inter Hinted for Windows
cp "misc/dist/about hinted fonts.txt" "$ZIPDIR/Inter Hinted for Windows/" &
@@ -122,9 +122,9 @@ if $OPT_DISPLAY; then
cp misc/dist/inter-display.css "$ZIPDIR/Inter Hinted for Windows/Web/" &
# Inter Variable
- cp $FONTDIR/var/InterDisplay.var.otf "$ZIPDIR/Inter Variable/InterDisplay.otf" &
- cp $FONTDIR/var/InterDisplay-roman.var.otf "$ZIPDIR/Inter Variable/Single axis/InterDisplay-roman.otf" &
- cp $FONTDIR/var/InterDisplay-italic.var.otf "$ZIPDIR/Inter Variable/Single axis/InterDisplay-italic.otf" &
+ cp $FONTDIR/var/InterDisplay.var.ttf "$ZIPDIR/Inter Variable/InterDisplay.ttf" &
+ cp $FONTDIR/var/InterDisplay-roman.var.ttf "$ZIPDIR/Inter Variable/Single axis/InterDisplay-roman.ttf" &
+ cp $FONTDIR/var/InterDisplay-italic.var.ttf "$ZIPDIR/Inter Variable/Single axis/InterDisplay-italic.ttf" &
# Inter Web
cp $FONTDIR/const/InterDisplay-*.woff* "$ZIPDIR/Inter Web/" &
diff --git a/misc/tools/font_names.py b/misc/tools/font_names.py
index c321ca673..e97f19baa 100644
--- a/misc/tools/font_names.py
+++ b/misc/tools/font_names.py
@@ -145,4 +145,4 @@ if __name__ == "__main__":
# Similar to:
# ttx -i -e -o ./build/tmp/var.ttx ./build/fonts/var/Inter.var.ttf
-# ttx -b --no-recalc-timestamp -o ./build/tmp/var.otf ./build/tmp/var.ttx
+# ttx -b --no-recalc-timestamp -o ./build/tmp/var.ttf ./build/tmp/var.ttx