7 Commits

Author SHA1 Message Date
s4luorth
d5a051befc Signatur: Leerzeilen an der Marker-Grenze nicht mehr rendern
All checks were successful
Build & Deploy / deploy (push) Successful in 11s
Die \n\n um [[signatur1]] erzeugten zusaetzliche Leerzeilen (grosse Luecken
trotz Abstand 0). Textsegmente werden an der Signatur-Grenze getrimmt; der
vertikale Platz haengt jetzt nur noch am (regelbaren) Abstand.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-01 11:04:57 +02:00
s4luorth
17eebcfe6a Signatur: kompakter + Abstand pro Signatur regelbar
All checks were successful
Build & Deploy / deploy (push) Successful in 15s
Signatur reserviert nur noch die tatsaechlich gerenderte Hoehe statt fix 2
Zeilen; Standard-Abstand = halber Zeilenabstand, pro Signatur ueber
signature_offsets[key].spacing (mm) ueberschreibbar. Zielhoehe kompakter (~1,2
statt 2 Zeilen).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-01 10:36:08 +02:00
s4luorth
9984b822aa A5-Greifrand an die KURZE Seite
All checks were successful
Build & Deploy / deploy (push) Successful in 10s
A5 hoch (a5p) unten, A5 quer (a5l) rechts - A5 wird an der kurzen (148 mm)
Seite gegriffen. A6 und DIN lang bleiben an der langen Seite.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-30 11:43:27 +02:00
s4luorth
29021281bb Greifrand auch fuer A5 + DIN lang (lange Seite)
All checks were successful
Build & Deploy / deploy (push) Successful in 11s
A5 hoch (a5p) rechts, A5 quer (a5l) + DIN lang (dinlang_karte) unten - analog
A6. Gleicher margin_right/margin_bottom-Mechanismus, Zeilen werden geometrisch
gedeckelt.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-30 11:41:55 +02:00
s4luorth
a882bf37f5 C4-Kuvert (quer) als Render-Format
All checks were successful
Build & Deploy / deploy (push) Successful in 11s
Neues Umschlag-Format c4 (324x229 mm, Querformat-Beschriftung, maschinenseitig
quer eingelegt) in den Backend-Defaults + ENVELOPE_FORMAT-Map. Absender oben
links, Empfaenger unten rechts (bestehende Kuvert-Logik, proportional).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-30 11:31:25 +02:00
s4luorth
7930c177ee A6-Greifrand an die lange Seite + A5/DIN-lang (Volltext)
All checks were successful
Build & Deploy / deploy (push) Successful in 15s
A6: Greifrand liegt jetzt IMMER an der langen (148mm) Seite - A6 quer (a6l)
unten (neuer margin_bottom-Mechanismus haelt untere Zeilen frei, 11->10),
A6 hoch (a6p) rechts. Neue Funktion getEffectiveLineLimit() deckelt das
Zeilenlimit zusaetzlich geometrisch; A4/A5 unberuehrt.

