import { MathNode } from '../core/document-model/index.js'; import { PathSegment } from '../core/vector.js'; /** Font variant a math glyph renders in (drives the auto-italic of letters). */ export type MathVariant = 'regular' | 'italic' | 'bold' | 'boldItalic'; /** * An ordinary symbol drawn from the font: a string positioned in the box's local * frame (origin = box left, baseline at `y = 0`, y up). */ export interface MathGlyphItem { readonly kind: 'glyph'; readonly x: number; /** Baseline offset, up positive. */ readonly y: number; readonly text: string; readonly variant: MathVariant; readonly sizePt: number; } /** A filled rectangle (fraction bars, accent rules); `(x, y)` is its bottom-left edge. */ export interface MathRuleItem { readonly kind: 'rule'; readonly x: number; readonly y: number; readonly w: number; readonly h: number; } /** * A vector path drawn instead of a math-font glyph (radicals, stretchy * delimiters, big operators) — so no math font is needed. */ export interface MathPathItem { readonly kind: 'path'; readonly segments: ReadonlyArray; /** Present ⇒ stroked at this width. */ readonly strokeWidthPt?: number; /** `true` ⇒ filled. */ readonly fill?: boolean; } /** A positioned draw item in a {@link MathBox}'s local frame. */ export type MathDrawItem = MathGlyphItem | MathRuleItem | MathPathItem; /** * A laid-out math box: a width plus ascent (above the baseline) and descent * (below), and a flat list of positioned {@link MathDrawItem}s in a LOCAL frame * (origin = box left, baseline at `y = 0`, y up). */ export interface MathBox { readonly width: number; readonly ascent: number; readonly descent: number; readonly items: ReadonlyArray; } /** Injected text-measure: the advance width of `text` at `sizePt` in `variant`. */ export type MeasureMath = (text: string, sizePt: number, variant: MathVariant) => number; /** Layout context threaded through {@link layoutMath} — currently just the em size. */ export interface MathCtx { readonly sizePt: number; } /** Decompose a {@link MathVariant} into its independent bold / italic flags. */ export declare function variantStyle(v: MathVariant): { bold: boolean; italic: boolean; }; /** * Recursively lay out an ECMA-376 §22 OfficeMath node into a {@link MathBox}. * Ordinary symbols become {@link MathGlyphItem}s (rendered from the font); * structural elements (fraction rules, radicals, big operators, stretchy * delimiters) become rule/path items drawn as vector graphics. Pure: text widths * arrive through the injected `measure` fn. * * @param node The math tree node to lay out. * @param ctx The layout context (em size). * @param measure The injected advance-width measurer. * @returns The positioned box; constructs added in later milestones render empty. */ export declare function layoutMath(node: MathNode, ctx: MathCtx, measure: MeasureMath): MathBox; /** Translate every item in a box by `(dx, dy)`, returning shifted copies. */ export declare function shiftItems(items: ReadonlyArray, dx: number, dy: number): Array; /** * Flatten a math tree into `(variant, text)` glyph segments — used to subset the * right glyphs into the right font variant. Grows alongside {@link layoutMath}. */ export declare function mathGlyphSegments(node: MathNode): Array<{ variant: MathVariant; text: string; }>;