Skip to content

Commit 8f2cdac

Browse files
committed
test(columns): pin per-column gap placement at the engine (SD-2629 4d)
Direct layoutDocument acceptance for the step-4 flip: three authored 192px columns with per-column gaps [0, 48] in a 720px content box. Asserts the fill places the three columns at x = 40 / 232 / 472, which only holds when (a) widths are NOT scaled to fill (pre-flip scaled to ~240px -> col1 at 280) and (b) each column is positioned by its own gap (uniform-gap would put col2 at 424, not 472). This is the F9 shape (equal widths, non-uniform gaps): the case where the equal-width balancer guard passes but the old uniform stride mis-placed the trailing column. Traced end-to-end against the resolved- geometry path (clone -> resolveColumnLayout -> page.columns -> normalize -> geometry -> columnX), confirming gaps survive to placement.
1 parent d26f623 commit 8f2cdac

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

packages/layout-engine/layout-engine/src/index.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,29 @@ describe('layoutDocument', () => {
311311
expect(layout.pages[0].columns).toEqual({ count: 2, gap: 20, widths: [192, 384], equalWidth: false });
312312
});
313313

314+
it('places explicit columns at authored widths driven by per-column gaps (SD-2629 step 4)', () => {
315+
// The step-4 flip: explicit widths are no longer scaled to fill the content box, and each
316+
// column is positioned by its own gap. Three authored 192px columns (sum 576) sit in a 720px
317+
// content box with per-column gaps [0, 48]; total 624 < 720 leaves trailing space (Word does
318+
// not stretch authored widths). Per-column geometry:
319+
// col0 @ 40 (left margin)
320+
// col1 @ 40 + 192 + gaps[0]=0 = 232
321+
// col2 @ 40 + 192 + 0 + 192 + gaps[1]=48 = 472
322+
// Before the flip, normalize scaled the widths to ~240px and applied the scalar gap (0),
323+
// placing the columns at 40 / 280 / 520. This test fails on the pre-flip engine.
324+
const options: LayoutOptions = {
325+
pageSize: { w: 800, h: 800 },
326+
margins: { top: 40, right: 40, bottom: 40, left: 40 },
327+
columns: { count: 3, gap: 0, widths: [192, 192, 192], gaps: [0, 48], equalWidth: false },
328+
};
329+
// One 700px line per column: each 720px-tall column holds exactly one, filling all three.
330+
const layout = layoutDocument([block], [makeMeasure([700, 700, 700])], options);
331+
332+
expect(layout.pages).toHaveLength(1);
333+
const xs = layout.pages[0].fragments.map((fragment) => Math.round(fragment.x)).sort((a, b) => a - b);
334+
expect(xs).toEqual([40, 232, 472]);
335+
});
336+
314337
it('does not set "page.columns" on single column layout', () => {
315338
const options: LayoutOptions = {
316339
pageSize: { w: 600, h: 800 },

0 commit comments

Comments
 (0)