Files
crosspoint-reader-mod/chat-summaries/2026-02-15_14-30-summary.md

33 lines
2.2 KiB
Markdown
Raw Normal View History

# Table Width Hints: HTML Attributes + CSS Width Support
## Task Description
Add support for author-specified column widths from HTML `width` attributes and CSS `width` property on `<table>`, `<col>`, `<td>`, and `<th>` elements, using them as hints for column sizing in `processTable()`.
## Changes Made
### 1. CSS Layer (`lib/Epub/Epub/css/CssStyle.h`, `lib/Epub/Epub/css/CssParser.cpp`)
- Added `width` bit to `CssPropertyFlags`
- Added `CssLength width` field to `CssStyle`
- Added `hasWidth()` convenience method
- Updated `applyOver()`, `reset()`, `clearAll()`, `anySet()` to include `width`
- Added `else if (propName == "width")` case to `CssParser::parseDeclarations()` using `interpretLength()`
### 2. Table Data (`lib/Epub/Epub/TableData.h`)
- Added `CssLength widthHint` and `bool hasWidthHint` to `TableCell`
- Added `std::vector<CssLength> colWidthHints` to `TableData` (from `<col>` tags)
- Added `#include "css/CssStyle.h"` for `CssLength`
### 3. Parser (`lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp`)
- Removed `"col"` from `TABLE_SKIP_TAGS` (was being skipped entirely)
- Added `parseHtmlWidthAttr()` helper: parses HTML `width="200"` (pixels) and `width="50%"` (percent) into `CssLength`
- Added `<col>` handling in `startElement`: parses `width` HTML attribute and `style` CSS, pushes to `tableData->colWidthHints`
- Updated `<td>`/`<th>` handling: now parses `width` HTML attribute, `style` attribute, and stylesheet CSS width (via `resolveStyle`). CSS takes priority over HTML attribute. Stored in `TableCell::widthHint`
### 4. Layout (`processTable()`)
- Added step 3a: resolves width hints per column. Priority: `<col>` hints > max cell hint (colspan=1 only). Percentages resolve relative to available content width.
- Modified step 3b: hinted columns get their resolved pixel width (clamped to min col width). If all hinted widths exceed available space, they're scaled down proportionally. Unhinted columns use the existing two-pass fair-share algorithm on the remaining space.
## Follow-up Items
- The `<colgroup>` tag is still skipped entirely; `<col>` tags within `<colgroup>` won't be reached. Could un-skip `<colgroup>` (make it transparent like `<thead>`/`<tbody>`) if needed.
- `rowspan` is not yet supported.