/** * Word Document Layout Engine — Advanced Pagination Model * * Provides page-break calculation for DOCX documents with support for: * - Precise line-by-line text wrapping with greedy algorithm * - CJK full-width character width awareness * - First-line indent / hanging indent * - Tab stop positioning * - Contextual spacing (paragraph spacing collapse) * - Widow & Orphan control * - Footnote/Endnote space reservation * - Table cell content height calculation * - Inline image height contribution * - Numbering (bullet/number) indent calculation * * Units reminder: * 1 inch = 1440 twips * 1 pt = 20 twips * Default US Letter: 12240 × 15840 twips, margins 1440 each * Half-point 24 = 12pt font; line height ~14.4pt = 288 twips (single-spaced) */ import type { DocxDocument } from "../types.js"; /** 分页结果:每个 body content 的页面位置 */ export interface LayoutResult { /** 总页数 */ readonly pageCount: number; /** 每一节的页数 */ readonly sectionPageCounts: readonly number[]; /** 每个 body content 项的页码(1-based) */ readonly contentPages: readonly number[]; /** 每个 body content 项的所在节(0-based) */ readonly contentSections: readonly number[]; /** 书签名 → 页码 的映射 */ readonly bookmarkPages: ReadonlyMap; } /** 布局选项 */ export interface LayoutOptions { /** 默认字号(半磅),默认 24 (= 12pt) */ readonly defaultFontSize?: number; /** 默认每行字符数估算(用于行高计算),默认 80 */ readonly defaultCharsPerLine?: number; /** 平均字符宽度(twips),默认基于 12pt 字体 */ readonly averageCharWidth?: number; /** * Optional text measurement function for precise layout. * Should return the width of the text in points. * Uses heuristic character-count estimation if not provided. * * @example * ```ts * import { measureTextWidth, mapToStandardFont } from "../../../utils/font-metrics.js"; * const options: LayoutOptions = { * measureText: (text, font, size) => measureTextWidth(text, mapToStandardFont(font), size) * }; * ``` */ readonly measureText?: (text: string, fontName: string, fontSize: number) => number; } /** * 对文档进行分页布局计算。 * 返回每个 body content 所在的页码和总页数。 */ export declare function layoutDocument(doc: DocxDocument, options?: LayoutOptions): LayoutResult;