/** * Font metric data for auto-fit column width and row height calculation. * * ## Architecture * * This module provides font advance width data at three precision tiers: * * **Tier 1 (Bitmap-accurate):** Calibri 11pt pixel widths, verified against * Excel's actual bitmap metrics (EBDT table). These values match * ClosedXML and rust_xlsxwriter measurements exactly. * * **Tier 2 (FUnit-accurate):** Per-character advance widths in font design units * (FUnits) extracted from TTF hmtx tables for Calibri and 8 other common fonts. * At runtime, pixel widths are calculated via: * `pixelWidth = ROUND(advanceFU / unitsPerEm * ROUND(fontSize / 72 * 96))` * This matches Excel's outline rendering for all sizes except Calibri 11pt * (where bitmap metrics differ from outline). * * **Tier 3 (Factor-based):** For ~230 other fonts, per-category average width * factors (lowercase, uppercase, wide) from excelize's experimentally-tuned table. * * ## Key References * * - ClosedXML Cell Dimensions wiki: https://github.com/closedxml/closedxml/wiki/Cell-Dimensions * - rust_xlsxwriter utility.rs pixel_width() * - excelize templates.go supportedFontWidthFactors * - ECMA-376 ยง18.3.1.13 (col element, width attribute) */ /** Calibri Regular 11pt per-character pixel widths (code point -> pixels) */ declare const CALIBRI_11PT_PX: Record; /** Font metrics header: unitsPerEm, usWinAscent, usWinDescent, maxDigitAdvance, sTypoAscender, sTypoDescender, sTypoLineGap */ export interface FontMetricsHeader { unitsPerEm: number; usWinAscent: number; usWinDescent: number; maxDigitAdvance: number; sTypoAscender: number; sTypoDescender: number; sTypoLineGap: number; } /** Run-length encoded advance data: [startCodePoint, count, advanceFU] */ export type AdvanceRun = [start: number, count: number, advance: number]; export interface FontMetrics { header: FontMetricsHeader; /** Default advance for characters not in the table (typically Latin average) */ defaultAdvance: number; /** Advance width for CJK ideographs (U+4E00..U+9FFF) */ cjkAdvance: number; /** Run-length encoded advance data */ advances: AdvanceRun[]; } /** * Get FUnit metrics for a font by name, optionally bold variant. * Returns undefined if no FUnit data is available (falls back to Tier 3). * When bold is true and no bold-specific metrics exist, returns the regular variant. */ export declare function getFontMetrics(fontName: string, bold?: boolean): FontMetrics | undefined; /** * Check if a font has a dedicated bold metrics table. * When false, the bold multiplier (1.05) should be applied to width calculations. */ export declare function hasBoldMetrics(fontName: string): boolean; /** * Get the Calibri Regular metrics (default font). */ export declare function getDefaultFontMetrics(): FontMetrics; /** * Get the advance width of a character in FUnits for a given font. * Returns the font's defaultAdvance if the character is not in the table. * * For CJK Unified Ideographs (U+4E00..U+9FFF, U+3400..U+4DBF, U+F900..U+FAFF), * returns the font's cjkAdvance. */ export declare function getCharAdvance(metrics: FontMetrics, codePoint: number): number; /** * Get the Calibri 11pt bitmap pixel width for a character. * Returns undefined if not in the bitmap table. */ export declare function getCalibri11PtPixelWidth(codePoint: number): number | undefined; /** * Get Tier 3 font width factors [lowercase, uppercase, wide] for a font. * Returns undefined if no factors are available. */ export declare function getFontWidthFactors(fontName: string): [number, number, number] | undefined; /** * Check if a code point is an East Asian wide/fullwidth character. * This replaces golang.org/x/text/width from excelize. */ export declare function isWideCharacter(codePoint: number): boolean; export { CALIBRI_11PT_PX };