TableGuard, BottomSpacer, FirstPageHeader and PageChrome implement the verified pagination rules; renderCore returns bytes, a normalised layout tree, audit issues and a layout fingerprint. auditLayout detects overlaps, ink overflow, truncation, header-only pages and split blocks. Quirk tests pin the react-pdf behaviours the design depends on, and a child-process test pins the page-level absolute Svg hang.
36 lines
1.8 KiB
TypeScript
36 lines
1.8 KiB
TypeScript
import { Text } from "@react-pdf/renderer";
|
|
import { FILL, pinned } from "../engine/columns";
|
|
import { roleToken, type RoleName, type TypeToken } from "../fonts/roles";
|
|
import { pdfFlags, type PdfFlagsInput } from "./pdfProps";
|
|
import { assertNoLineHeight, baseTextStyle, type TxtStyleProps } from "./Txt";
|
|
|
|
export interface RenderTxtProps extends TxtStyleProps, PdfFlagsInput {
|
|
/** Receives { pageNumber, totalPages, subPageNumber, ... } from react-pdf. */
|
|
render: (info: { pageNumber: number; totalPages: number; subPageNumber: number; subPageTotalPages: number }) => string;
|
|
role: RoleName | TypeToken;
|
|
/** react-pdf copies the id into the layout tree (the audit finds chrome nodes by it). */
|
|
id?: string;
|
|
width?: number;
|
|
grow?: boolean;
|
|
style?: Record<string, unknown>;
|
|
}
|
|
|
|
/**
|
|
* Text drawn from a render prop (page numbers, continuation band). It sets NO lineHeight, and no
|
|
* ancestor may set one either: react-pdf multiplies a render-prop lineHeight again on every relayout
|
|
* ('10pt' ends up as 5120 and nothing draws). The box is auto-height; reserve its space from font
|
|
* metrics, never a fixed height. No maxLines: a clamped render-prop Text draws nothing.
|
|
* `totalPages` is undefined on the first layout pass, so the render function must cope with that.
|
|
*/
|
|
export function RenderTxt({ id, role, render, color, align, weight, italic, width, grow, style, faceOverrides, fixed, wrap, minPresenceAhead }: RenderTxtProps) {
|
|
const token = roleToken(role);
|
|
assertNoLineHeight(style, "RenderTxt");
|
|
const merged = {
|
|
...baseTextStyle(token, { color, align, weight, italic, faceOverrides }),
|
|
...(width !== undefined ? pinned(width) : {}),
|
|
...(grow ? FILL : {}),
|
|
...style,
|
|
};
|
|
return <Text {...(id !== undefined ? { id } : {})} style={merged as never} render={render as never} {...pdfFlags({ fixed, wrap, minPresenceAhead })} />;
|
|
}
|