@@ -6,23 +6,32 @@ 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 } ,
a6 p : { marginTopMm : 8 , marginLeftMm : 8 , lineHeightFactor : 1.3 } ,
a6 l : { marginTopMm : 8 , marginLeftMm : 8 , marginRightMm : 14 , lineHeightFactor : 1.2 } ,
a5 p : { marginTopMm : 20 , marginLeftMm : 15 , lineHeightFactor : 1.35 } ,
a5 l : { marginTopMm : 20 , marginLeftMm : 15 , lineHeightFactor : 1.35 } ,
dinlang _karte : { marginTopMm : 8 , marginLeftMm : 10 , 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 } ,
} ;
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 } ,
} ;
// 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' } ;
// Live-Cache (wird von applyRenderFormats ersetzt). Start = Defaults.
let LINE _LIMITS = { ... DEFAULT _LINE _LIMITS } ;
@@ -56,6 +65,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 +121,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 +155,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 +177,7 @@ module.exports = {
getLayoutForFormat ,
getPageDimensions ,
getLineLimit ,
getEffectiveLineLimit ,
getFormatKind ,
escapeXml ,
applyRenderFormats ,