A5 (a5p 148x210, a5l 210x148) und DIN lang komplett beschrieben
(dinlang_karte 210x105) als Brief-Fallback-Formate ergaenzt.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-30 10:53:19 +02:00
s4luorth
c73109b8ca FTP: Passwort base64-sicher via SKRIFT_FTP_PASSWORD_B64
All checks were successful
Build & Deploy / deploy (push) Successful in 9s
Passwoerter mit Sonderzeichen ($ # @) werden in .env-Dateien verstuemmelt
(bestaetigt durch falsche pw_len -> 530 Login incorrect). Neue Variable
SKRIFT_FTP_PASSWORD_B64 nimmt den base64-kodierten Wert (env-sicher) und
wird dekodiert; hat Vorrang vor SKRIFT_FTP_PASSWORD.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-28 11:33:33 +02:00
4 changed files with 74 additions and 21 deletions

View File

@@ -17,7 +17,7 @@ const { replacePlaceholders } = require('../../services/placeholder-service');
// Directus-Formatschlüssel → Backend-Formate
const LETTER_FORMAT = { a4: 'a4', a6_hoch: 'a6p', a6_quer: 'a6l' };
const ENVELOPE_FORMAT = { c6: 'c6', dinlang: 'din_lang' };
const ENVELOPE_FORMAT = { c6: 'c6', dinlang: 'din_lang', c4: 'c4' };
/** Baut den Adressblock für einen Umschlag aus einer Empfängerzeile. */
function addressText(entry) {

View File

@@ -64,11 +64,16 @@ module.exports = {
// Login incorrect" führen, obwohl die Daten korrekt sind.
ftp: (() => {
const envClean = (v) => String(v || '').replace(/[\r\n]+/g, '').replace(/^(['"])([\s\S]*)\1$/, '$2');
// Passwoerter mit Sonderzeichen ($ # @ …) werden in .env-Dateien oft
// verstuemmelt ($ = Variable, # = Kommentar). Deshalb bevorzugt base64:
// SKRIFT_FTP_PASSWORD_B64 wird dekodiert und ist damit env-sicher.
const pwB64 = envClean(process.env.SKRIFT_FTP_PASSWORD_B64);
const password = pwB64 ? Buffer.from(pwB64, 'base64').toString('utf8') : envClean(process.env.SKRIFT_FTP_PASSWORD);
return {
host: envClean(process.env.SKRIFT_FTP_HOST),
port: parseInt(process.env.SKRIFT_FTP_PORT, 10) || 21,
user: envClean(process.env.SKRIFT_FTP_USER),
password: envClean(process.env.SKRIFT_FTP_PASSWORD),
password,
// explizites FTP über TLS (wie im FTP-Client eingestellt). 'false' schaltet ab.
secure: String(process.env.SKRIFT_FTP_SECURE || 'true').toLowerCase() !== 'false',
// Selbstsigniertes Zertifikat zulassen (viele FTP-Server) – auf 'false' setzen für strikte Prüfung.

View File

@@ -6,23 +6,37 @@ const FONT_SIZE_PX = 26;
// im Speicher gehalten (stündlich / manuell aufgefrischt via applyRenderFormats).
// Ist Directus nicht erreichbar oder ein Format nicht hinterlegt, greifen die
// eingebauten Defaults – die Generierung läuft also immer.
const DEFAULT_LINE_LIMITS = { a4: 27, a6p: 14, a6l: 11 };
const DEFAULT_LINE_LIMITS = { a4: 27, a5p: 19, a5l: 13, a6p: 14, a6l: 11, dinlang_karte: 11 };
const DEFAULT_FORMAT_LAYOUTS = {
a4: { marginTopMm: 25, marginLeftMm: 20, lineHeightFactor: 1.35 },
a6p: { marginTopMm: 8, marginLeftMm: 8, lineHeightFactor: 1.3 },
a6l: { marginTopMm: 8, marginLeftMm: 8, marginRightMm: 14, lineHeightFactor: 1.2 },
// A5 greift an der KURZEN (148 mm) Seite: hoch → unten, quer → rechts.
a5p: { marginTopMm: 20, marginLeftMm: 15, marginBottomMm: 14, lineHeightFactor: 1.35 },
a5l: { marginTopMm: 20, marginLeftMm: 15, marginRightMm: 14, lineHeightFactor: 1.35 },
// DIN lang greift an der langen (210 mm) Seite → unten.
dinlang_karte: { marginTopMm: 8, marginLeftMm: 10, marginBottomMm: 14, lineHeightFactor: 1.2 },
// A6-Greifrand IMMER an der langen (148 mm) Seite:
// • a6p (hoch, 105×148): lange Seite = rechts → marginRightMm (Breite)
// • a6l (quer, 148×105): lange Seite = unten → marginBottomMm (Zeilen)
a6p: { marginTopMm: 8, marginLeftMm: 8, marginRightMm: 14, lineHeightFactor: 1.3 },
a6l: { marginTopMm: 8, marginLeftMm: 8, marginBottomMm: 14, lineHeightFactor: 1.2 },
din_lang: { marginTopMm: 50, marginLeftMm: 10, lineHeightFactor: 1.2 },
c6: { marginTopMm: 60, marginLeftMm: 10, lineHeightFactor: 1.2 },
// C4 quer (Querformat-Beschriftung, maschinenseitig quer eingelegt).
c4: { marginTopMm: 70, marginLeftMm: 20, lineHeightFactor: 1.2 },
};
const DEFAULT_PAGE_FORMATS = {
a4: { widthMm: 210, heightMm: 297 },
a5p: { widthMm: 148, heightMm: 210 },
a5l: { widthMm: 210, heightMm: 148 },
dinlang_karte: { widthMm: 210, heightMm: 105 },
a6p: { widthMm: 105, heightMm: 148 },
a6l: { widthMm: 148, heightMm: 105 },
din_lang: { widthMm: 220, heightMm: 110 },
c6: { widthMm: 162, heightMm: 114 },
c4: { widthMm: 324, heightMm: 229 },
};
// Art des Formats (brief/umschlag/postkarte) – steuert, WAS generiert wird.
const DEFAULT_KINDS = { a4: 'brief', a6p: 'brief', a6l: 'brief', din_lang: 'umschlag', c6: 'umschlag' };
const DEFAULT_KINDS = { a4: 'brief', a5p: 'brief', a5l: 'brief', a6p: 'brief', a6l: 'brief', dinlang_karte: 'brief', din_lang: 'umschlag', c6: 'umschlag', c4: 'umschlag' };
// Live-Cache (wird von applyRenderFormats ersetzt). Start = Defaults.
let LINE_LIMITS = { ...DEFAULT_LINE_LIMITS };
@@ -56,6 +70,8 @@ function applyRenderFormats(rows) {
};
const mr = r.margin_right_mm ?? alt.marginRightMm;
if (mr != null && mr !== '') layout.marginRightMm = Number(mr);
const mb = r.margin_bottom_mm ?? alt.marginBottomMm;
if (mb != null && mb !== '') layout.marginBottomMm = Number(mb);
fl[k] = layout;
if (r.line_limit != null && r.line_limit !== '') ll[k] = Number(r.line_limit);
}
@@ -110,6 +126,7 @@ function getLayoutForFormat(format) {
marginTopPx: mmToPx(layoutConfig.marginTopMm),
marginLeftPx: mmToPx(layoutConfig.marginLeftMm),
marginRightPx: layoutConfig.marginRightMm ? mmToPx(layoutConfig.marginRightMm) : null,
marginBottomPx: layoutConfig.marginBottomMm ? mmToPx(layoutConfig.marginBottomMm) : 0,
lineHeightPx: FONT_SIZE_PX * layoutConfig.lineHeightFactor,
};
}
@@ -143,6 +160,21 @@ function getLineLimit(format) {
return LINE_LIMITS[normalizedFormat] || LINE_LIMITS.a4;
}
// Effektives Zeilenlimit: das kleinere aus (a) konfiguriertem line_limit,
// gegenläufig zur Schriftgröße skaliert, und (b) geometrischer Kapazität, die
// einen unteren Greifrand (marginBottomMm) frei hält. Dadurch reserviert A6 quer
// (marginBottomMm=14) unten Freiraum für den rollengeführten Plotter, ohne dass
// die anderen Formate (ohne Bottom-Rand) berührt werden.
function getEffectiveLineLimit(format, fontScale = 1) {
const fs = Math.max(0.8, Math.min(1.5, Number(fontScale) || 1));
const konfiguriert = Math.max(1, Math.round(getLineLimit(format) / fs));
const { heightPx } = getPageDimensions(format);
const { marginTopPx, marginBottomPx, lineHeightPx } = getLayoutForFormat(format);
const nutzbarPx = heightPx - marginTopPx - (marginBottomPx || 0);
const geo = Math.max(1, Math.floor(nutzbarPx / (lineHeightPx * fs)));
return Math.min(konfiguriert, geo);
}
module.exports = {
PX_PER_MM,
FONT_SIZE_PX,
@@ -150,6 +182,7 @@ module.exports = {
getLayoutForFormat,
getPageDimensions,
getLineLimit,
getEffectiveLineLimit,
getFormatKind,
escapeXml,
applyRenderFormats,

View File

@@ -2,7 +2,7 @@ const {
FONT_SIZE_PX,
getLayoutForFormat,
getPageDimensions,
getLineLimit,
getEffectiveLineLimit,
escapeXml,
mmToPx
} = require('./page-layout');
@@ -140,7 +140,7 @@ function generateLetterSVG(text, format, options = {}) {
.join('\n ');
// Größere Schrift → weniger Zeilen passen aufs Blatt (Limit gegenläufig skalieren).
const lineLimit = Math.max(1, Math.round(getLineLimit(format) / fontScale));
const lineLimit = getEffectiveLineLimit(format, fontScale);
return {
svg: `<svg xmlns="http://www.w3.org/2000/svg"
width="${widthMm}mm" height="${heightMm}mm"
@@ -156,12 +156,13 @@ function generateLetterSVG(text, format, options = {}) {
// ── Pfad mit Signaturen: Text in Segmente aufteilen ───────────────────────
// Jede Signatur-Zeile ist 2 Zeilen hoch; bis zu 3 Signaturen nebeneinander.
const sigHeightPx = 2 * lineHeightPx;
// Signatur-Größe: kompakte Zielhöhe (~1,2 Zeilen statt fix 2) ODER schmaler Slot –
// gleichmäßig skalieren. Über signatureOffsets[key].scale je Signatur anpassbar.
const sigSlotW = maxWidthPx / 3; // Breite pro Signatur-Slot
const sigScaleH = sigHeightPx / SIG_CANVAS_H;
const sigScaleW = sigSlotW / SIG_CANVAS_W;
const sigScale = Math.min(sigScaleH, sigScaleW); // gleichmäßig skalieren
const sigPaddingPx = lineHeightPx * 0.3; // kleiner Abstand ober/unterhalb
const sigScale = Math.min((lineHeightPx * 1.2) / SIG_CANVAS_H, sigSlotW / SIG_CANVAS_W);
// Standard-Abstand ober-/unterhalb der Signatur = halber Zeilenabstand.
// Pro Signatur über signatureOffsets[key].spacing (mm) überschreibbar.
const defaultSpacingPx = lineHeightPx * 0.5;
const rawText = String(text || '');
const segments = [];
@@ -182,17 +183,19 @@ function generateLetterSVG(text, format, options = {}) {
const allSvgElements = [];
let currentY = marginTopPx + fontSizePx;
let totalLineCount = 0;
const lineLimit = Math.max(1, Math.round(getLineLimit(format) / fontScale));
const lineLimit = getEffectiveLineLimit(format, fontScale);
let si = 0;
while (si < segments.length) {
const seg = segments[si];
if (seg.type === 'text') {
// Leerzeilen direkt an der Signatur-Grenze entfernen – sonst „fressen" die
// \n\n um [[signatur1]] zusätzlichen Platz. Abstand regelt NUR das spacing.
const trimmed = seg.content.replace(/^\n+/, '').replace(/\n+$/, '');
if (!trimmed) { si++; continue; }
const lines = wrapTextToLinesByWidth({
text: seg.content,
text: trimmed,
maxWidthPx,
fontFileName: fontConfig.file,
fontSizePx,
@@ -217,13 +220,25 @@ function generateLetterSVG(text, format, options = {}) {
totalLineCount += lines.length;
si++;
} else {
// Aufeinanderfolgende Signaturen als Zeile nebeneinander rendern
// Aufeinanderfolgende Signaturen als Zeile nebeneinander rendern.
const sigRow = [];
while (si < segments.length && segments[si].type === 'sig') {
sigRow.push(segments[si]);
si++;
}
currentY += sigPaddingPx;
// Tatsächlich gerenderte Höhe der Zeile + individueller Abstand je Signatur
// (Default halber Zeilenabstand). So wird nur der real benötigte Platz
// reserviert statt fix 2 Zeilen – Signaturen „fressen" keinen Platz mehr.
let rowHeightPx = 0;
let spacingPx = defaultSpacingPx;
for (const sigSeg of sigRow) {
const off = signatureOffsets[sigSeg.key] || {};
const sc = Number(off.scale) > 0 ? Number(off.scale) : 1;
if (signatures[sigSeg.key]) rowHeightPx = Math.max(rowHeightPx, SIG_CANVAS_H * sigScale * sc);
if (off.spacing != null && off.spacing !== '') spacingPx = Math.max(0, mmToPx(Number(off.spacing)));
}
if (rowHeightPx <= 0) rowHeightPx = lineHeightPx; // keine SVG → eine Platzhalterzeile
currentY += spacingPx;
sigRow.forEach((sigSeg, slotIdx) => {
const svgString = signatures[sigSeg.key] || null;
if (svgString) {
@@ -237,8 +252,8 @@ function generateLetterSVG(text, format, options = {}) {
if (sigEl) allSvgElements.push(sigEl);
}
});
currentY += sigHeightPx + sigPaddingPx;
totalLineCount += 2; // ganze Zeile zählt als 2 Zeilen, unabhängig von Anzahl
currentY += rowHeightPx + spacingPx;
totalLineCount += Math.max(1, Math.ceil((2 * spacingPx + rowHeightPx) / lineHeightPx));
}
}
@@ -606,7 +621,7 @@ function generateLetterPages(text, format, options = {}) {
const fontScale = Math.max(0.8, Math.min(1.5, Number(options.fontScale) || 1));
const fontSizePx = FONT_SIZE_PX * fontScale;
const lineHeightPx = baseLineHeightPx * fontScale;
const linesPerPage = Math.max(1, Math.round(getLineLimit(format) / fontScale));
const linesPerPage = getEffectiveLineLimit(format, fontScale);
// Erzwungene Seitenumbrüche zuerst; danach jeden Block nach Zeilen auto-fließen.
const bloecke = String(text || '').split(/\[\[seitenumbruch\]\]/gi);
@@ -666,7 +681,7 @@ function countLetterPages(text, format, options = {}) {
const maxWidthPx = widthPx - marginLeftPx - (marginRightPx ?? marginLeftPx);
const fontScale = Math.max(0.8, Math.min(1.5, Number(options.fontScale) || 1));
const fontSizePx = FONT_SIZE_PX * fontScale;
const linesPerPage = Math.max(1, Math.round(getLineLimit(format) / fontScale));
const linesPerPage = getEffectiveLineLimit(format, fontScale);
const seitenZeilen = [];
for (const block of String(text || '').split(/\[\[seitenumbruch\]\]/gi)) {