Skip to content

Commit

Permalink
Add CanvasRenderingContext2D#font getter
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Nov 9, 2023
1 parent cd8557b commit e81ae48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-brooms-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nxjs-runtime': patch
---

Add `CanvasRenderingContext2D#font` getter
11 changes: 8 additions & 3 deletions packages/runtime/src/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface CanvasRenderingContext2DInternal {
fillStyle: RGBA;
strokeStyle: RGBA;
currentStyle?: RGBA;
font: string;
}

const ctxInternalMap = new WeakMap<
Expand Down Expand Up @@ -86,6 +87,7 @@ export class CanvasRenderingContext2D {
ctx: Switch.native.canvasNewContext(w, h),
strokeStyle: [0, 0, 0, 1],
fillStyle: [0, 0, 0, 1],
font: ''
});
this.font = '10px system-ui';

Expand Down Expand Up @@ -644,12 +646,14 @@ export class CanvasRenderingContext2D {
}

get font(): string {
// TODO: implement
return '';
return internal(this).font;
}

set font(v: string) {
if (!v) return;
const i = internal(this);
if (i.font === v) return;

const parsed = parseCssFont(v);
if ('system' in parsed) {
// "system" fonts are not supported
Expand Down Expand Up @@ -677,8 +681,9 @@ export class CanvasRenderingContext2D {
return;
}
}
i.font = v;
native.canvasSetFont(
internal(this).ctx,
i.ctx,
fontFaceInternal.get(font)!.fontFace,
px
);
Expand Down

0 comments on commit e81ae48

Please sign in to comment.