Skip to content

Commit

Permalink
faster painting of empty inlines, prep for positioning
Browse files Browse the repository at this point in the history
perf-2 gets another 4-5ms by skipping the BoxBuilder stuff when
there aren't any inlines to paint in a paragraph

this is prep for relative positioning: now that inlines and items
get position information before paint, the postprocess step can
easily offset inlines and blocks according to `position: relative`
and the 4 side properties. this also enables
`display: inline-block` because the relative position of an inline-
block can't be known until after bidi reordering.
  • Loading branch information
chearon committed Dec 30, 2023
1 parent fe590c3 commit a5be286
Show file tree
Hide file tree
Showing 3 changed files with 345 additions and 329 deletions.
27 changes: 18 additions & 9 deletions src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,15 +1321,16 @@ export class IfcInline extends Inline {
public paragraph: Paragraph;
private analysis: number;

static ANALYSIS_HAS_TEXT = 1 << 0;
static ANALYSIS_WRAPS = 1 << 1;
static ANALYSIS_WS_COLLAPSES = 1 << 2;
static ANALYSIS_HAS_INLINES = 1 << 3;
static ANALYSIS_HAS_BREAKS = 1 << 4;
static ANALYSIS_IS_COMPLEX_TEXT = 1 << 5;
static ANALYSIS_HAS_SOFT_HYPHEN = 1 << 6;
static ANALYSIS_HAS_FLOATS = 1 << 7;
static ANALYSIS_HAS_NEWLINES = 1 << 8;
static ANALYSIS_HAS_TEXT = 1 << 0;
static ANALYSIS_WRAPS = 1 << 1;
static ANALYSIS_WS_COLLAPSES = 1 << 2;
static ANALYSIS_HAS_INLINES = 1 << 3;
static ANALYSIS_HAS_BREAKS = 1 << 4;
static ANALYSIS_IS_COMPLEX_TEXT = 1 << 5;
static ANALYSIS_HAS_SOFT_HYPHEN = 1 << 6;
static ANALYSIS_HAS_FLOATS = 1 << 7;
static ANALYSIS_HAS_NEWLINES = 1 << 8;
static ANALYSIS_HAS_PAINTED_SPANS = 1 << 9;

constructor(style: Style, text: string, children: InlineLevel[], attrs: number) {
super(0, text.length, style, children, Box.ATTRS.isAnonymous | attrs);
Expand Down Expand Up @@ -1382,6 +1383,9 @@ export class IfcInline extends Inline {
if (!isWsPreserved(box.style.whiteSpace)) {
this.analysis |= IfcInline.ANALYSIS_WS_COLLAPSES;
}
if (box.style.backgroundColor.a !== 0 || box.style.hasBorder()) {
this.analysis |= IfcInline.ANALYSIS_HAS_PAINTED_SPANS;
}
stack.unshift(...box.children);
} else if (box.isBreak()) {
this.analysis |= IfcInline.ANALYSIS_HAS_BREAKS;
Expand Down Expand Up @@ -1433,6 +1437,7 @@ export class IfcInline extends Inline {
doTextLayout(ctx: LayoutContext) {
if (this.hasText() || this.hasFloats()) {
this.paragraph.createLineboxes(ctx);
this.paragraph.positionItems(ctx);
}
}

Expand Down Expand Up @@ -1472,6 +1477,10 @@ export class IfcInline extends Inline {
return this.analysis & IfcInline.ANALYSIS_HAS_NEWLINES;
}

hasPaintedSpans() {
return this.analysis & IfcInline.ANALYSIS_HAS_PAINTED_SPANS;
}

assignContainingBlocks(ctx: LayoutContext) {
this.containingBlock = ctx.lastBlockContainerArea;
}
Expand Down
Loading

0 comments on commit a5be286

Please sign in to comment.