import type { PdfDefaultAppearance } from '../fields/pdf-default-appearance.js'; import { PdfFont } from '../../fonts/pdf-font.js'; /** * Resource names of font variants to use when rendering styled markdown segments. * When a variant is provided, the appearance stream switches fonts instead of * simulating bold/italic via stroke width or matrix shear. */ export interface FontVariantNames { bold?: string; italic?: string; boldItalic?: string; } /** * Lightweight builder for PDF content streams. * Chains PDF operators via a fluent API and emits the final stream with build(). * Enhanced with text measurement capabilities for layout calculations. */ export declare class PdfGraphics { private lines; private resolvedFonts?; private defaultAppearance?; private fontVariantNames?; constructor(options?: { resolvedFonts?: Map; defaultAppearance?: PdfDefaultAppearance; fontVariantNames?: FontVariantNames; }); save(): this; restore(): this; beginText(): this; endText(): this; setDefaultAppearance(da: PdfDefaultAppearance): this; moveTo(x: number, y: number): this; showText(text: string, isUnicode: boolean, reverseEncodingMap?: Map): this; showLiteralText(text: string): this; beginMarkedContent(): this; endMarkedContent(): this; raw(op: string): this; setFillRGB(r: number, g: number, b: number): this; setFillGray(v: number): this; setFont(name: string, size: number): this; movePath(x: number, y: number): this; lineTo(x: number, y: number): this; curveTo(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): this; fill(): this; stroke(): this; closePath(): this; static readonly ITALIC_SHEAR = 0.267; static readonly BOLD_STROKE_RATIO = 0.04; /** * Re-attributes styled segments to wrapped lines by tracking character * positions in the flat plain-text. One whitespace character is consumed * at each line boundary (space from word-wrap or newline from paragraph). */ private static splitSegmentsToLines; /** * Returns the resource name of the best-matching font variant for the given * bold/italic flags, or undefined if no variant fonts are configured. */ private resolveVariantFontName; /** * Measures text width using a specific font from resolvedFonts by resource * name, falling back to measureTextWidth (regular font) if not found. */ measureTextWidthWithFont(text: string, fontName: string | undefined, fontSize: number): number; /** * Emits styled text segments into the current BT…ET block. * Returns an array of rects for any strikethrough segments so the caller * can draw the lines after closing the text object. */ private showSegments; /** * Parses a markdown string, renders the styled segments inside a BT…ET * block, then draws strikethrough lines (if any) as path operations after * the text object. Pass `multiline` to wrap across multiple lines. */ showMarkdown(markdown: string, isUnicode: boolean, reverseEncodingMap: Map | undefined, x: number, y: number, fontSize: number, multiline?: { availableWidth: number; lineHeight: number; }): this; build(): string; private get currentFont(); /** * Calculate the width of text using the current font and size. */ measureTextWidth(text: string, fontSize?: number): number; /** * Wrap text to fit within the specified width, breaking at word boundaries. * When a bold font variant is configured, uses its metrics conservatively * to prevent bold glyphs from overflowing field bounds. */ wrapTextToLines(text: string, maxWidth: number, fontSize?: number): string[]; /** * Calculate the minimum font size needed to fit text within given constraints. */ calculateFittingFontSize(text: string, maxWidth: number, maxHeight?: number, lineHeight?: number): number; private breakLongWord; }