-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create framework for compatability API * Add missing file * Simplify type conversion * Remove uneeded file
- Loading branch information
Showing
6 changed files
with
50 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ mj_sre | |
dev | ||
wasm | ||
*~ | ||
.vscode | ||
.vscode | ||
.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* This is the API used by PreFigure when running in the browser. It implements the necessary | ||
* functions for Prefigure's abstract classes. | ||
*/ | ||
export class PrefigBrowserApi { | ||
offscreenCanvas: OffscreenCanvas | null = null; | ||
ctx: OffscreenCanvasRenderingContext2D | null = null; | ||
measure_text(text: string, _font_data?: unknown) { | ||
if (!this.offscreenCanvas) { | ||
this.offscreenCanvas = new OffscreenCanvas(200, 200); | ||
} | ||
if (!this.ctx) { | ||
this.ctx = this.offscreenCanvas.getContext("2d"); | ||
if (!this.ctx) { | ||
throw new Error("Failed to create canvas context"); | ||
} | ||
} | ||
// XXX replace this with proper data from `font_data` | ||
this.ctx.font = "14px sans"; | ||
|
||
const tm = this.ctx.measureText(text); | ||
console.log("Measured text", text, tm); | ||
return [ | ||
tm.width, | ||
tm.actualBoundingBoxAscent, | ||
tm.actualBoundingBoxDescent, | ||
]; | ||
} | ||
} | ||
|
||
export const prefigBrowserApi = new PrefigBrowserApi(); | ||
|
||
(globalThis as any).prefigBrowserApi = prefigBrowserApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.