[cantarell-fonts/ufo-conversion] Add script to generate a variable font



commit 6a0a516925929102bc381551ade0a2b5f528c197
Author: Nikolaus Waxweiler <madigens gmail com>
Date:   Wed Feb 27 23:38:03 2019 +0000

    Add script to generate a variable font

 requirements-dev.txt          |  6 +++--
 requirements.in               |  1 +
 requirements.txt              |  5 +++-
 scripts/make-variable-font.py | 53 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+), 3 deletions(-)
---
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 50a59482..d532f244 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -5,14 +5,15 @@
 #    pip-compile --output-file requirements-dev.txt requirements-dev.in
 #
 appdirs==1.4.3
-attrs==18.2.0             # via ufolib2
+attrs==18.2.0
 booleanoperations==0.8.2
+cattrs==0.9.0
 compreffor==0.4.6.post1
 cu2qu==1.6.5
 defcon[lxml]==0.6.0
 fontmake==1.9.1
 fontmath==0.4.9
-fonttools[lxml,ufo,unicode]==3.37.3
+fonttools[lxml,ufo,unicode]==3.38.0
 fs==2.3.0
 glyphslib==3.2.0
 lxml==4.3.1
@@ -21,5 +22,6 @@ psautohint==1.9.1
 pyclipper==1.1.0.post1
 pytz==2018.9
 six==1.12.0
+statmake==0.1.0
 ufo2ft==2.7.0
 ufolib2==0.3.0
diff --git a/requirements.in b/requirements.in
index 68583d79..48e63ac2 100644
--- a/requirements.in
+++ b/requirements.in
@@ -1,2 +1,3 @@
 fontmake>=1.9.1
 psautohint>=1.8.0
+statmake
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 1f442250..07ac17bb 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,13 +5,15 @@
 #    pip-compile --output-file requirements.txt requirements.in
 #
 appdirs==1.4.3            # via fs
+attrs==18.2.0             # via cattrs, statmake
 booleanoperations==0.8.2  # via fontmake, ufo2ft
+cattrs==0.9.0             # via statmake
 compreffor==0.4.6.post1   # via ufo2ft
 cu2qu==1.6.5              # via fontmake, ufo2ft
 defcon[lxml]==0.6.0       # via fontmake, glyphslib, mutatormath, ufo2ft
 fontmake==1.9.1
 fontmath==0.4.9           # via mutatormath
-fonttools[lxml,ufo,unicode]==3.37.3  # via booleanoperations, compreffor, cu2qu, defcon, fontmake, fontmath, 
glyphslib, mutatormath, psautohint, ufo2ft
+fonttools[lxml,ufo,unicode]==3.38.0  # via booleanoperations, compreffor, cu2qu, defcon, fontmake, fontmath, 
glyphslib, mutatormath, psautohint, statmake, ufo2ft
 fs==2.3.0                 # via fonttools
 glyphslib==3.2.0          # via fontmake
 lxml==4.3.1               # via fonttools
@@ -20,4 +22,5 @@ psautohint==1.9.1
 pyclipper==1.1.0.post1    # via booleanoperations
 pytz==2018.9              # via fs
 six==1.12.0               # via fs
+statmake==0.1.0
 ufo2ft==2.7.0             # via fontmake
diff --git a/scripts/make-variable-font.py b/scripts/make-variable-font.py
new file mode 100644
index 00000000..63b6a3db
--- /dev/null
+++ b/scripts/make-variable-font.py
@@ -0,0 +1,53 @@
+#!/bin/env python3
+
+# Note: To parallelize this, the cubic to quadratic filter could be run on all sources
+# sequentially and the resulting single-layer UFOs written to disk, then compiling the
+# masters could be done in parallel and finally, merging into a variable font happens
+# sequentially.
+
+import argparse
+from pathlib import Path
+
+import fontTools.designspaceLib
+import fontTools.varLib
+import statmake.classes
+import statmake.lib
+import ufo2ft
+import ufoLib2
+
+parser = argparse.ArgumentParser()
+parser.add_argument(
+    "designspace_path", type=Path, help="The path to the Designspace file."
+)
+parser.add_argument(
+    "stylespace_path", type=Path, help="The path to the Stylespace file."
+)
+parser.add_argument("output_path", type=Path, help="The variable TTF output path.")
+args = parser.parse_args()
+
+designspace_path = args.designspace_path.resolve()
+stylespace_path = args.stylespace_path.resolve()
+output_path = args.output_path.resolve()
+
+
+# 1. Load Designspace and filter out instances that are marked as non-exportable.
+designspace = fontTools.designspaceLib.DesignSpaceDocument.fromfile(designspace_path)
+for source in designspace.sources:
+    source.font = ufoLib2.Font.open(designspace_path.parent / source.filename)
+
+designspace.instances = [
+    s for s in designspace.instances if s.lib.get("com.schriftgestaltung.export", True)
+]
+
+# 2. Compile interpolatable master TTFs.
+ufo2ft.compileInterpolatableTTFsFromDS(designspace, inplace=True)
+
+# 3. Combine masters into a variable TTF.
+varfont, _, _ = fontTools.varLib.build(designspace)
+
+# 4. Generate STAT table.
+stylespace = statmake.classes.Stylespace.from_file(stylespace_path)
+statmake.lib.apply_stylespace_to_variable_font(stylespace, varfont, {})
+
+
+varfont.save(output_path)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]