Files
crosspoint-reader-mod/chat-summaries/2026-02-15_13-00-summary.md

50 lines
2.7 KiB
Markdown
Raw Permalink Normal View History

# Table Rendering Tweaks: Centering, Line Breaks, Padding
## Task Description
Three visual tweaks to the EPUB table rendering based on comparison with a Wikipedia article (Anders Celsius):
1. Full-width spanning rows (like "Anders Celsius", "Scientific career", "Signature") should be center-aligned
2. `<br>` tags and block elements within table cells should create actual line breaks (e.g., "(aged 42)" then "Uppsala, Sweden" on the next line)
3. Cell padding was too tight — text too close to grid borders
## Changes Made
### 1. Forced Line Breaks in Table Cells
**`lib/Epub/Epub/ParsedText.h`**:
- Added `std::vector<bool> forceBreakAfter` member to track mandatory line break positions
- Added `void addLineBreak()` public method
**`lib/Epub/Epub/ParsedText.cpp`**:
- `addWord()`: grows `forceBreakAfter` vector alongside other word vectors
- `addLineBreak()`: sets `forceBreakAfter.back() = true` on the last word
- `computeLineBreaks()` (DP algorithm): respects forced breaks — cannot extend a line past a forced break point, and forced breaks override continuation groups
- `computeHyphenatedLineBreaks()` (greedy): same — stops line at forced break, won't backtrack past one
- `hyphenateWordAtIndex()`: when splitting a word, transfers the forced break flag to the remainder (last part)
**`lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp`** — `startNewTextBlock()`:
- When `inTable`, instead of being a no-op, now: flushes the word buffer, calls `addLineBreak()` on the current ParsedText, and resets `nextWordContinues`
- This means `<br>`, `<p>`, `<div>` etc. within table cells now produce real visual line breaks
### 2. Center-Aligned Full-Width Spanning Cells
**`lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp`** — `processTable()`:
- Before laying out a cell's content, checks if `cell.colspan >= numCols` (spans full table width)
- If so, sets the cell's BlockStyle alignment to `CssTextAlign::Center`
- This correctly centers section headers and title rows in Wikipedia infobox-style tables
### 3. Increased Cell Padding
**`lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp`**:
- `TABLE_CELL_PAD_X`: 2 → 4 pixels (horizontal padding)
- Added `TABLE_CELL_PAD_Y = 2` pixels (vertical padding)
- Row height now includes `2 * TABLE_CELL_PAD_Y` for top/bottom padding
**`lib/Epub/Epub/Page.cpp`**:
- `TABLE_CELL_PADDING_X`: 2 → 4 pixels (matches parser constant)
- Added `TABLE_CELL_PADDING_Y = 2` pixels
- Cell text Y position now accounts for vertical padding: `baseY + 1 + TABLE_CELL_PADDING_Y`
## Follow-up Items
- The padding constants are duplicated between `ChapterHtmlSlimParser.cpp` and `Page.cpp` — could be unified into a shared header
- Vertical centering within cells (when a cell has fewer lines than the tallest cell) is not implemented