From 0ba3ae14a4cc8ea72041fba1ea46d8eadf9a437f Mon Sep 17 00:00:00 2001 From: Eugene Date: Fri, 2 Aug 2024 11:39:00 +0100 Subject: [PATCH] refactor: moves font size and type to a constant --- src/utils/pdf.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/utils/pdf.ts b/src/utils/pdf.ts index f2da806..70b6539 100644 --- a/src/utils/pdf.ts +++ b/src/utils/pdf.ts @@ -10,6 +10,18 @@ PDFJS.GlobalWorkerOptions.workerSrc = 'node_modules/pdfjs-dist/build/pdf.worker. * @constant {number} */ const SCALE: number = 3; +/** + * Defined font size used when generating a PDF. Currently it is difficult to fully + * correlate font size used at the time of filling in / drawing on the PDF + * because it is dynamically rendered, and the final size. + * This should be fixed going forward. + * Switching to PDF-Lib will most likely make this problem redundant. + */ +const FONT_SIZE: number = 40; +/** + * Current font type used when generating a PDF. + */ +const FONT_TYPE: string = 'Arial'; /** * Converts a PDF ArrayBuffer to a generic PDF File @@ -162,7 +174,8 @@ const hasValue = (mark: Mark): boolean => !!mark.value; */ const draw = (mark: Mark, ctx: CanvasRenderingContext2D) => { const { location } = mark; - ctx!.font = '20px Arial'; + + ctx!.font = FONT_SIZE + 'px ' + FONT_TYPE; ctx!.fillStyle = 'black'; const textMetrics = ctx!.measureText(mark.value!); const textX = location.left + (location.width - textMetrics.width) / 2;