fixed paragraph layout to handle forced breaks

This commit is contained in:
Agel committed 2026-11-01 12:01:26 +01:00
1 parent 8782a3be8a
commit 1ad2f5446b
6 files changed
+142 -11

No files matched your search

+2 -1
View File
@@ -190,7 +190,8 @@ public:
- Headings (`h1`..`h6`) default to left-aligned (`TextAlign::Left`) without first-line indentation (`textIndent = 0`). In `Fb2Reader`, `<title>` flattens child `<p>` lines separated by `<br/>` with `text-align: left; text-indent: 0;`, preventing nested paragraph indent on titles. Scene transitions via FB2 `<empty-line>` use explicit margins to provide intended section gaps.
- When viewport geometry or font preferences change, `ReadingModel::updateLayoutMetrics()` runs `ChunkLayoutEngine` off-thread:
- Pre-parsed `BlockItem`s in `ContentChunk` scale dynamically with user font preferences in `ChunkLayoutEngine::prepareBlocks()` with zero HTML/XML re-parsing.
- `KnuthPlass` computes optimal justified/aligned line breaks.
- `KnuthPlass` computes optimal justified/aligned line breaks. Inline forced breaks (`<br/>`, `InlineItem::Kind::LineBreak`) use `finishLine()` to append infinite stretch glue (`kInfiniteStretch`), ensuring short lines ending at `<br/>` are not justified to full width and do not push the paragraph into loose/emergency fallback passes.
- Overly stretched line fallback: When a line's stretch ratio in a justified paragraph exceeds `tolerance` (`line.ratio > 2.0`), `ChunkLayoutEngine` falls back to natural inter-word spacing (left alignment) rather than stretching words across the viewport with large gaps.
- `BookImageResolver` resolves embedded image dimensions and URLs.
- Off-thread calculation stores `ChunkLayout` and pixel heights.
- **Two-Phase Visible-First Layout**: On book open and font changes, `ReadingModel::startLayoutMeasurement()` computes layout for the visible window around the anchor chunk synchronously (<1ms) and emits `restoreReady(chunkIndex, intraOffset)` immediately so the visible screen renders on the first frame, while the background thread computes remaining off-screen chunks and updates only non-visible model ranges. On-demand layout guards ensure any chunk scrolled to before background completion is measured instantly.