paperWidthPx function
The paper content width (px) for the on-screen preview.
Conversion basis: CSS's 96dpi (1in = 96px = 25.4mm), minus 44px total for the left/right margins. A4 portrait comes out to exactly 750 —— the same as flutter.pas's original hardcoded PaperW constant, which confirms in reverse that that 750 was "A4 portrait minus margins", so this formula is compatible with the existing layout.
With this, WML no longer needs to "stretch" the layout with a long string, nor does each page need its own <table width=>: the width is determined by the paper size and orientation, and the screen updates automatically when orientation changes.
Implementation
double paperWidthPx(String paper, String orient) {
const mmPerPx = 96.0 / 25.4;
const margin = 44.0; // left + right margins combined
// short/long side of each paper size (mm)
const sizes = <String, List<double>>{
'A3': [297, 420],
'A4': [210, 297],
'A5': [148, 210],
'B5': [176, 250],
'letter': [215.9, 279.4],
'legal': [215.9, 355.6],
};
final wh = sizes[normalizePaper(paper)] ?? sizes['A4']!;
final mm = isLandscape(orient) ? wh[1] : wh[0];
final px = mm * mmPerPx - margin;
return px < 200 ? 200 : px; // lower-bound safety net
}