diff --git a/www/lang/de-DE.json b/www/lang/de-DE.json index b7f14eb..2e9862d 100644 --- a/www/lang/de-DE.json +++ b/www/lang/de-DE.json @@ -43,6 +43,8 @@ "coming-soon": "Demnächst verfügbar…", "dry-run": "Testlauf", "dry-run-test-print-process-only": "Testlauf: nur Probedruckvorgang", + "text-font": "Schriftart", + "text-size": "Textgröße", "you-can-close-this-page-manually": "Sie können diese Seite manuell schließen", "please-enable-bluetooth": "Bitte aktivieren Sie Bluetooth", "error-happened-please-check-error-message": "Fehler aufgetreten, bitte Fehlermeldung einsehen", diff --git a/www/lang/en-US.json b/www/lang/en-US.json index 88cac2a..2d50641 100644 --- a/www/lang/en-US.json +++ b/www/lang/en-US.json @@ -42,6 +42,8 @@ "coming-soon": "Coming Soon…", "dry-run": "Dry Run", "dry-run-test-print-process-only": "Dry Run: test print process only", + "text-font": "Font", + "text-size": "Text size", "you-can-close-this-page-manually": "You can close this page manually", "please-enable-bluetooth": "Please enable Bluetooth", "error-happened-please-check-error-message": "Error happened, please check error message", diff --git a/www/main.js b/www/main.js index c589b96..c6c41e3 100644 --- a/www/main.js +++ b/www/main.js @@ -455,13 +455,17 @@ class CanvasController { // Use Word Wrap to split the text over multiple lines let lines = []; - const getMaxCharsPerLine = (text, ctx) => { + // Calculate the aproximate maximum length of a string + // taking font and text size in account + const getMaxCharsPerLine = (text, ctx) => { let textWidth = ctx.measureText(text).width; let textIndex = maxWidth / textWidth; if (textIndex > 1) { return text.length} return Math.floor(textIndex * text.length); } + + // Wrap the text if it does not fit on a single line const wrapText = (text, maxLength) => { let splitPos = maxLength - 1; while (text[splitPos] != " " && splitPos > 0) { @@ -470,7 +474,7 @@ class CanvasController { if (splitPos == 0) { splitPos = maxLength; } return [text.slice(0, splitPos).trim(), text.slice(splitPos, text.length).trim()]; } - + while (ctx.measureText(text).width > maxWidth) { let line; [line, text] = wrapText(text, getMaxCharsPerLine(text, ctx)); @@ -478,7 +482,6 @@ class CanvasController { } lines.push(text) - let yPos = yStep; for (let line of lines) { ctx.fillText(line, 0, yPos);