harfbuzzjs 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,3 +2,4 @@
2
2
  #undef HB_NO_OT_FONT_CFF
3
3
  #undef HB_NO_SUBSET_CFF
4
4
  #undef HB_NO_SUBSET_LAYOUT
5
+ #undef HB_NO_VAR
@@ -1,13 +1,17 @@
1
1
  // Based on https://github.com/harfbuzz/harfbuzzjs/issues/9#issuecomment-507874962
2
2
  // Which was based on https://github.com/harfbuzz/harfbuzzjs/issues/9#issuecomment-507622485
3
- const fs = require('fs');
4
- const readFileAsync = require('util').promisify(fs.readFile);
5
- const writeFileAsync = require('util').promisify(fs.writeFile);
3
+ const { readFile, writeFile } = require('fs').promises;
4
+ const { join, extname, basename } = require('path');
5
+ const { performance } = require('node:perf_hooks');
6
+
7
+ const SUBSET_TEXT = 'abc';
6
8
 
7
9
  (async () => {
8
- const { instance: { exports } } = await WebAssembly.instantiate(await readFileAsync(__dirname + '/../hb-subset.wasm'));
9
- const fontBlob = await readFileAsync(__dirname + '/Roboto-Black.ttf');
10
+ const { instance: { exports } } = await WebAssembly.instantiate(await readFile(join(__dirname, '../hb-subset.wasm')));
11
+ const fileName = 'Roboto-Black.ttf';
12
+ const fontBlob = await readFile(join(__dirname, '/', fileName));
10
13
 
14
+ const t = performance.now();
11
15
  const heapu8 = new Uint8Array(exports.memory.buffer);
12
16
  const fontBuffer = exports.malloc(fontBlob.byteLength);
13
17
  heapu8.set(new Uint8Array(fontBlob), fontBuffer);
@@ -20,9 +24,9 @@ const writeFileAsync = require('util').promisify(fs.writeFile);
20
24
  /* Add your glyph indices here and subset */
21
25
  const input = exports.hb_subset_input_create_or_fail();
22
26
  const unicode_set = exports.hb_subset_input_unicode_set(input);
23
- exports.hb_set_add(unicode_set, 'a'.charCodeAt(0));
24
- exports.hb_set_add(unicode_set, 'b'.charCodeAt(0));
25
- exports.hb_set_add(unicode_set, 'c'.charCodeAt(0));
27
+ for (const text of SUBSET_TEXT) {
28
+ exports.hb_set_add(unicode_set, text.codePointAt(0));
29
+ }
26
30
 
27
31
  // exports.hb_subset_input_set_drop_hints(input, true);
28
32
  const subset = exports.hb_subset_or_fail(face, input);
@@ -31,16 +35,31 @@ const writeFileAsync = require('util').promisify(fs.writeFile);
31
35
  exports.hb_subset_input_destroy(input);
32
36
 
33
37
  /* Get result blob */
34
- const result = exports.hb_face_reference_blob(subset);
38
+ const resultBlob = exports.hb_face_reference_blob(subset);
35
39
 
36
- const data = exports.hb_blob_get_data(result, 0);
37
- const subsetFontBlob = heapu8.subarray(data, data + exports.hb_blob_get_length(result));
40
+ const offset = exports.hb_blob_get_data(resultBlob, 0);
41
+ const subsetByteLength = exports.hb_blob_get_length(resultBlob);
42
+ if (subsetByteLength === 0) {
43
+ exports.hb_blob_destroy(resultBlob);
44
+ exports.hb_face_destroy(subset);
45
+ exports.hb_face_destroy(face);
46
+ exports.free(fontBuffer);
47
+ throw new Error(
48
+ 'Failed to create subset font, maybe the input file is corrupted?'
49
+ );
50
+ }
51
+
52
+ // Output font data(Uint8Array)
53
+ const subsetFontBlob = heapu8.subarray(offset, offset + exports.hb_blob_get_length(resultBlob));
54
+ console.info('✨ Subset done in', performance.now() - t, 'ms');
38
55
 
39
- await writeFileAsync(__dirname + '/Roboto-Black.subset.ttf', subsetFontBlob);
40
- console.log(`Wrote subset to: ${__dirname}/Roboto-Black.subset.ttf`);
56
+ const extName = extname(fileName).toLowerCase();
57
+ const fontName = basename(fileName, extName);
58
+ await writeFile(join(__dirname, '/', `${fontName}.subset${extName}`), subsetFontBlob);
59
+ console.info(`Wrote subset to: ${__dirname}/${fontName}.subset${extName}`);
41
60
 
42
61
  /* Clean up */
43
- exports.hb_blob_destroy(result);
62
+ exports.hb_blob_destroy(resultBlob);
44
63
  exports.hb_face_destroy(subset);
45
64
  exports.hb_face_destroy(face);
46
65
  exports.free(fontBuffer);
package/hb-subset.symbols CHANGED
@@ -18,11 +18,15 @@ _hb_subset_input_destroy
18
18
  _hb_subset_input_get_flags
19
19
  _hb_subset_input_get_user_data
20
20
  _hb_subset_input_glyph_set
21
+ _hb_subset_input_pin_axis_location
22
+ _hb_subset_input_pin_axis_to_default
21
23
  _hb_subset_input_reference
22
24
  _hb_subset_input_set
23
25
  _hb_subset_input_set_flags
24
26
  _hb_subset_input_set_user_data
25
27
  _hb_subset_input_unicode_set
28
+ _hb_subset_input_keep_everything
26
29
  _hb_subset_or_fail
30
+ _hb_subset_preprocess
27
31
  _malloc
28
32
  _free
package/hb-subset.wasm CHANGED
Binary file
package/hb.wasm CHANGED
Binary file
package/hbjs.js CHANGED
@@ -142,7 +142,7 @@ function hbjs(instance) {
142
142
  var unicodeSetPtr = exports.hb_set_create();
143
143
  exports.hb_face_collect_unicodes(ptr, unicodeSetPtr);
144
144
  var result = typedArrayFromSet(unicodeSetPtr, Uint32Array);
145
- exports.hb_set_destroy(ptr);
145
+ exports.hb_set_destroy(unicodeSetPtr);
146
146
  return result;
147
147
  },
148
148
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harfbuzzjs",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Minimal version of HarfBuzz for JavaScript use",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,45 +0,0 @@
1
- name: Build
2
-
3
- on:
4
- push:
5
- branches: [ "main" ]
6
- pull_request:
7
- branches: [ "main" ]
8
-
9
- env:
10
- EM_VERSION: 3.1.16
11
- EM_CACHE_FOLDER: 'emsdk-cache'
12
-
13
- jobs:
14
- build:
15
-
16
- runs-on: ubuntu-latest
17
-
18
- steps:
19
- - name: Checkout
20
- uses: actions/checkout@v3
21
- with:
22
- submodules: true
23
-
24
- - name: Setup cache
25
- id: cache-system-libraries
26
- uses: actions/cache@v3
27
- with:
28
- path: ${{env.EM_CACHE_FOLDER}}
29
- key: ${{env.EM_VERSION}}-${{runner.os}}
30
- - name: Setup Emscripten
31
- uses: mymindstorm/setup-emsdk@v11
32
- with:
33
- version: ${{env.EM_VERSION}}
34
- actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
35
- - name: Build hb.wasm
36
- run: ./build.sh
37
- - name: Build hb-subset.wasm
38
- run: ./build-subset.sh
39
-
40
- - name: Setup Node.js
41
- uses: actions/setup-node@v3
42
- - name: Test hb.wasm
43
- run: node examples/hbjs.example.node.js
44
- - name: Test hb-subset.wasm
45
- run: node examples/hb-subset.example.node.js
package/.gitmodules DELETED
@@ -1,3 +0,0 @@
1
- [submodule "harfbuzz"]
2
- path = harfbuzz
3
- url = https://github.com/harfbuzz/harfbuzz.git
package/wapm.toml DELETED
@@ -1,8 +0,0 @@
1
- [package]
2
- name = "ebraminio/harfbuzz"
3
- version = "0.0.2"
4
- description = "HarfBuzz text shaping engine"
5
-
6
- [[module]]
7
- name = "harfbuzz"
8
- source = "hb.wasm"