Skip to content

feat(builder): cell, table and paragraph formatting gaps (per-side borders and padding, spacer, paragraph options, short rules) #296

Done

Description

@vaceslav

Found by porting a real-world template end to end (#292; epic #261, phase 4). The template matched the original in pages, words and fonts through a Stirling-PDF (LibreOffice) PDF path.

F2 — Cell and table geometry: per-side borders, per-side padding · significant

Missing today: a border on one cell or on one side of a cell; a rule only above or only below a table; different
padding per side for a cell, a table style or a box.

Where the port needed it:

  • a status cell whose frame has its own colour inside a strip of neutral cells — not possible;
  • "a record that belongs to the one above": stepped in, with a rule down its left edge — done with a 0.75 pt column
    that has a background, plus an empty spacer column;
  • a list table that opens with a rule on top — done with a Rule block before the table;
  • padding of 8 / 9 pt and 6 / 7 pt, and a box with less padding at the bottom than on top — only symmetric values.
cell.Border(Sides.Left, 0.75.Pt(), theme.Line);          // one side of one cell
cell.Border(Sides.All, 1.Pt(), tone.Line);               // a frame of its own
cell.Padding(top: 8.Pt(), right: 6.Pt(), bottom: 9.Pt(), left: 6.Pt());
s.Table(Marked, g => g.TopRule(0.75.Pt(), line).RowRule(0.5.Pt(), hairline));
s.Box(Panel, b => b.Padding(top: 12.Pt(), right: 12.Pt(), bottom: 6.Pt(), left: 12.Pt()));
table.Indent(6.Mm());                                    // a stepped-in table

Vertical merge, text direction and row height belong to the same group; this template did not need them.

F3 — No paragraph-level formatting and no spacer block · significant

Every deviation from a style is a style of its own. In the port 17 of 37 paragraph styles exist only for that: five
gap styles (a gap is an empty paragraph), "kept with next" copies of two styles, copies with 3 / 5 / 7 pt above or
below, two styles for lines that hold an image. A user who opens the template sees a style list almost twice as long
as the design has.

c.Spacer(14.Pt());                                        // no style needed
c.Paragraph(Styles.TableValue, x => …, p => p.KeepWithNext());
c.Paragraph(Styles.TableLabel, text, p => p.SpaceBefore(7.Pt()));
table.SpaceBefore(17.Pt());                               // today only SpaceAfter

If "named styles only" stays the policy, Spacer(height) and KeepWithNext on a paragraph alone would remove most of
the variants.

F8 — A rule is always as wide as the frame; styles have no borders · cosmetic

A short rule (12 mm under a title) is a table with one filled cell in the port. The rules of the running head and foot
are Rule blocks, which works well.

c.Rule(1.5.Pt(), ink).Width(12.Mm()).SpaceBelow(14.Pt());
s.Paragraph(RunHead, p => p.BorderBottom(0.75.Pt(), line, space: 3.Pt()));

F13 — Spacer paragraphs stack · cosmetic

After filling, a box that ends with conditionals ends with two or three "Template Spacer" paragraphs in a row, one per
reason (after a table, at the end of the inner cell, at the end of the outer cell). Each is 1 pt, so a box grows by
2–4 pt. One per position would do.

Activity

  1. added
    enhancement
    builder
    on Nov 26, 2026
  2. vaceslav commented on Dec 1, 2026

    @vaceslav
    ContributorAuthor

    Done on feature/builder (e4e4036..e32e67d). Design: docs/superpowers/specs/2026-12-01-builder-formatting-gaps-design.md.

    Built

    • F3 paragraph options: Paragraph(style, text | value | content, p => p.SpaceBefore(…).SpaceAfter(…).KeepWithNext().KeepLinesTogether()). They are written as the paragraph's own properties on top of its named style; text formatting, alignment and indents stay style-only. The builder design's rule 2.3 is amended.
    • F3 Spacer(height): an empty paragraph of exact height, up to 72 pt. JSON form: {"spacer": "14pt"}.
    • F8 Rule(…, width): a short rule; a rule wider than its container is TB7002.
    • F8 BorderBottom(width, color, space) on a paragraph style, with space from 0 to 31 pt.
    • F2 per-side padding: CellPadding(top, right, bottom, left), box Padding(…) and a cell's own Padding(…). JSON padding takes one to four values.
    • F2 per-side borders: Sides, OuterBorder(Sides.Top, …) on a table style, and a cell's own Border(sides, …). In JSON, a line or {top, right, bottom, left}.
    • F2/F3 table.Indent(…) and table.SpaceBefore(…).
    • F13: one Template Spacer per position. A box that ends with a conditional no longer grows.

    Notes

    • DOCX tblInd = indent + the left cell margin. The builder writes no compatibility mode, and in that layout LibreOffice and Word measure tblInd to the first cell's text. A LibreOffice round trip shows the same 17 pt shift in both formats.
    • Every construct has a LibreOffice → PDF round trip test that measures word and line positions.

    Deferred minors (from the final review)

    • tblInd uses the table style's left padding, not a first cell's own padding.
    • On a shared edge, the wider line wins; a thinner own line loses to the neighbour's rule.
    • DOCX space before a table is 1 pt more than in ODT; the existing space after has the same difference.
    • DOCX spacer and rule paragraphs have no pStyle.
    • A stale import message for cells.
    • DOCX rounds the border space to whole points.

    Open edge: a cell whose only content is a table inside a conditional gets two spacers (1 pt extra) when the branch is kept.

  3. vaceslav commented on Dec 2, 2026

    @vaceslav
    ContributorAuthor

    Done on feature/builder, merged to main in #316 and released in builder 0.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    builderenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions