Skip to content

Commit 128a94a

Browse files
committed
rename Paragraph.backgroundBoxes to fragments
that's what they are, fragmented inline areas! `items` are also fragments, so perhaps it should be `itemFragments` and `areaFragments`, but `items` and `fragments` seems easy enough to figure out
1 parent 3628037 commit 128a94a

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed

src/layout-flow.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,13 +1345,13 @@ export class IfcInline extends Inline {
13451345
}
13461346
}
13471347

1348-
for (const [inline, backgrounds] of this.paragraph.backgroundBoxes) {
1348+
for (const [inline, fragments] of this.paragraph.fragments) {
13491349
const {dx, dy} = inlineShifts.get(inline)!;
13501350

1351-
for (const background of backgrounds) {
1352-
background.blockOffset += this.containingBlock.y + dy;
1353-
background.start += this.containingBlock.x + dx;
1354-
background.end += this.containingBlock.x + dx;
1351+
for (const fragment of fragments) {
1352+
fragment.blockOffset += this.containingBlock.y + dy;
1353+
fragment.start += this.containingBlock.x + dx;
1354+
fragment.end += this.containingBlock.x + dx;
13551355
}
13561356
}
13571357
}

src/layout-text.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ export class Linebox extends LineItemLinkedList {
15171517
}
15181518
}
15191519

