Skip to content

A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy injectors to reality checkers. Each agent is a specialized expert with personality, processes, and proven deliverables.

Shell

Reject invalid custom page geometry before producing PDF CSS

Rudy Celekli3ba3eafbe303
diff --git a/engineering/engineering-pdf-engine-architect.md b/engineering/engineering-pdf-engine-architect.md
index 8737e44e..1dcd00ae 100644
--- a/engineering/engineering-pdf-engine-architect.md
+++ b/engineering/engineering-pdf-engine-architect.md
@@ -278,22 +278,32 @@ export class PageGeometryEngine {
};
public static getDimensions(format: PageFormat, custom?: CustomPageDimensions) {
- const dim = format === 'custom' && custom ? custom : this.PRESETS[format as keyof typeof this.PRESETS] || this.PRESETS.a4;
- const widthPt = (dim.widthMm * 72) / 25.4;
- const heightPt = (dim.heightMm * 72) / 25.4;
- const widthPx = (dim.widthMm * 96) / 25.4;
- const heightPx = (dim.heightMm * 96) / 25.4;
+ const dim = format === 'custom' ? custom : this.PRESETS[format as keyof typeof this.PRESETS];
+ if (!dim || !Number.isFinite(dim.widthMm) || !Number.isFinite(dim.heightMm) ||
+ dim.widthMm <= 0 || dim.heightMm <= 0) {
+ throw new Error('A supported format or finite positive custom page dimensions are required.');
+ }
+ const widthPt = Number(((dim.widthMm * 72) / 25.4).toFixed(2));
+ const heightPt = Number(((dim.heightMm * 72) / 25.4).toFixed(2));
+ const widthPx = Number(((dim.widthMm * 96) / 25.4).toFixed(2));
+ const heightPx = Number(((dim.heightMm * 96) / 25.4).toFixed(2));
+ const heightBudgetPx = Number(((dim.heightMm * 96) / 25.4 - 0.5).toFixed(2));
+ if (![widthPt, heightPt, widthPx, heightPx].every(Number.isFinite) ||
+ widthPt <= 0 || heightPt <= 0 || widthPx <= 0 || heightPx <= 0 ||
+ heightBudgetPx <= 0) {
+ throw new Error('Page geometry must leave a positive finite layout budget.');
+ }
return {
name: dim.name || 'Custom',
widthMm: dim.widthMm,
heightMm: dim.heightMm,
- widthPt: Number(widthPt.toFixed(2)),
- heightPt: Number(heightPt.toFixed(2)),
- widthPx: Number(widthPx.toFixed(2)),
- heightPx: Number(heightPx.toFixed(2)),
+ widthPt,
+ heightPt,
+ widthPx,
+ heightPx,
// Epsilon-buffered maximum height to prevent LayoutUnit quantization blank pages
- heightBudgetPx: Number((heightPx - 0.5).toFixed(2))
+ heightBudgetPx
};
}