diff --git a/examples/image.ts b/examples/image.ts index 6661872..1be9ee3 100644 --- a/examples/image.ts +++ b/examples/image.ts @@ -10,6 +10,9 @@ ctx.fillRect(10, 10, 200 - 20, 200 - 20); const img = await loadImage("https://cdn.discordapp.com/emojis/587737413330272291.gif?v=1"); ctx.drawImage(img, 100 - img.width() / 2, 100 - img.height() / 2); +ctx.font = '30px Impact' +console.log(ctx.measureText('3'), (ctx as any).gg.getGlyphBounds('3')); + const server = serve({ hostname: "0.0.0.0", port: 8080 }); console.log(`HTTP webserver running. Access it at: http://localhost:8080/`); diff --git a/lib.js b/lib.js index 8e6e14b..0a9f24d 100644 --- a/lib.js +++ b/lib.js @@ -2822,7 +2822,7 @@ export const CanvasKitInit = (function () { }, [], ); - let actualBoundingBoxAscent = ((glyphBounds.map(e => e[1]).reduce((p, a) => p + a, 0)) * -1) / glyphBounds.length; + let actualBoundingBoxAscent = (Math.abs(glyphBounds.map(e => e[1]).reduce((p, a) => p + a, 0))) / glyphBounds.length; return { width, actualBoundingBoxAscent, @@ -6919,9 +6919,13 @@ export const CanvasKitInit = (function () { a(h.instance); } function c(h) { - return Hb().then(function (m) { + return Promise.resolve().then(function (m) { return new Promise((res) => - res(new WebAssembly.Instance(wasmMod, d)) + { + const inst = new WebAssembly.Instance(wasmMod, d); + storeWasm = inst; + return res(inst); + } ); }).then(h, function (m) { Ka("failed to asynchronously prepare wasm: " + m);