From 78c5c6ac306e79a474bb014a7f27334199918c79 Mon Sep 17 00:00:00 2001 From: George Stagg Date: Wed, 28 Feb 2024 08:54:25 +0000 Subject: [PATCH] Include `cex` parameters when calculating font size in canvas graphics device (#369) * Include cex in canvas device font size calculation * Update NEWS.md --- NEWS.md | 2 ++ packages/webr/src/canvas.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index dd076c47..674b8e0b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/packages/webr/src/canvas.c b/packages/webr/src/canvas.c index 7fde7dcc..ffe58711 100644 --- a/packages/webr/src/canvas.c +++ b/packages/webr/src/canvas.c @@ -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( @@ -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,