nehan
Version:
Html layout engine for paged-media written in Typescript
88 lines • 2.41 kB
JavaScript
import { LogicalCursorPos, } from './public-api';
export class TextFormatContext {
constructor(lexer, parent) {
this.lexer = lexer;
this.parent = parent;
this.name = "(text)";
this.progress = 1;
this.cursorPos = LogicalCursorPos.zero;
this.characters = [];
this.text = "";
}
get env() {
return this.parent.env;
}
get boxPos() {
return {
offsetPos: this.parent.flowRootPos,
clientPos: { start: 0, before: 0 }
};
}
get globalPos() {
return this.parent.globalPos.translate(this.cursorPos);
}
get flowRootPos() {
return this.parent.flowRootPos.translate(this.cursorPos);
}
get localPos() {
return this.parent.localPos.translate(this.cursorPos);
}
get lineHeadPos() {
return this.parent.lineHeadPos;
}
get pageRoot() {
return this.parent.pageRoot;
}
get flowRoot() {
return this.parent.flowRoot;
}
get inlineRoot() {
return this.parent.inlineRoot;
}
isLineHead() {
if (this.cursorPos.start > 0) {
return false;
}
let ctx = this.parent;
while (ctx) {
if (ctx.env.display.isBlockLevel() || ctx.env.display.isFlowRoot()) {
return ctx.inlineNodes.length === 0;
}
if (ctx.cursorPos.start > 0) {
return false;
}
ctx = ctx.parent;
}
throw new Error("inline root not found!");
}
get maxMeasure() {
return this.parent.maxMeasure;
}
get maxExtent() {
return this.parent.maxExtent;
}
get rootMeasure() {
return this.parent.rootMeasure;
}
get rootExtent() {
return this.parent.rootExtent;
}
get contextRestMeasure() {
return this.parent.contextRestMeasure;
}
get restMeasure() {
return this.parent.contextRestMeasure - this.cursorPos.start;
}
get restExtent() {
return this.parent.restExtent - this.cursorPos.before;
}
addCharacter(char) {
this.characters.push(char);
this.cursorPos.start += char.size.measure;
this.text += char.text;
}
acceptLayoutReducer(visitor, overflow) {
return visitor.visit(this, overflow);
}
}
//# sourceMappingURL=text-format-context.js.map