diff options
author | Rasmus Andersson <rasmus@notion.se> | 2022-10-08 03:39:15 +0300 |
---|---|---|
committer | Rasmus Andersson <rasmus@notion.se> | 2022-10-08 03:39:22 +0300 |
commit | 7cc0ab62e6b2e24aa0497487b0c360af13b15808 (patch) | |
tree | 3169648830dd479386b3b135aaad72b41482a6a2 /misc | |
parent | c81a0abf02fb2ea03c7569e5aa718c1e55c45d0d (diff) | |
download | inter-7cc0ab62e6b2e24aa0497487b0c360af13b15808.tar.xz |
patch UFO files with WWS entries and simplify UFO generation
Patches UFO files to contain WWS entries.
Also simplify UFO generation by moving the hard-coded make rules from the makefile into a shell script.
Related to #498 and https://github.com/googlefonts/glyphsLib/issues/820
Diffstat (limited to 'misc')
-rwxr-xr-x | misc/tools/gen-instance-ufo.sh | 69 | ||||
-rw-r--r-- | misc/tools/postprocess-designspace.py | 21 | ||||
-rw-r--r-- | misc/tools/postprocess_instance_ufo.py | 28 |
3 files changed, 113 insertions, 5 deletions
diff --git a/misc/tools/gen-instance-ufo.sh b/misc/tools/gen-instance-ufo.sh new file mode 100755 index 000000000..b8deb0632 --- /dev/null +++ b/misc/tools/gen-instance-ufo.sh @@ -0,0 +1,69 @@ +#!/bin/sh +set -e +PROG=${0##*/} +DESIGNSPACE=$1 +UFO=$2 + +INSTANCE_Light="Inter Light" +INSTANCE_ExtraLight="Inter Extra Light" +INSTANCE_Medium="Inter Medium" +INSTANCE_SemiBold="Inter Semi Bold" +INSTANCE_Bold="Inter Bold" +INSTANCE_ExtraBold="Inter Extra Bold" + +INSTANCE_DisplayLight="Inter Display Light" +INSTANCE_DisplayExtraLight="Inter Display Extra Light" +INSTANCE_DisplayMedium="Inter Display Medium" +INSTANCE_DisplaySemiBold="Inter Display Semi Bold" +INSTANCE_DisplayBold="Inter Display Bold" +INSTANCE_DisplayExtraBold="Inter Display Extra Bold" + +INSTANCE_LightItalic="Inter Light Italic" +INSTANCE_ExtraLightItalic="Inter Extra Light Italic" +INSTANCE_MediumItalic="Inter Medium Italic" +INSTANCE_SemiBoldItalic="Inter Semi Bold Italic" +INSTANCE_BoldItalic="Inter Bold Italic" +INSTANCE_ExtraBoldItalic="Inter Extra Bold Italic" + +INSTANCE_DisplayLightItalic="Inter Display Light Italic" +INSTANCE_DisplayExtraLightItalic="Inter Display Extra Light Italic" +INSTANCE_DisplayMediumItalic="Inter Display Medium Italic" +INSTANCE_DisplaySemiBoldItalic="Inter Display Semi Bold Italic" +INSTANCE_DisplayBoldItalic="Inter Display Bold Italic" +INSTANCE_DisplayExtraBoldItalic="Inter Display Extra Bold Italic" + +MASTER_Thin=1 +MASTER_Regular=1 +MASTER_Black=1 +MASTER_ThinItalic=1 +MASTER_Italic=1 +MASTER_BlackItalic=1 +MASTER_DisplayThin=1 +MASTER_Display=1 +MASTER_DisplayBlack=1 +MASTER_DisplayThinItalic=1 +MASTER_DisplayItalic=1 +MASTER_DisplayBlackItalic=1 + +_err() { echo "$PROG: $@" >&2; exit 1; } + +# build/ufo/Inter-DisplayExtraBold.ufo -> DisplayExtraBold +UFO_NAME=$(basename "$UFO" .ufo) +case "$UFO_NAME" in Inter-*) UFO_NAME=${UFO_NAME:6} ;; esac + +# DisplayExtraBold -> "Inter Display Extra Bold" +INSTANCE=INSTANCE_${UFO_NAME} ; INSTANCE=${!INSTANCE} + +# If UFO is not an instance, assume that it's a master (or else error) +# master UFOs are byproducts of building Inter.designspace, so we just update mtime. +if [ -z "$INSTANCE" ]; then + MASTER=MASTER_${UFO_NAME} + [ -n "${!MASTER}" ] || _err "Failed to map UFO name \"$UFO_NAME\" to instance" + echo "touch $UFO" + touch "$UFO" + exit +fi + +set -x +fontmake -o ufo -m "$DESIGNSPACE" --output-path "$UFO" -i "$INSTANCE" +exec python misc/tools/postprocess_instance_ufo.py "$UFO" diff --git a/misc/tools/postprocess-designspace.py b/misc/tools/postprocess-designspace.py index 8dae2b571..745e73570 100644 --- a/misc/tools/postprocess-designspace.py +++ b/misc/tools/postprocess-designspace.py @@ -6,6 +6,8 @@ from datetime import datetime sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'tools'))) from common import getGitHash, getVersion +from postprocess_instance_ufo import ufo_set_wws + def update_version(ufo): version = getVersion() @@ -24,6 +26,7 @@ def update_version(ufo): ufo.info.openTypeNameUniqueID = "%s-%s:%d:%s" % (psFamily, psStyle, now.year, buildtag) ufo.info.openTypeHeadCreated = now.strftime("%Y/%m/%d %H:%M:%S") + def fix_opsz_range(designspace): # TODO: find extremes by looking at the source for a in designspace.axes: @@ -33,6 +36,7 @@ def fix_opsz_range(designspace): break return designspace + def fix_wght_range(designspace): for a in designspace.axes: if a.tag == "wght": @@ -41,6 +45,7 @@ def fix_wght_range(designspace): break return designspace + def should_decompose_glyph(g): # A trivial glyph is one that does not use components or where component transformation # does not include mirroring (i.e. "flipped"). @@ -58,12 +63,14 @@ def should_decompose_glyph(g): return True return False + def find_glyphs_to_decompose(designspace): source = designspace.sources[int(len(designspace.sources)/2)] print("find_glyphs_to_decompose sourcing from %r" % source.name) ufo = defcon.Font(source.path) return sorted([g.name for g in ufo if should_decompose_glyph(g)]) + def set_ufo_filter(ufo, **filter_dict): filters = ufo.lib.setdefault("com.github.googlei18n.ufo2ft.filters", []) for i in range(len(filters)): @@ -72,24 +79,27 @@ def set_ufo_filter(ufo, **filter_dict): return filters.append(filter_dict) -def update_source_ufo(ufo_file, weight, glyphs_to_decompose): - print(f"update {os.path.basename(ufo_file)} (weight={weight})") + +def update_source_ufo(ufo_file, glyphs_to_decompose): + print(f"update {os.path.basename(ufo_file)}") ufo = defcon.Font(ufo_file) update_version(ufo) set_ufo_filter(ufo, name="decomposeComponents", include=glyphs_to_decompose) + ufo_set_wws(ufo) # Fix missing WWS entries for Display fonts ufo.save(ufo_file) + def update_sources(designspace): glyphs_to_decompose = find_glyphs_to_decompose(designspace) #print("glyphs marked to be decomposed: %s" % ', '.join(glyphs_to_decompose)) sources = [source for source in designspace.sources] # sources = [s for s in sources if s.name == "Inter Thin"] # DEBUG - source_files = list(set([(s.path, s.location["Weight"]) for s in sources])) + source_files = list(set([s.path for s in sources])) with Pool(len(source_files)) as p: - p.starmap(update_source_ufo, - [(t[0], t[1], glyphs_to_decompose) for t in source_files]) + p.starmap(update_source_ufo, [(path, glyphs_to_decompose) for path in source_files]) return designspace + def main(argv): designspace_file = argv[1] designspace = DesignSpaceDocument.fromfile(designspace_file) @@ -98,5 +108,6 @@ def main(argv): designspace = update_sources(designspace) designspace.write(designspace_file) + if __name__ == '__main__': main(sys.argv) diff --git a/misc/tools/postprocess_instance_ufo.py b/misc/tools/postprocess_instance_ufo.py new file mode 100644 index 000000000..26d29aa96 --- /dev/null +++ b/misc/tools/postprocess_instance_ufo.py @@ -0,0 +1,28 @@ +import sys +import defcon + +def ufo_set_wws(ufo): + # Fix missing WWS entries for Display fonts: + # See https://github.com/googlefonts/glyphsLib/issues/820 + subfamily = ufo.info.styleName + if subfamily.find("Display") == -1: + return + subfamily = subfamily[len("Display"):].strip() + if subfamily == "": + # "Display" -> "Regular" + subfamily = "Regular" + ufo.info.openTypeNameWWSFamilyName = "Inter Display" + ufo.info.openTypeNameWWSSubfamilyName = subfamily + + +def main(argv): + ufo_file = argv[1] + if ufo_file.find("Display") == -1: + return # skip fonts of "default" family + ufo = defcon.Font(ufo_file) + ufo_set_wws(ufo) + ufo.save(ufo_file) + + +if __name__ == '__main__': + main(sys.argv) |