UNPKG

nehan

Version:

Html layout engine for paged-media written in Typescript

35 lines 1.03 kB
import { LogicalSize, Tcy, TextMeasure, } from "./public-api"; export class Word { constructor(str) { this.text = str; this.size = new LogicalSize({ measure: 0, extent: 0 }); this.kerning = false; this.spacing = 0; } get charCount() { return this.text.length; } toString() { return this.text; } setMetrics(opts) { this.size = TextMeasure.getWordSize(opts.font, this.text); } toTcys() { return this.text.split("").map(chr => new Tcy(chr)); } breakWord(measure) { const headLen = Math.floor(this.text.length * measure / this.size.measure); const headText = this.text.substring(0, headLen); const tailText = this.text.substring(headLen); this.text = tailText; return new Word(headText); } restoreBrokenWord(word) { this.text = word.text + this.text; } acceptEvaluator(visitor) { return visitor.visitWord(this); } } //# sourceMappingURL=word.js.map