mirror of
https://github.com/NaitLee/Cat-Printer.git
synced 2025-05-31 14:40:12 -07:00
+ Added comments to getMaxCharsPerLine and wrapText
+ Added German and English strings for text-size and text-font
This commit is contained in:
parent
8f402eb80f
commit
7afe68c151
@ -43,6 +43,8 @@
|
|||||||
"coming-soon": "Demnächst verfügbar…",
|
"coming-soon": "Demnächst verfügbar…",
|
||||||
"dry-run": "Testlauf",
|
"dry-run": "Testlauf",
|
||||||
"dry-run-test-print-process-only": "Testlauf: nur Probedruckvorgang",
|
"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",
|
"you-can-close-this-page-manually": "Sie können diese Seite manuell schließen",
|
||||||
"please-enable-bluetooth": "Bitte aktivieren Sie Bluetooth",
|
"please-enable-bluetooth": "Bitte aktivieren Sie Bluetooth",
|
||||||
"error-happened-please-check-error-message": "Fehler aufgetreten, bitte Fehlermeldung einsehen",
|
"error-happened-please-check-error-message": "Fehler aufgetreten, bitte Fehlermeldung einsehen",
|
||||||
|
@ -42,6 +42,8 @@
|
|||||||
"coming-soon": "Coming Soon…",
|
"coming-soon": "Coming Soon…",
|
||||||
"dry-run": "Dry Run",
|
"dry-run": "Dry Run",
|
||||||
"dry-run-test-print-process-only": "Dry Run: test print process only",
|
"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",
|
"you-can-close-this-page-manually": "You can close this page manually",
|
||||||
"please-enable-bluetooth": "Please enable Bluetooth",
|
"please-enable-bluetooth": "Please enable Bluetooth",
|
||||||
"error-happened-please-check-error-message": "Error happened, please check error message",
|
"error-happened-please-check-error-message": "Error happened, please check error message",
|
||||||
|
@ -455,6 +455,8 @@ class CanvasController {
|
|||||||
|
|
||||||
// Use Word Wrap to split the text over multiple lines
|
// Use Word Wrap to split the text over multiple lines
|
||||||
let lines = [];
|
let lines = [];
|
||||||
|
// Calculate the aproximate maximum length of a string
|
||||||
|
// taking font and text size in account
|
||||||
const getMaxCharsPerLine = (text, ctx) => {
|
const getMaxCharsPerLine = (text, ctx) => {
|
||||||
let textWidth = ctx.measureText(text).width;
|
let textWidth = ctx.measureText(text).width;
|
||||||
let textIndex = maxWidth / textWidth;
|
let textIndex = maxWidth / textWidth;
|
||||||
@ -462,6 +464,8 @@ class CanvasController {
|
|||||||
if (textIndex > 1) { return text.length}
|
if (textIndex > 1) { return text.length}
|
||||||
return Math.floor(textIndex * text.length);
|
return Math.floor(textIndex * text.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wrap the text if it does not fit on a single line
|
||||||
const wrapText = (text, maxLength) => {
|
const wrapText = (text, maxLength) => {
|
||||||
let splitPos = maxLength - 1;
|
let splitPos = maxLength - 1;
|
||||||
while (text[splitPos] != " " && splitPos > 0) {
|
while (text[splitPos] != " " && splitPos > 0) {
|
||||||
@ -478,7 +482,6 @@ class CanvasController {
|
|||||||
}
|
}
|
||||||
lines.push(text)
|
lines.push(text)
|
||||||
|
|
||||||
|
|
||||||
let yPos = yStep;
|
let yPos = yStep;
|
||||||
for (let line of lines) {
|
for (let line of lines) {
|
||||||
ctx.fillText(line, 0, yPos);
|
ctx.fillText(line, 0, yPos);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user