papandreou / subset-font

Create a subset of a TrueType/OpenType/WOFF/WOFF2 font using the wasm build of harfbuzz/hb-subset
BSD 3-Clause "New" or "Revised" License
85 stars 6 forks source link

Upgrade harfbuzzjs 0.2.0 / harfbuzz 3.0.0 #12

Closed ebraminio closed 2 years ago

ebraminio commented 2 years ago

HarfBuzz 3.0.0 provides a different set of API for its subset functionality, opened this file to let you know about the release and the fact the upgrade needs some intervention. Thanks!

papandreou commented 2 years ago

Thanks for the heads up!

I don't know what the equivalent of hb_subset_input_nameid_set is in the new version, but this seems to sort of work:

diff --git a/package.json b/package.json
index 5f2e712..94c684c 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
   "main": "index.js",
   "dependencies": {
     "fontverter": "^2.0.0",
-    "harfbuzzjs": "^0.1.5",
+    "harfbuzzjs": "^0.2.0",
     "lodash": "^4.17.21",
     "p-limit": "^3.1.0"
   },
diff --git a/index.js b/index.js
index 904d287..ad85c42 100644
--- a/index.js
+++ b/index.js
@@ -45,10 +45,10 @@ async function subsetFont(
   const input = exports.hb_subset_input_create_or_fail();

   if (preserveNameIds) {
-    const inputNameIds = exports.hb_subset_input_nameid_set(input);
-    for (const nameId of preserveNameIds) {
-      exports.hb_set_add(inputNameIds, nameId);
-    }
+    // const inputNameIds = exports.hb_subset_input_nameid_set(input);
+    // for (const nameId of preserveNameIds) {
+    //   exports.hb_set_add(inputNameIds, nameId);
+    // }
   }

   // Add unicodes indices
@@ -57,7 +57,7 @@ async function subsetFont(
     exports.hb_set_add(inputUnicodes, c.codePointAt(0));
   }

-  const subset = exports.hb_subset(face, input);
+  const subset = exports.hb_subset_or_fail(face, input);

   // Clean up
   exports.hb_subset_input_destroy(input);

When I link it into the subfont test suite, everything seems to work, except that one of the reference image-based tests complains that the web page renders differently before vs. after subsetting. It produces this image diff:

121104-53177-8-10w3kkc esw1

I guess I'll just wait for the updated example 😇

ebraminio commented 2 years ago

I don't know what the equivalent of hb_subset_input_nameid_set is in the new version

It should be hb_subset_input_set(input, 4/*HB_SUBSET_SETS_NAME_ID*/) IIUC

I guess I'll just wait for the updated example 😇

Guess you had good progress here actually!

papandreou commented 2 years ago

Ah yeah, that works, now the (minimal) test suite here passes. I opened a PR here: https://github.com/papandreou/subset-font/pull/13

Would be nice to figure out why that subfont test fails, but I don't really know where to start 🙈