import { BodyElement, ParagraphProperties, Section, SectionProperties, TextOutline } from '../core/document-model/index.js'; import { FlowDoc } from '../core/ir/flow.js'; import { FontRegistry } from '../core/font/index.js'; import { Loss, ResourceStore } from '../core/ir/index.js'; import { PdfImage } from './images.js'; import { PdfPage } from './document.js'; import { PdfVector } from './vector.js'; import { TextMarkup } from './annot-draw.js'; import { TextRun } from './content.js'; /** * A reconstruction's document plus the losses incurred reading it (e.g. an * undecodable image colour space) — surfaced through the reader's `LossReport`. */ export interface Reconstruction { readonly doc: FlowDoc; readonly losses: ReadonlyArray; } /** * The corner a page's marks are measured from, in the SHOWN page's own y-up * frame — see `./display`, which puts every mark into it. * * The shown page starts at its own origin, so `left` is zero and `top` is its * height; the two are kept as a pair because a caller that has not been through * `display` (none, today) would state something else. */ export interface PageFrame { /** Left edge — subtract it to get an offset from the page. */ readonly left: number; /** Top edge — subtract from it to flip into a top-down frame. */ readonly top: number; } /** * Build a paragraph {@link BodyElement} from a single plain-text string, * optionally at the given outline (heading) level. Empty text yields a * paragraph with no runs. The link-free counterpart of {@link paragraphFromRuns}. */ export declare function paragraphBlock(text: string, outlineLevel?: number): BodyElement; /** One piece of reconstructed text, carrying any hyperlink (E-PDF EP8). */ export interface TextSpan { readonly text: string; readonly href?: string; /** The size the glyphs were SHOWN at (§9.3.1 Tf), so the run keeps it. */ readonly sizePt?: number; /** §8.6.8 — the colour they were painted in, when it is not plain black. */ readonly colorHex?: string; /** §9.6.2 — the face's own name, for a document that embeds its programs. */ readonly fontName?: string; /** §9.3.6 — a line round the glyphs, when the page asked for one. */ readonly outline?: TextOutline; /** §9.8.1 — the face was a bold one. */ readonly bold?: boolean; /** §9.8.1 — the face was a slanted one. */ readonly italic?: boolean; /** * §17.3.2.42 — the glyphs stood OFF the baseline the line is set on, and * smaller: a footnote mark, an exponent, an index. The page states it by * placement, and a document by the property. */ readonly script?: 'superscript' | 'subscript'; /** §12.5.6.10 — a text-markup annotation marks these words. */ readonly markup?: TextMarkup; } /** * Build a paragraph {@link BodyElement} from positioned {@link TextSpan}s, * coalescing consecutive spans that share an `href` into one run (so a link * survives as its own run) and squashing whitespace. With no hrefs this * collapses to a single run — the same shape {@link paragraphBlock} produces. */ export declare function paragraphFromRuns(spans: ReadonlyArray, outlineLevel?: number, placement?: Pick): BodyElement; /** * Store a {@link PdfImage}'s bytes (content-addressed dedup) and build the image * {@link BodyElement} that references them, sized in points from the placement * CTM. `alt` becomes the block's alt text when given. */ export declare function imageBlock(image: PdfImage, resources: ResourceStore, alt?: string, frame?: PageFrame, zOrder?: number, behind?: boolean): BodyElement; /** * A line of text as an anchored box, standing where the page set it. * * The flowed reconstruction reads a document OUT of a page: paragraphs in * reading order, re-flowable, free to land wherever the next medium puts them. * A form is not that document. 160F-2019.pdf is a grid of ruled boxes with a * label in each, and a label means nothing an inch from the box it labels — the * artwork is placed absolutely, so text that flows beside it lines up with none * of it. * * @param spans The line's runs. * @param box Its page-space rectangle (y-up, as PDF measures). * @param frame The page's own corner, to measure the box off. * @param zOrder Its place in the page's painting order. * @param rotation60k §20.1.7.6 — how far the box turns about its own centre, * for a baseline the page did not set flat. * @returns A shape carrying the text, anchored where the glyphs were. */ export declare function positionedText(spans: ReadonlyArray, box: { x: number; y: number; width: number; height: number; }, frame: PageFrame, zOrder: number, rotation60k?: number): BodyElement; /** Collapse losses sharing a `detail` message (the same colour space dropped on many pages). */ export declare function dedupeLosses(losses: ReadonlyArray): Array; /** * Turn a lifted {@link PdfVector} path (filled EP10 / stroked EP11) into a * custom-geometry shape {@link BodyElement}. Page-space points (y-up) become * path-space (bbox-relative, y-down); the shape is sized from the bounding box * (plus the stroke thickness). A fill becomes a solid fill, a stroke the outline. * * Given the page's frame the shape is ANCHORED where the page drew it, behind * the text, rather than taking a place of its own in the flow. A drawing is not * a paragraph: 22060_A1_01_Plans.pdf is one A3 sheet of vectors, and stacking * its forty-nine paths one under another spilled it onto a second page. */ export declare function shapeBlock(v: PdfVector, frame?: PageFrame, zOrder?: number, behind?: boolean): BodyElement; /** * Derive the {@link SectionProperties} geometry from the source pages so a * reconstructed PDF re-renders at its real page size and orientation rather than * the layout engine's `A4` default — without it an `A3` source paginates onto * several `A4` pages, a wide/landscape page is letterboxed, and so on. PDF * user-space units are points, matching `Pt`, so the `MediaBox` extents map * straight to the page size. Uses the first {@link PdfPage}'s box (the * near-universal uniform-size case); a PDF whose pages differ in size reflows to * this single geometry — a known approximation, still far better than a fixed * `A4`. Returns `undefined` when there is no usable first-page box. */ export declare function sectionFromPdfPages(pages: ReadonlyArray): SectionProperties | undefined; export declare function withMeasuredMargins(section: SectionProperties | undefined, shown: ReadonlyArray<{ width: number; height: number; }>, pageRuns: ReadonlyArray>, pageMarks?: ReadonlyArray>): SectionProperties | undefined; /** * Assemble the final {@link FlowDoc} for a reconstruction: the body elements * with their styles resolved against the empty style sheet, the lifted-image * resource store, and the optional page {@link SectionProperties}. Shared by * both reconstruction paths (the tagged fast-path EP3 and the heuristic layout * path EP4). */ export declare function buildFlowDoc(body: ReadonlyArray, resources?: ResourceStore, section?: SectionProperties, embeddedFonts?: ReadonlyMap, sections?: ReadonlyArray
, headersFooters?: ReadonlyMap>): FlowDoc;