Postkarte: kein falscher „Text zu lang"-Fehler mehr
All checks were successful
Build & Deploy / deploy (push) Successful in 10s
All checks were successful
Build & Deploy / deploy (push) Successful in 10s
- Überlauf nur noch am Brieftext messen (echte lineCount/lineLimit statt 0/0) – behebt die Meldung „1 Zeile zu lang – 0 statt max. 0". - Empfänger-Adresse wird automatisch verkleinert, wenn sie nicht ins sichere Adressfeld passt → Codierzone bleibt immer frei, keine Blockade der Vorschau. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -476,6 +476,8 @@ function generatePostcardSVG(text, format, options = {}) {
|
|||||||
const trennXmm = (textLowerRightMm + addrLeftMm) / 2; // A6: 84
|
const trennXmm = (textLowerRightMm + addrLeftMm) / 2; // A6: 84
|
||||||
|
|
||||||
const paths = [];
|
const paths = [];
|
||||||
|
let bodyLineCount = 0;
|
||||||
|
let bodyLineLimit = 1;
|
||||||
let overflow = false;
|
let overflow = false;
|
||||||
|
|
||||||
// Variabler (L-förmiger) Textfluss: oben schmal (bis Frankierzone), unten breit.
|
// Variabler (L-förmiger) Textfluss: oben schmal (bis Frankierzone), unten breit.
|
||||||
@@ -500,12 +502,13 @@ function generatePostcardSVG(text, format, options = {}) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Text links (L-förmig).
|
// Text links (L-förmig). Nur DER Text kann „zu lang" sein (Nutzer kürzt ihn).
|
||||||
if (body) {
|
|
||||||
const baseline0 = mmToPx(14) + fontSizePx;
|
const baseline0 = mmToPx(14) + fontSizePx;
|
||||||
|
bodyLineLimit = Math.max(1, Math.floor((mmToPx(maxYmm) - baseline0) / lineHeightPx) + 1);
|
||||||
|
if (body) {
|
||||||
const bodyLines = flowVariabel(body, fontSizePx, baseline0, lineHeightPx);
|
const bodyLines = flowVariabel(body, fontSizePx, baseline0, lineHeightPx);
|
||||||
const letzteBaseline = baseline0 + Math.max(0, bodyLines.length - 1) * lineHeightPx;
|
bodyLineCount = bodyLines.length;
|
||||||
if (letzteBaseline > mmToPx(maxYmm)) overflow = true;
|
if (bodyLineCount > bodyLineLimit) overflow = true;
|
||||||
paths.push(...layoutTextToPaths({
|
paths.push(...layoutTextToPaths({
|
||||||
lines: bodyLines, fontFileName: fontFile, fontSizePx,
|
lines: bodyLines, fontFileName: fontFile, fontSizePx,
|
||||||
startX: mmToPx(textLeftMm), startY: baseline0, lineHeightPx, realisticHandwriting: realistic,
|
startX: mmToPx(textLeftMm), startY: baseline0, lineHeightPx, realisticHandwriting: realistic,
|
||||||
@@ -523,14 +526,26 @@ function generatePostcardSVG(text, format, options = {}) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empfänger im sicheren Adressfeld (rechts unten).
|
// Empfänger im sicheren Adressfeld (rechts unten). Passt der Block nicht in die
|
||||||
|
// 46 mm hohe Zone, wird die Schrift automatisch verkleinert – so bleibt die
|
||||||
|
// Codierzone (unten) IMMER frei und es gibt keinen „Adresse zu lang"-Fehler.
|
||||||
if (recipient) {
|
if (recipient) {
|
||||||
const recLines = wrapTextToLinesByWidth({ text: recipient, maxWidthPx: mmToPx(addrRightMm - addrLeftMm), fontFileName: fontFile, fontSizePx });
|
const feldOben = mmToPx(addrTopMm);
|
||||||
const recBaseline0 = mmToPx(addrTopMm) + fontSizePx;
|
const feldUnten = mmToPx(maxYmm);
|
||||||
if (recBaseline0 + Math.max(0, recLines.length - 1) * lineHeightPx > mmToPx(maxYmm)) overflow = true;
|
const feldBreite = mmToPx(addrRightMm - addrLeftMm);
|
||||||
|
let recSize = fontSizePx;
|
||||||
|
let recLH = lineHeightPx;
|
||||||
|
let recLines = [];
|
||||||
|
for (const scale of [1, 0.9, 0.8, 0.72, 0.65, 0.6]) {
|
||||||
|
recSize = fontSizePx * scale;
|
||||||
|
recLH = lineHeightPx * scale;
|
||||||
|
recLines = wrapTextToLinesByWidth({ text: recipient, maxWidthPx: feldBreite, fontFileName: fontFile, fontSizePx: recSize });
|
||||||
|
const blockUnten = feldOben + recSize + Math.max(0, recLines.length - 1) * recLH + recSize * 0.3;
|
||||||
|
if (blockUnten <= feldUnten) break;
|
||||||
|
}
|
||||||
paths.push(...layoutTextToPaths({
|
paths.push(...layoutTextToPaths({
|
||||||
lines: recLines, fontFileName: fontFile, fontSizePx,
|
lines: recLines, fontFileName: fontFile, fontSizePx: recSize,
|
||||||
startX: mmToPx(addrLeftMm), startY: recBaseline0, lineHeightPx, realisticHandwriting: realistic,
|
startX: mmToPx(addrLeftMm), startY: feldOben + recSize, lineHeightPx: recLH, realisticHandwriting: realistic,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,7 +573,7 @@ function generatePostcardSVG(text, format, options = {}) {
|
|||||||
${pathElements}
|
${pathElements}
|
||||||
</svg>`;
|
</svg>`;
|
||||||
|
|
||||||
return { svg: svg.trim(), overflow, lineCount: 0, lineLimit: 0 };
|
return { svg: svg.trim(), overflow, lineCount: bodyLineCount, lineLimit: bodyLineLimit };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user