UNPKG

@mlightcad/shx-parser

Version:

A TypeScript library for parsing AutoCAD SHX font files

53 lines (52 loc) 2.26 kB
import { ShxAdvanceWidthStrategy } from './advanceWidthStrategy'; import { ShxFont } from './font'; import { ShxFontData } from './fontData'; import { ShxShape } from './shape'; /** A glyph positioned on a text line. */ export interface PlacedGlyph { /** Scaled glyph geometry translated to the line position */ shape: ShxShape; /** Left edge x coordinate (baseline origin for this glyph) */ x: number; } /** One character in a horizontal text run. */ export interface TextRunGlyph { font: ShxFont; code: number; size: number; } /** * Returns the horizontal advance width stored on a scaled glyph. * * Uses {@link ShxShape.lastPoint}.x when present; otherwise falls back to ink width. * Prefer {@link resolveAdvanceWidth} for layout, which applies cell-width fallback. */ export declare function getAdvanceWidth(shape: ShxShape): number; /** Options for {@link layoutTextRun}. */ export interface TextLayoutOptions { /** Horizontal advance strategy applied to each glyph in the run. */ advance?: ShxAdvanceWidthStrategy; } /** * Resolves the horizontal advance for a layout-ready glyph. * * @param shape - Scaled glyph geometry, typically from {@link ShxFont.getLayoutCharShape} * @param fontData - Parsed font header and content * @param size - Target font size in drawing units * @param advanceStrategy - Advance strategy; defaults to {@link defaultAdvanceWidthStrategy} */ export declare function resolveAdvanceWidth(shape: ShxShape, fontData: ShxFontData, size: number, advanceStrategy?: ShxAdvanceWidthStrategy): number; /** * Translates a glyph so its font baseline sits at `(x, baselineY)`. * * Glyphs keep their encoded vertical coordinates from the SHX file; the baseline is * y = 0 in font space per the AutoCAD shape-font specification. */ export declare function placeGlyphOnBaseline(shape: ShxShape, x: number, baselineY?: number): ShxShape; /** * Lays out glyphs horizontally on a shared baseline using each font's native coordinates. * * @param glyphs - Characters to place left-to-right * @param baselineY - Shared baseline y coordinate in drawing units */ export declare function layoutTextRun(glyphs: TextRunGlyph[], baselineY?: number, options?: TextLayoutOptions): PlacedGlyph[];