import { GlyphBuffer } from "../buffer/glyph-buffer.ts"; import type { Font } from "../font/font.ts"; import type { GlyphId, Tag } from "../types.ts"; /** * Justification mode */ export declare enum JustifyMode { /** Shrink text to fit */ Shrink = "shrink", /** Extend text to fit */ Extend = "extend", /** Auto-select based on delta */ Auto = "auto" } /** * Justification options */ export interface JustifyOptions { /** Target line width */ targetWidth: number; /** Script tag */ script?: Tag; /** Language tag */ language?: Tag; /** Justification mode */ mode?: JustifyMode; /** Maximum priority level to use (0-based) */ maxPriority?: number; /** Enable Kashida insertion for Arabic */ enableKashida?: boolean; /** Minimum word spacing factor (default: 0.8) */ minWordSpacingFactor?: number; /** Maximum word spacing factor (default: 1.5) */ maxWordSpacingFactor?: number; /** Enable inter-character spacing adjustment */ enableLetterSpacing?: boolean; /** Maximum letter spacing in font units */ maxLetterSpacing?: number; } /** * Justification result */ export interface JustifyResult { /** Whether justification succeeded */ success: boolean; /** Final line width after justification */ finalWidth: number; /** Delta from target (positive = too wide, negative = too narrow) */ delta: number; /** Priority level used */ priorityLevel: number; /** Adjustments applied */ adjustments: JustifyAdjustment[]; } /** * Individual justification adjustment */ export interface JustifyAdjustment { type: "spacing" | "kashida" | "lookup"; /** Glyph indices affected */ glyphIndices: number[]; /** Adjustment value */ value: number; } /** * Calculate current line width from glyph buffer * @param buffer - The glyph buffer to measure * @returns Total line width in font units (sum of all xAdvance values) */ export declare function calculateLineWidth(buffer: GlyphBuffer): number; /** * Justify a shaped glyph buffer to fit a target width * @param font - The font containing JSTF and glyph metrics * @param buffer - The shaped glyph buffer to justify (modified in place) * @param options - Justification options including target width and mode * @returns Result containing success status, final width, and applied adjustments */ export declare function justify(font: Font, buffer: GlyphBuffer, options: JustifyOptions): JustifyResult; /** * Simple line breaking for multi-line text */ export interface LineBreakResult { lines: GlyphBuffer[]; breakPoints: number[]; } /** * Break shaped text into lines at a given width using simple greedy algorithm * @param buffer - The shaped glyph buffer to break into lines * @param maxWidth - Maximum line width in font units * @param spaceGlyph - Optional glyph ID of space character for word boundary detection * @returns Object containing array of line buffers and break point indices */ export declare function breakIntoLines(buffer: GlyphBuffer, maxWidth: number, spaceGlyph?: GlyphId): LineBreakResult; /** * Justify all lines in a paragraph to the same width * @param font - The font containing JSTF and glyph metrics * @param lines - Array of glyph buffers representing lines (modified in place) * @param options - Justification options including target width and mode * @returns Array of justification results, one per line */ export declare function justifyParagraph(font: Font, lines: GlyphBuffer[], options: JustifyOptions): JustifyResult[];