UNPKG

nehan

Version:

Html layout engine for paged-media written in Typescript

57 lines 1.69 kB
import { LogicalSize, SpaceCharTable, TextMeasure, } from "./public-api"; export class SpaceChar { constructor(str) { this.text = this.normalize(str); this.size = new LogicalSize({ measure: 0, extent: 0 }); this.info = SpaceCharTable.load(str); this.kerning = false; this.spacing = 0; this.charCount = 0; } static charRefToStr(str) { switch (str) { case " ": return "\u00A0"; case " ": return "\u2009"; case " ": return "\u2002"; case " ": return "\u2003"; } throw new Error("invalid space char ref(" + str + ")"); } normalize(str) { if (str.indexOf("&") === 0) { return SpaceChar.charRefToStr(str); } return str; } setMetrics(opts) { this.size = TextMeasure.getWordSize(opts.font, this.text); if (this.size.measure === 0) { this.size.measure = this.size.extent * this.info.advanceRate; } } toString() { return this.text; } isNoBreak() { return this.info.isNoBreak; } isZeroWidth() { return this.info.advanceRate === 0; } isCarriageReturn() { return this.text === "\u000D"; } isLineFeed() { return this.text === "\u000A"; } acceptEvaluator(visitor) { return visitor.visitSpaceChar(this); } } SpaceChar.zeroWidthSpace = "\u200B"; SpaceChar.enSpace = "\u2002"; SpaceChar.emSpace = "\u2003"; SpaceChar.noBreakSpace = "\u00A0"; SpaceChar.ideographicSpace = "\u3000"; SpaceChar.markerSpace = SpaceChar.enSpace; //# sourceMappingURL=space-char.js.map