Skip to content

Commit

Permalink
Include cex parameters when calculating font size in canvas graphic…
Browse files Browse the repository at this point in the history
…s device (#369)

* Include cex in canvas device font size calculation

* Update NEWS.md
  • Loading branch information
georgestagg authored Feb 28, 2024
1 parent a9396fe commit 78c5c6a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

* Fixed spelling errors in some JavaScript errors thrown by webR.

* Include `cex` parameters when calculating font size in canvas graphics device (#348).

# webR 0.2.2

## New features
Expand Down
4 changes: 2 additions & 2 deletions packages/webr/src/canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void canvasMetricInfo(int c, const pGEcontext gc, double* ascent,
const ffamily = (f) => fsans.includes(f) ? "sans-serif" : f;
const font = `${fface[$2]} ${$0}px ${ffamily(UTF8ToString($1))}`;
Module.canvasCtx.font = font;
}, 2*gc->ps, gc->fontfamily, gc->fontface);
}, 2 * gc->cex * gc->ps, gc->fontfamily, gc->fontface);

*ascent = EM_ASM_DOUBLE({
return Module.canvasCtx.measureText(
Expand Down Expand Up @@ -486,7 +486,7 @@ static double canvasStrWidth(const char *str, const pGEcontext gc, pDevDesc RGD)
const font = `${fface[$2]} ${$0}px ${ffamily(UTF8ToString($1))}`;
Module.canvasCtx.font = font;
return Module.canvasCtx.measureText(UTF8ToString($3)).width;
}, 2*gc->ps, gc->fontfamily, gc->fontface, str) / 2.0;
}, 2 * gc->cex * gc->ps, gc->fontfamily, gc->fontface, str) / 2.0;
}

void canvasText(double x, double y, const char *str, double rot, double hadj,
Expand Down

0 comments on commit 78c5c6a

Please sign in to comment.