[cantarell-fonts] Compress VF with the AFDKO



commit 5719b301089ba91d3efff4b9885ffcc1e81b3bd2
Author: Nikolaus Waxweiler <madigens gmail com>
Date:   Fri Jan 3 23:54:48 2020 +0000

    Compress VF with the AFDKO

 requirements-dev.txt          | 16 +++++++++++++---
 requirements.in               |  1 +
 requirements.txt              | 17 ++++++++++++++---
 scripts/make-variable-font.py | 38 ++++++++++++++++++++++++++++++++++----
 4 files changed, 62 insertions(+), 10 deletions(-)
---
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 53f0a46f..15d6e1b2 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -4,20 +4,27 @@
 #
 #    pip-compile requirements-dev.in
 #
+afdko==3.1.0
 appdirs==1.4.3
 astroid==2.3.3            # via pylint
 attrs==19.3.0
 booleanoperations==0.9.0
+brotli==1.0.7
 cattrs==1.0.0
 compreffor==0.5.0
-cu2qu==1.6.6
+cu2qu[cli]==1.6.6
+defcon[lxml,pens]==0.6.0
 fontmath==0.5.2
-fonttools[ufo,unicode]==4.2.2
+fontparts==0.9.2
+fontpens==0.2.4
+fonttools[lxml,ufo,unicode,woff]==4.2.2
 fs==2.4.11
 glyphslib==5.1.0
 isort==4.3.21             # via pylint
 lazy-object-proxy==1.4.3  # via astroid
+lxml==4.4.2
 mccabe==0.6.1             # via pylint
+mutatormath==2.1.2
 mypy-extensions==0.4.3    # via mypy
 mypy==0.761
 psautohint==2.0.0
@@ -31,8 +38,11 @@ typed-ast==1.4.0          # via astroid, mypy
 typing-extensions==3.7.4.1  # via mypy
 ufo2ft==2.11.1
 ufolib2==0.5.1
-unicodedata2==12.1.0      # via fonttools
+ufonormalizer==0.3.6
+ufoprocessor==1.0.6
+unicodedata2==12.1.0
 wrapt==1.11.2             # via astroid
+zopfli==0.1.7
 
 # The following packages are considered to be unsafe in a requirements file:
 # setuptools
diff --git a/requirements.in b/requirements.in
index cf2f206a..4e32e327 100644
--- a/requirements.in
+++ b/requirements.in
@@ -1,3 +1,4 @@
+afdko>=3.1.0
 attrs>=18.2
 fontMath>=0.5.0
 fontTools>=4.0.0
diff --git a/requirements.txt b/requirements.txt
index d02663c9..ce393294 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,15 +4,22 @@
 #
 #    pip-compile requirements.in
 #
+afdko==3.1.0
 appdirs==1.4.3            # via fs
 attrs==19.3.0
-booleanoperations==0.9.0  # via ufo2ft
+booleanoperations==0.9.0  # via afdko, ufo2ft
+brotli==1.0.7             # via fonttools
 cattrs==1.0.0             # via statmake
 compreffor==0.5.0         # via ufo2ft
-cu2qu==1.6.6              # via ufo2ft
+cu2qu[cli]==1.6.6         # via afdko, ufo2ft
+defcon[lxml,pens]==0.6.0  # via afdko, cu2qu, fontparts, mutatormath, ufoprocessor
 fontmath==0.5.2
-fonttools[ufo]==4.2.2
+fontparts==0.9.2          # via ufoprocessor
+fontpens==0.2.4           # via defcon
+fonttools[lxml,ufo,unicode,woff]==4.2.2
 fs==2.4.11                # via fonttools
+lxml==4.4.2               # via afdko, fonttools
+mutatormath==2.1.2        # via afdko, ufoprocessor
 psautohint==2.0.0
 pyclipper==1.1.0.post3    # via booleanoperations
 pytz==2019.3              # via fs
@@ -21,6 +28,10 @@ skia-pathops==0.2.1
 statmake==0.2.2
 ufo2ft==2.11.1
 ufolib2==0.5.1
+ufonormalizer==0.3.6      # via afdko
+ufoprocessor==1.0.6       # via afdko
+unicodedata2==12.1.0      # via fonttools
+zopfli==0.1.7             # via fonttools
 
 # The following packages are considered to be unsafe in a requirements file:
 # setuptools
diff --git a/scripts/make-variable-font.py b/scripts/make-variable-font.py
index e8a0f89d..5c245664 100644
--- a/scripts/make-variable-font.py
+++ b/scripts/make-variable-font.py
@@ -6,7 +6,9 @@
 # sequentially.
 
 import argparse
+import tempfile
 import subprocess
+import os
 from pathlib import Path
 
 import fontTools.designspaceLib
@@ -23,7 +25,13 @@ parser.add_argument(
 parser.add_argument(
     "stylespace_path", type=Path, help="The path to the Stylespace file."
 )
-parser.add_argument("psautohint_path", type=Path, help="The path to psautohint.")
+parser.add_argument(
+    "psautohint_path", type=Path, help="The path to the psautohint executable."
+)
+parser.add_argument("tx_path", type=Path, help="The path to the AFDKO's tx executable.")
+parser.add_argument(
+    "sfntedit_path", type=Path, help="The path to the AFDKO's sfntedit executable."
+)
 parser.add_argument("output_path", type=Path, help="The variable TTF output path.")
 args = parser.parse_args()
 
@@ -48,8 +56,30 @@ varfont = ufo2ft.compileVariableCFF2(designspace, inplace=True, useProductionNam
 stylespace = statmake.classes.Stylespace.from_file(stylespace_path)
 statmake.lib.apply_stylespace_to_variable_font(stylespace, varfont, {})
 
-# External tools after this point.
+# 4. Save. External tools after this point.
 varfont.save(output_path)
 
-# 4. Autohint
-subprocess.run([psautohint_path, str(output_path)])
+# 5. Autohint
+subprocess.check_call([os.fspath(args.psautohint_path), os.fspath(output_path)])
+
+# 6. Subroutinize (compress)
+tmp_cff2_table = os.fspath(Path(tempfile.mkdtemp()) / "cff2_table")
+subprocess.check_call(
+    [
+        os.fspath(args.tx_path),
+        "-cff2",
+        "+S",  # Subroutinize.
+        "+b",  # Preserve glyph order.
+        os.fspath(output_path),
+        tmp_cff2_table,
+    ]
+)
+os.chdir(output_path.parent)  # Avoid weird "Invalid cross-device link" error.
+subprocess.check_call(
+    [
+        os.fspath(args.sfntedit_path),
+        "-a",
+        f"CFF2={tmp_cff2_table}",  # Reinsert compressed CFF2 table in-place.
+        os.fspath(output_path),
+    ]
+)


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