Text Measurer
Class reference for TextMeasurer.
Because Scrivr renders off-DOM, it maps text dimensions manually via hardware-accelerated Canvas interactions wrapped in strict LRUCache architectures to guarantee 60fps throughput.
Constructor
new TextMeasurer({ lineHeightMultiplier?: number })Accepts a multiplier variant (default 1.2) defining global vertical spacing limits mathematically calculated over maximum glyph heights natively.
Type Interfaces
FontMetrics
export interface FontMetrics {
ascent: number;
descent: number;
lineHeight: number;
xHeight: number;
}RunMetrics
export interface RunMetrics {
totalWidth: number;
charPositions: number[];
}API Methods
measureWidth()
measureWidth(text: string, font: string): numberRuns a hyper-cached simple measurement resolving the raw pixel width of an identical string and font matrix. (Uses Map<font, Map<text, width>>).
getFontMetrics()
getFontMetrics(font: string): FontMetricsRetrieves fontBoundingBoxAscent/Descent ensuring a heavily stabilized string box. Rather than lines constantly bumping natively based on j, y, or p tails, the layout remains rigidly uniform across the entire document organically. Falls back to measuring "Hg" internally on unsupporting Chromium implementations.
measureRun()
measureRun(text: string, font: string): RunMetricsKerning check. Measures the string entirely via cumulative concatenation tracking accurately how the browser naturally merges specific characters tightly (AV). Because it calculates recursively, this resolves inside a bounded LRUCache<RunMetrics> limited safely to 2000 total keys aggressively.
invalidate()
invalidate(font?: string): voidTriggered manually following successful document.fonts.ready promises, throwing out prior cached font limits to force accurate Word-Wrap breakpoints to restart calculation cleanly.