[cantarell-fonts/housekeeping: 3/3] Subroutinize with cffsubr after autohinting



commit a848a9b2da6e9d2e863e9f8f6b08df9f41637765
Author: Nikolaus Waxweiler <madigens gmail com>
Date:   Sat Jun 13 22:03:26 2020 +0100

    Subroutinize with cffsubr after autohinting

 scripts/make-static-fonts.py  |  7 +++++++
 scripts/make-variable-font.py | 31 ++++++++++---------------------
 2 files changed, 17 insertions(+), 21 deletions(-)
---
diff --git a/scripts/make-static-fonts.py b/scripts/make-static-fonts.py
index 7b2a9c17..634daf45 100644
--- a/scripts/make-static-fonts.py
+++ b/scripts/make-static-fonts.py
@@ -5,6 +5,8 @@ import multiprocessing
 import subprocess
 from pathlib import Path
 
+import cffsubr
+import fontTools.ttLib
 import fontTools.designspaceLib
 import ufo2ft
 
@@ -31,6 +33,7 @@ def generate_and_write_autohinted_instance(
         overlapsBackend="pathops",
         inplace=True,
         useProductionNames=True,
+        optimizeCFF=ufo2ft.CFFOptimization.NONE,
     )
     output_path = output_dir / f"{file_stem}.otf"
     instance_font.save(output_path)
@@ -38,6 +41,10 @@ def generate_and_write_autohinted_instance(
     # 5. Run psautohint on it.
     subprocess.run([psautohint, str(output_path)])
 
+    # 6. Subroutinize (compress) it
+    instance_font = fontTools.ttLib.TTFont(output_path)
+    cffsubr.subroutinize(instance_font).save(output_path)
+
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()
diff --git a/scripts/make-variable-font.py b/scripts/make-variable-font.py
index 5c245664..944d99d7 100644
--- a/scripts/make-variable-font.py
+++ b/scripts/make-variable-font.py
@@ -11,8 +11,10 @@ import subprocess
 import os
 from pathlib import Path
 
+import cffsubr
 import fontTools.designspaceLib
 import fontTools.varLib
+import fontTools.ttLib
 import statmake.classes
 import statmake.lib
 import ufo2ft
@@ -50,7 +52,12 @@ designspace.instances = [
 ]
 
 # 2. Compile variable OTF from the masters.
-varfont = ufo2ft.compileVariableCFF2(designspace, inplace=True, useProductionNames=True)
+varfont = ufo2ft.compileVariableCFF2(
+    designspace,
+    inplace=True,
+    useProductionNames=True,
+    optimizeCFF=ufo2ft.CFFOptimization.NONE,
+)
 
 # 3. Generate STAT table.
 stylespace = statmake.classes.Stylespace.from_file(stylespace_path)
@@ -63,23 +70,5 @@ varfont.save(output_path)
 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),
-    ]
-)
+varfont = fontTools.ttLib.TTFont(output_path)
+cffsubr.subroutinize(varfont).save(output_path)


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