ttf2woff2 7.0.0 → 8.0.0
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/CHANGELOG.md +9 -0
- package/csrc/addon.cc +2 -1
- package/csrc/fallback.cc +5 -2
- package/dist/tests.test.js +25 -1
- package/dist/tests.test.js.map +1 -1
- package/jssrc/index.js +22 -14
- package/jssrc/ttf2woff2.wasm +0 -0
- package/package.json +3 -3
- package/src/tests.test.ts +28 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
# [8.0.0](https://github.com/nfroidure/ttf2woff2/compare/v7.0.0...v8.0.0) (2025-06-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **leak:** fix the error cas memory leak ([0896e18](https://github.com/nfroidure/ttf2woff2/commit/0896e183ee7f43d5f7cca5d4205557548dd86c71)), closes [#91](https://github.com/nfroidure/ttf2woff2/issues/91)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
# [7.0.0](https://github.com/nfroidure/ttf2woff2/compare/v6.0.1...v7.0.0) (2025-05-22)
|
|
2
11
|
|
|
3
12
|
|
package/csrc/addon.cc
CHANGED
|
@@ -31,7 +31,8 @@ NAN_METHOD(convert) {
|
|
|
31
31
|
reinterpret_cast<const uint8_t*>(input_data), input_length,
|
|
32
32
|
reinterpret_cast<uint8_t*>(output_data), &actual_output_length
|
|
33
33
|
)) {
|
|
34
|
-
|
|
34
|
+
free(output_data);
|
|
35
|
+
Nan::ThrowError(Nan::Error("E_CONVERT_ERROR"));
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
|
package/csrc/fallback.cc
CHANGED
|
@@ -22,16 +22,19 @@ int convert(int inputDataAddress, int inputLength, int outputSizePtrAddress) {
|
|
|
22
22
|
|
|
23
23
|
uint8_t* outputData = reinterpret_cast<uint8_t*>(calloc(outputSize, sizeof(uint8_t)));
|
|
24
24
|
|
|
25
|
-
|
|
26
25
|
if(!woff2::ConvertTTFToWOFF2(
|
|
27
26
|
reinterpret_cast<const uint8_t*>(inputData),
|
|
28
27
|
inputLength,
|
|
29
28
|
outputData,
|
|
30
29
|
&outputSize
|
|
31
30
|
)) {
|
|
32
|
-
|
|
31
|
+
outputData = reinterpret_cast<uint8_t*>(realloc(outputData, 0));
|
|
32
|
+
*outputSizePtr = 0;
|
|
33
|
+
return reinterpret_cast<int>(outputData);
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
outputData = reinterpret_cast<uint8_t*>(realloc(outputData, outputSize));
|
|
37
|
+
|
|
35
38
|
*outputSizePtr = outputSize;
|
|
36
39
|
|
|
37
40
|
return reinterpret_cast<int>(outputData);
|
package/dist/tests.test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, test, expect, jest } from '@jest/globals';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { YError } from 'yerror';
|
|
3
4
|
describe('ttf2woff2', () => {
|
|
4
5
|
test('should work from the main endpoint', async () => {
|
|
5
6
|
jest.setTimeout(5000);
|
|
@@ -18,7 +19,18 @@ describe('ttf2woff2', () => {
|
|
|
18
19
|
expect(outputContent[1071]).toEqual(0);
|
|
19
20
|
expect(outputContent).toEqual(await readFile('fixtures/iconsfont.woff2'));
|
|
20
21
|
});
|
|
21
|
-
test('should
|
|
22
|
+
test('should well fail from the native build', async () => {
|
|
23
|
+
const ttf2woff2 = (await import('bindings')).default('addon.node').convert;
|
|
24
|
+
const inputContent = Buffer.alloc(2 ** 32, 0xff);
|
|
25
|
+
try {
|
|
26
|
+
ttf2woff2(inputContent);
|
|
27
|
+
throw new YError('E_UNEXPECTED_SUCCESS');
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
expect(err).toMatchInlineSnapshot(`[Error: E_CONVERT_ERROR]`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
test('should work from the Emscripten endpoint', async () => {
|
|
22
34
|
jest.setTimeout(5000);
|
|
23
35
|
const ttf2woff2 = (await import('../jssrc/index.js')).default;
|
|
24
36
|
const inputContent = await readFile('fixtures/iconsfont.ttf');
|
|
@@ -27,5 +39,17 @@ describe('ttf2woff2', () => {
|
|
|
27
39
|
expect(outputContent[1071]).toEqual(0);
|
|
28
40
|
expect(outputContent).toEqual(await readFile('fixtures/iconsfont.woff2'));
|
|
29
41
|
});
|
|
42
|
+
test('should well fail from the Emscripten build', async () => {
|
|
43
|
+
jest.setTimeout(5000);
|
|
44
|
+
const ttf2woff2 = (await import('../jssrc/index.js')).default;
|
|
45
|
+
const inputContent = Buffer.alloc(512, 0xff);
|
|
46
|
+
try {
|
|
47
|
+
ttf2woff2(inputContent);
|
|
48
|
+
throw new YError('E_UNEXPECTED_SUCCESS');
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
expect(err).toMatchInlineSnapshot(`[YError: E_CONVERT_ERROR (): E_CONVERT_ERROR]`);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
30
54
|
});
|
|
31
55
|
//# sourceMappingURL=tests.test.js.map
|
package/dist/tests.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tests.test.js","sourceRoot":"","sources":["../src/tests.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"tests.test.js","sourceRoot":"","sources":["../src/tests.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,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,CAAC,CAAC,CAAC,OAAO,CAAC;QAC9D,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAE7C,IAAI,CAAC;YACH,SAAS,CAAC,YAAY,CAAC,CAAC;YACxB,MAAM,IAAI,MAAM,CAAC,sBAAsB,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,CAAC,CAAC,qBAAqB,CAAC,+CAA+C,CAAC,CAAC;QACrF,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/jssrc/index.js
CHANGED
|
@@ -1,31 +1,39 @@
|
|
|
1
|
+
import { YError } from 'yerror';
|
|
1
2
|
import theTTFToWOFF2Module from './ttf2woff2.cjs';
|
|
2
3
|
|
|
3
4
|
export default function ttf2woff2(inputContent) {
|
|
4
5
|
// Prepare input
|
|
5
6
|
const inputBuffer = theTTFToWOFF2Module._malloc(inputContent.length + 1);
|
|
6
|
-
const outputSizePtr = theTTFToWOFF2Module._malloc(4);
|
|
7
|
+
const outputSizePtr = theTTFToWOFF2Module._malloc(4);
|
|
7
8
|
let outputBufferPtr;
|
|
8
9
|
let outputSize;
|
|
9
10
|
let outputContent;
|
|
10
11
|
|
|
11
12
|
theTTFToWOFF2Module.writeArrayToMemory(inputContent, inputBuffer);
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
try {
|
|
15
|
+
// Run
|
|
16
|
+
outputBufferPtr = theTTFToWOFF2Module.convert(
|
|
17
|
+
inputBuffer,
|
|
18
|
+
inputContent.length,
|
|
19
|
+
outputSizePtr,
|
|
20
|
+
);
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
// Retrieve output
|
|
23
|
+
outputSize = theTTFToWOFF2Module.getValue(outputSizePtr, 'i32');
|
|
24
|
+
outputContent = Buffer.alloc(outputSize);
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
for (let i = 0; i < outputSize; i++) {
|
|
27
|
+
outputContent[i] = theTTFToWOFF2Module.getValue(outputBufferPtr + i, 'i8');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (outputSize === 0) {
|
|
31
|
+
throw new YError('E_CONVERT_ERROR');
|
|
32
|
+
}
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
} finally {
|
|
35
|
+
theTTFToWOFF2Module.freePtrs(outputBufferPtr, outputSizePtr);
|
|
36
|
+
}
|
|
29
37
|
|
|
30
38
|
return outputContent;
|
|
31
39
|
};
|
package/jssrc/ttf2woff2.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"name": "ttf2woff2",
|
|
28
|
-
"version": "
|
|
28
|
+
"version": "8.0.0",
|
|
29
29
|
"description": "Convert TTF files to WOFF2 ones.",
|
|
30
30
|
"main": "dist/index.js",
|
|
31
31
|
"browser": "jssrc/index.js",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"configure": "node-gyp configure",
|
|
43
43
|
"cover": "npm run jest -- --coverage",
|
|
44
44
|
"cz": "env NODE_ENV=${NODE_ENV:-cli} git cz",
|
|
45
|
-
"emcc": "miniquery -p \"targets.#.sources.#\" ./binding.gyp | grep -v \"csrc/addon.cc\" | xargs emcc --bind -o jssrc/ttf2woff2.cjs -O2 -s \"TOTAL_MEMORY=536870912\" -s \"ALLOW_MEMORY_GROWTH=1\" -s BINARYEN_ASYNC_COMPILATION=0 -s EXPORTED_FUNCTIONS=[\"_malloc\"] -s 'EXPORTED_RUNTIME_METHODS=[\"getValue\", \"writeArrayToMemory\"]' -s NODEJS_CATCH_EXIT=0 -s NODEJS_CATCH_REJECTION=0 --post-js jssrc/post.js csrc/fallback.cc",
|
|
46
|
-
"emcc-debug": "miniquery -p \"targets.#.sources.#\" ./binding.gyp | grep -v \"csrc/addon.cc\" | xargs emcc --bind -o jssrc/ttf2woff2.cjs -s \"ALLOW_MEMORY_GROWTH=1\" -s \"ASSERTIONS=1\" -s BINARYEN_ASYNC_COMPILATION=0 -s EXPORTED_FUNCTIONS=[\"_malloc\"] -s 'EXPORTED_RUNTIME_METHODS=[\"getValue\", \"writeArrayToMemory\"]' -s NODEJS_CATCH_EXIT=0 -s NODEJS_CATCH_REJECTION=0 --post-js jssrc/post.js csrc/fallback.cc",
|
|
45
|
+
"emcc": "miniquery -p \"targets.#.sources.#\" ./binding.gyp | grep -v \"csrc/addon.cc\" | xargs docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emcc --bind -o jssrc/ttf2woff2.cjs -O2 -s \"TOTAL_MEMORY=536870912\" -s \"ALLOW_MEMORY_GROWTH=1\" -s BINARYEN_ASYNC_COMPILATION=0 -s EXPORTED_FUNCTIONS=[\"_malloc\"] -s 'EXPORTED_RUNTIME_METHODS=[\"getValue\", \"writeArrayToMemory\"]' -s NODEJS_CATCH_EXIT=0 -s NODEJS_CATCH_REJECTION=0 --post-js jssrc/post.js csrc/fallback.cc",
|
|
46
|
+
"emcc-debug": "miniquery -p \"targets.#.sources.#\" ./binding.gyp | grep -v \"csrc/addon.cc\" | xargs docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emcc --bind -o jssrc/ttf2woff2.cjs -s \"ALLOW_MEMORY_GROWTH=1\" -s \"ASSERTIONS=1\" -s BINARYEN_ASYNC_COMPILATION=0 -s EXPORTED_FUNCTIONS=[\"_malloc\"] -s 'EXPORTED_RUNTIME_METHODS=[\"getValue\", \"writeArrayToMemory\"]' -s NODEJS_CATCH_EXIT=0 -s NODEJS_CATCH_REJECTION=0 --post-js jssrc/post.js csrc/fallback.cc",
|
|
47
47
|
"format": "npm run prettier",
|
|
48
48
|
"install": "((node-gyp configure && node-gyp build) > builderror.log) || (exit 0)",
|
|
49
49
|
"jest": "NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest",
|
package/src/tests.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, test, expect, jest } from '@jest/globals';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { YError } from 'yerror';
|
|
3
4
|
|
|
4
5
|
describe('ttf2woff2', () => {
|
|
5
6
|
test('should work from the main endpoint', async () => {
|
|
@@ -24,7 +25,19 @@ describe('ttf2woff2', () => {
|
|
|
24
25
|
expect(outputContent).toEqual(await readFile('fixtures/iconsfont.woff2'));
|
|
25
26
|
});
|
|
26
27
|
|
|
27
|
-
test('should
|
|
28
|
+
test('should well fail from the native build', async () => {
|
|
29
|
+
const ttf2woff2 = (await import('bindings')).default('addon.node').convert;
|
|
30
|
+
const inputContent = Buffer.alloc(2 ** 32, 0xff);
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
ttf2woff2(inputContent);
|
|
34
|
+
throw new YError('E_UNEXPECTED_SUCCESS');
|
|
35
|
+
} catch (err) {
|
|
36
|
+
expect(err).toMatchInlineSnapshot(`[Error: E_CONVERT_ERROR]`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('should work from the Emscripten endpoint', async () => {
|
|
28
41
|
jest.setTimeout(5000);
|
|
29
42
|
|
|
30
43
|
const ttf2woff2 = (await import('../jssrc/index.js')).default;
|
|
@@ -35,4 +48,18 @@ describe('ttf2woff2', () => {
|
|
|
35
48
|
expect(outputContent[1071]).toEqual(0);
|
|
36
49
|
expect(outputContent).toEqual(await readFile('fixtures/iconsfont.woff2'));
|
|
37
50
|
});
|
|
51
|
+
|
|
52
|
+
test('should well fail from the Emscripten build', async () => {
|
|
53
|
+
jest.setTimeout(5000);
|
|
54
|
+
|
|
55
|
+
const ttf2woff2 = (await import('../jssrc/index.js')).default;
|
|
56
|
+
const inputContent = Buffer.alloc(512, 0xff);
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
ttf2woff2(inputContent);
|
|
60
|
+
throw new YError('E_UNEXPECTED_SUCCESS');
|
|
61
|
+
} catch (err) {
|
|
62
|
+
expect(err).toMatchInlineSnapshot(`[YError: E_CONVERT_ERROR (): E_CONVERT_ERROR]`);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
38
65
|
});
|