1520-
export interface BackgroundBox {
1520+
export interface InlineFragment {
15211521
inline: Inline;
15221522
start: number;
15231523
end: number;
@@ -1529,41 +1529,41 @@ export interface BackgroundBox {
15291529
}
15301530

15311531
class ContiguousBoxBuilder {
1532-
opened: Map<Inline, BackgroundBox>;
1533-
closed: Map<Inline, BackgroundBox[]>;
1532+
opened: Map<Inline, InlineFragment>;
1533+
closed: Map<Inline, InlineFragment[]>;
15341534

15351535
constructor() {
15361536
this.opened = new Map();
15371537
this.closed = new Map();
15381538
}
15391539

15401540
open(inline: Inline, naturalStart: boolean, start: number, blockOffset: number) {
1541-
const box = this.opened.get(inline);
1541+
const fragment = this.opened.get(inline);
15421542

1543-
if (box) {
1544-
box.end = start;
1543+
if (fragment) {
1544+
fragment.end = start;
15451545
} else {
15461546
const end = start;
15471547
const naturalEnd = false;
15481548
const {ascender, descender} = inline.metrics;
1549-
const box: BackgroundBox = {
1549+
const fragment: InlineFragment = {
15501550
start, end, inline, blockOffset, ascender, descender, naturalStart, naturalEnd
15511551
};
1552-
this.opened.set(inline, box);
1552+
this.opened.set(inline, fragment);
15531553
// Make sure closed is in open order
15541554
if (!this.closed.has(inline)) this.closed.set(inline, []);
15551555
}
15561556
}
15571557

15581558
close(inline: Inline, naturalEnd: boolean, end: number) {
1559-
const box = this.opened.get(inline);
1559+
const fragment = this.opened.get(inline);
15601560

1561-
if (box) {
1561+
if (fragment) {
15621562
const list = this.closed.get(inline);
1563-
box.end = end;
1564-
box.naturalEnd = naturalEnd;
1563+
fragment.end = end;
1564+
fragment.naturalEnd = naturalEnd;
15651565
this.opened.delete(inline);
1566-
list ? list.push(box) : this.closed.set(inline, [box]);
1566+
list ? list.push(fragment) : this.closed.set(inline, [fragment]);
15671567
}
15681568
}
15691569

@@ -1651,15 +1651,15 @@ export class Paragraph {
16511651
buffer: AllocatedUint16Array;
16521652
items: ShapedItem[];
16531653
lineboxes: Linebox[];
1654-
backgroundBoxes: Map<Inline, BackgroundBox[]>;
1654+
fragments: Map<Inline, InlineFragment[]>;
16551655

16561656
constructor(ifc: IfcInline, buffer: AllocatedUint16Array) {
16571657
this.ifc = ifc;
16581658
this.string = ifc.text;
16591659
this.buffer = buffer;
16601660
this.items = [];
16611661
this.lineboxes = [];
1662-
this.backgroundBoxes = new Map();
1662+
this.fragments = new Map();
16631663
}
16641664

16651665
getHeight() {
@@ -2653,11 +2653,11 @@ export class Paragraph {
26532653

26542654
if (boxBuilder) {
26552655
for (const [inline, list] of boxBuilder.closed) {
2656-
const thisList = this.backgroundBoxes.get(inline);
2656+
const thisList = this.fragments.get(inline);
26572657
if (thisList) {
2658-
for (const backgroundBox of list) thisList.push(backgroundBox);
2658+
for (const fragment of list) thisList.push(fragment);
26592659
} else {
2660-
this.backgroundBoxes.set(inline, list);
2660+
this.fragments.set(inline, list);
26612661
}
26622662
}
26632663
}

src/paint.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Box, FormattingBox} from './layout-box.ts';
66
import {binarySearchOf} from './util.ts';
77

88
import type {InlineLevel, BlockLevel} from './layout-flow.ts';
9-
import type {BackgroundBox} from './layout-text.ts';
9+
import type {InlineFragment} from './layout-text.ts';
1010
import type {Color} from './style.ts';
1111
import type {LoadedFontFace} from './text-font.ts';
1212

@@ -214,21 +214,21 @@ function snap(ox: number, oy: number, ow: number, oh: number) {
214214
}
215215

216216
function paintInlineBackground(
217-
background: BackgroundBox,
217+
fragment: InlineFragment,
218218
paragraph: Paragraph,
219219
b: PaintBackend
220220
) {
221221
const ifc = paragraph.ifc;
222222
const direction = ifc.style.direction;
223-
const inline = background.inline;
223+
const inline = fragment.inline;
224224
const bgc = inline.style.backgroundColor;
225225
const clip = inline.style.backgroundClip;
226226
const {borderTopColor, borderRightColor, borderBottomColor, borderLeftColor} = inline.style;
227227
const {a: ta} = borderTopColor;
228228
const {a: ra} = borderRightColor;
229229
const {a: ba} = borderBottomColor;
230230
const {a: la} = borderLeftColor;
231-
const {start, end, blockOffset, ascender, descender, naturalStart, naturalEnd} = background;
231+
const {start, end, blockOffset, ascender, descender, naturalStart, naturalEnd} = fragment;
232232
const paddingTop = inline.style.getPaddingBlockStart(ifc);
233233
const paddingRight = inline.style.getPaddingLineRight(ifc);
234234
const paddingBottom = inline.style.getPaddingBlockEnd(ifc);
@@ -350,9 +350,9 @@ function paintInline(
350350
const box = stack.pop()!;
351351
if (box.isInline()) {
352352
if (!box.isLayerRoot() || box === inlineRoot) {
353-
const inlineBackgrounds = paragraph.backgroundBoxes.get(box);
354-
if (inlineBackgrounds) {
355-
for (const background of inlineBackgrounds) {
353+
const fragments = paragraph.fragments.get(box);
354+
if (fragments) {
355+
for (const background of fragments) {
356356
paintInlineBackground(background, paragraph, b);
357357
}
358358
}

test/flow.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,18 +1680,18 @@ describe('Flow', function () {
16801680
/** @type import('../src/layout-flow.ts').IfcInline[] */
16811681
const [ifc] = this.get('div').children;
16821682

1683-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t1'))[0].start).to.equal(87.03125);
1684-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t1'))[0].end).to.equal(133.28125);
1683+
expect(ifc.paragraph.fragments.get(this.get('#t1'))[0].start).to.equal(87.03125);
1684+
expect(ifc.paragraph.fragments.get(this.get('#t1'))[0].end).to.equal(133.28125);
16851685
expect(ifc.paragraph.items[1].x).to.equal(87.03125);
16861686

1687-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t2'))[0].start).to.equal(139.7265625);
1688-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t2'))[0].end).to.equal(211.7734375);
1687+
expect(ifc.paragraph.fragments.get(this.get('#t2'))[0].start).to.equal(139.7265625);
1688+
expect(ifc.paragraph.fragments.get(this.get('#t2'))[0].end).to.equal(211.7734375);
16891689
expect(ifc.paragraph.items[3].x).to.equal(139.7265625);
16901690

1691-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t3'))[0].blockOffset).to.equal(13.74609375);
1691+
expect(ifc.paragraph.fragments.get(this.get('#t3'))[0].blockOffset).to.equal(13.74609375);
16921692
expect(ifc.paragraph.items[5].y).to.equal(13.74609375);
16931693

1694-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t4'))[0].blockOffset).to.equal(15.74609375);
1694+
expect(ifc.paragraph.fragments.get(this.get('#t4'))[0].blockOffset).to.equal(15.74609375);
16951695
expect(ifc.paragraph.items[7].y).to.equal(15.74609375);
16961696
});
16971697

@@ -1714,18 +1714,18 @@ describe('Flow', function () {
17141714
/** @type import('../src/layout-flow.ts').IfcInline[] */
17151715
const [ifc] = this.get('div').children;
17161716

1717-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t1'))[0].start).to.equal(88.03125);
1718-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t1'))[0].end).to.equal(134.28125);
1717+
expect(ifc.paragraph.fragments.get(this.get('#t1'))[0].start).to.equal(88.03125);
1718+
expect(ifc.paragraph.fragments.get(this.get('#t1'))[0].end).to.equal(134.28125);
17191719
expect(ifc.paragraph.items[1].x).to.equal(88.03125);
17201720

1721-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t2'))[0].start).to.equal(140.7265625);
1722-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t2'))[0].end).to.equal(212.7734375);
1721+
expect(ifc.paragraph.fragments.get(this.get('#t2'))[0].start).to.equal(140.7265625);
1722+
expect(ifc.paragraph.fragments.get(this.get('#t2'))[0].end).to.equal(212.7734375);
17231723
expect(ifc.paragraph.items[3].x).to.equal(140.7265625);
17241724

1725-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t3'))[0].blockOffset).to.equal(14.74609375);
1725+
expect(ifc.paragraph.fragments.get(this.get('#t3'))[0].blockOffset).to.equal(14.74609375);
17261726
expect(ifc.paragraph.items[5].y).to.equal(14.74609375);
17271727

1728-
expect(ifc.paragraph.backgroundBoxes.get(this.get('#t4'))[0].blockOffset).to.equal(16.74609375);
1728+
expect(ifc.paragraph.fragments.get(this.get('#t4'))[0].blockOffset).to.equal(16.74609375);
17291729
expect(ifc.paragraph.items[8].y).to.equal(16.74609375);
17301730
});
17311731

test/text.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,9 +2086,9 @@ describe('Inline Blocks', function () {
20862086
const [ifc] = this.get('#t1').children;
20872087
/** @type import('../src/layout-flow.ts').Inline */
20882088
const span = this.get('#t2');
2089-
const box = ifc.paragraph.backgroundBoxes.get(span);
2090-
expect(box[0].start).to.equal(8.96);
2091-
expect(box[0].end).to.equal(90.44800000000001);
2089+
const fragment = ifc.paragraph.fragments.get(span);
2090+
expect(fragment[0].start).to.equal(8.96);
2091+
expect(fragment[0].end).to.equal(90.44800000000001);
20922092
});
20932093

20942094
it('occupies the right amount of space for floats', function () {

0 commit comments

Comments
 (0)