Add text fit safety margin

This commit is contained in:
Mikei386
2026-06-22 16:35:26 +02:00
parent 7243250abc
commit 1c2b2df3a0
2 changed files with 42 additions and 2 deletions
+2 -1
View File
@@ -8,6 +8,7 @@ const PRINTABLE_TAPE_PX = {
24: 128,
};
const STORAGE_KEY = "ptouch-web-layout";
const TEXT_FIT_EXTRA_MM = 6;
const state = {
zoom: 1.5,
@@ -113,7 +114,7 @@ function textNaturalWidthMm(obj) {
const lines = String(obj.text || " ").split("\n");
const maxTextWidthPx = Math.max(...lines.map((line) => ctx.measureText(line || " ").width), 0);
ctx.restore();
return Math.max(2, pxToMm(maxTextWidthPx) + 1);
return Math.max(2, pxToMm(maxTextWidthPx) + TEXT_FIT_EXTRA_MM);
}
function autoFitTextObject(obj) {