harfbuzzjs 0.3.1 → 0.3.2
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.
- package/config-override-subset.h +1 -0
- package/examples/hb-subset.example.node.js +33 -14
- package/hb-subset.symbols +4 -0
- package/hb-subset.wasm +0 -0
- package/hb.wasm +0 -0
- package/package.json +1 -1
- package/.github/workflows/build.yml +0 -45
- package/.gitmodules +0 -3
- package/wapm.toml +0 -8
package/config-override-subset.h
CHANGED
|
@@ -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
|
|
4
|
-
const
|
|
5
|
-
const
|
|
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
|
|
9
|
-
const
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
38
|
+
const resultBlob = exports.hb_face_reference_blob(subset);
|
|
35
39
|
|
|
36
|
-
const
|
|
37
|
-
const
|
|
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
|
-
|
|
40
|
-
|
|
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(
|
|
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/package.json
CHANGED
|
@@ -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