Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ em++ \
-s MODULARIZE \
-s EXPORT_NAME=createHarfBuzz \
-s [email protected] \
-s EXPORTED_RUNTIME_METHODS='["addFunction", "wasmMemory", "wasmExports"]' \
-s EXPORTED_RUNTIME_METHODS='["addFunction", "removeFunction", "wasmMemory", "wasmExports"]' \
-s INITIAL_MEMORY=65MB \
-s ALLOW_TABLE_GROWTH \
-lexports.js \
Expand Down
1 change: 1 addition & 0 deletions hb.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ _hb_font_set_scale
_hb_font_set_variations
_hb_font_draw_glyph
_hb_draw_funcs_create
_hb_draw_funcs_destroy
_hb_draw_funcs_set_move_to_func
_hb_draw_funcs_set_line_to_func
_hb_draw_funcs_set_quadratic_to_func
Expand Down
30 changes: 24 additions & 6 deletions hbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function hbjs(Module) {
var heapf32 = Module.HEAPF32;
var utf8Decoder = new TextDecoder("utf8");
let addFunction = Module.addFunction;
let removeFunction = Module.removeFunction;

var freeFuncPtr = addFunction(function (ptr) { exports.free(ptr); }, 'vi');

Expand Down Expand Up @@ -177,6 +178,11 @@ function hbjs(Module) {
function createFont(face) {
var ptr = exports.hb_font_create(face.ptr);
var drawFuncsPtr = null;
var moveToPtr = null;
var lineToPtr = null;
var cubicToPtr = null;
var quadToPtr = null;
var closePathPtr = null;

/**
* Return a glyph as an SVG path string.
Expand All @@ -200,11 +206,11 @@ function hbjs(Module) {
pathBuffer += 'Z';
}

var moveToPtr = addFunction(moveTo, 'viiiffi');
var lineToPtr = addFunction(lineTo, 'viiiffi');
var cubicToPtr = addFunction(cubicTo, 'viiiffffffi');
var quadToPtr = addFunction(quadTo, 'viiiffffi');
var closePathPtr = addFunction(closePath, 'viiii');
moveToPtr = addFunction(moveTo, 'viiiffi');
lineToPtr = addFunction(lineTo, 'viiiffi');
cubicToPtr = addFunction(cubicTo, 'viiiffffffi');
quadToPtr = addFunction(quadTo, 'viiiffffi');
closePathPtr = addFunction(closePath, 'viiii');
drawFuncsPtr = exports.hb_draw_funcs_create();
exports.hb_draw_funcs_set_move_to_func(drawFuncsPtr, moveToPtr, 0, 0);
exports.hb_draw_funcs_set_line_to_func(drawFuncsPtr, lineToPtr, 0, 0);
Expand Down Expand Up @@ -275,7 +281,18 @@ function hbjs(Module) {
/**
* Free the object.
*/
destroy: function () { exports.hb_font_destroy(ptr); }
destroy: function () {
exports.hb_font_destroy(ptr);
if (drawFuncsPtr) {
exports.hb_draw_funcs_destroy(drawFuncsPtr);
drawFuncsPtr = null;
removeFunction(moveToPtr);
removeFunction(lineToPtr);
removeFunction(cubicToPtr);
removeFunction(quadToPtr);
removeFunction(closePathPtr);
}
}
};
}

Expand Down Expand Up @@ -529,6 +546,7 @@ function hbjs(Module) {
exports.hb_buffer_set_message_func(buffer.ptr, traceFuncPtr, 0, 0);
shape(font, buffer, features, 0);
exports.free(traceBufPtr);
removeFunction(traceFuncPtr);

return trace;
}
Expand Down
Loading
Loading