Skip to content

Commit

Permalink
Move allocations around so there's nothing to clean up when hb_subset…
Browse files Browse the repository at this point in the history
…_input_create_or_fail returns 0

#13 (comment)
  • Loading branch information
papandreou committed Nov 5, 2021
1 parent e2deb41 commit 2e3baa2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ async function subsetFont(

originalFont = await fontverter.convert(originalFont, 'truetype');

const input = exports.hb_subset_input_create_or_fail();
if (input === 0) {
throw new Error(
'hb_subset_input_create_or_fail (harfbuzz) returned zero, indicating failure'
);
}

const fontBuffer = exports.malloc(originalFont.byteLength);
heapu8.set(new Uint8Array(originalFont), fontBuffer);

Expand All @@ -42,13 +49,6 @@ async function subsetFont(
const face = exports.hb_face_create(blob, 0);
exports.hb_blob_destroy(blob);

const input = exports.hb_subset_input_create_or_fail();
if (input === 0) {
throw new Error(
'hb_subset_input_create_or_fail (harfbuzz) returned zero, indicating failure'
);
}

if (preserveNameIds) {
const inputNameIds = exports.hb_subset_input_set(
input,
Expand Down

0 comments on commit 2e3baa2

Please sign in to comment.