some refactor

This commit is contained in:
Agel committed 2026-10-30 12:00:49 +01:00
1 parent 870bd1c0be
commit c25e8ddb90
20 files changed
+1204 -948

No files matched your search

+15 -6
View File
@@ -30,9 +30,9 @@ Full target format list:
| Format | Active | Approach |
|----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------|
| EPUB | Yes | Unzip (`ZipByteSource`) + parse OPF spine + CSS parser + Knuth-Plass text layout |
| FB2 | Yes | `Fb2ByteSource` (plain XML / ZIP) + encoding detection (BOM/XML/iconv) + semantic tag mapping + shared `DomChunkPipeline` + Knuth-Plass |
| TXT | Queued | `QTextStream` + encoding detection + paginate for `ChunkLayoutEngine` |
| EPUB | Yes | Unzip (`ZipByteSource`) + parse OPF spine + CSS parser + `HtmlBlockParser` to `DocumentChunkBuilder` + Knuth-Plass |
| FB2 | Yes | `Fb2ByteSource` (plain XML / ZIP) + `TextEncoding` + direct `DocumentChunkBuilder` streaming + Knuth-Plass |
| TXT | Queued | `TextEncoding` + direct streaming into `DocumentChunkBuilder` + Knuth-Plass |
| PDF | Planned | `QtPdf` module (`QPdfDocument`, Qt 6.4+) |
| DOC | Planned | `libwpd` or antiword subprocess |
| RTF | Planned | `QTextDocumentReader` or RTF→HTML |
@@ -159,8 +159,14 @@ public:
### 1. Text Mode (`ScrollPageView.qml`)
- `ReadingModel` manages a list of `ContentChunk`s (`QVector<ContentChunk>`).
- `EpubReader` cascades CSS onto the spine DOM and delegates directly to `HtmlBlockParser::parseChunks()`. This bypasses raw HTML string serialization and eliminates the double-parsing penalty, producing structured `ContentChunk` entities with pre-parsed `BlockItem`s, `wordCount`, `charCount`, and `unnestedContainers` for open containers spanning chunk boundaries.
- `HtmlBlockParser` normalizes paragraph typography across EPUB (`<div class="paragraph">` and `<p>`) and FB2 (`<p>`): unstyled paragraphs default to zero vertical margins (`marginTop = 0`, `marginBottom = 0`) and `2.0em` first-line indent (`textIndent = 2.0 * baseFontSize`), eliminating `ContainerStart`/`ContainerEnd` box allocation overhead and preventing blank vertical gaps between prose/dialogue lines. Explicit CSS margins in publisher stylesheets override this default. Shorthand `margin` and `padding` (1 to 4 token syntax) are fully parsed.
- **Format-Agnostic IR Pipeline (`DocumentIr.h`, `DocumentChunkBuilder.h`)**:
- Readers build intermediate representation (`ContentChunk`, `BlockItem`, `InlineItem`, `BoxStyle`) directly via `DocumentChunkBuilder` without allocating intermediate HTML DOM trees or serializing HTML strings.
- `DocumentChunkBuilder` streams and partitions content chunks (target ~512 chars), normalizes inter-word spacing, trims paragraph whitespace, and handles cross-chunk container splitting and reopening (`unnestedContainers`).
- `HtmlBlockParser` serves as the unified XML/HTML-to-IR converter streaming directly into `DocumentChunkBuilder`. It handles both XHTML (EPUB) and FictionBook (FB2) elements with native semantic tag defaults, CSS cascade, container nesting, and inline styling.
- `Fb2Reader` streams XML sections directly into `HtmlBlockParser::parseChunks()` without synthetic HTML DOM allocations.
- `EpubReader` resolves spine XHTML DOM nodes against in-memory CSS stylesheets (`Css::StyleSheet`) via `HtmlBlockParser::parseChunks()`, streaming directly into `DocumentChunkBuilder` with on-the-fly image URL resolution and zero DOM string mutations.
- `TextEncoding` provides unified BOM/XML/HTML/iconv encoding detection across `FB2` and queued formats (`TXT`, `MOBI`, `PDB`).
- `HtmlBlockParser` and `Fb2Reader` normalize paragraph typography across EPUB (`<div class="paragraph">` and `<p>`) and FB2 (`<p>`): unstyled paragraphs default to zero vertical margins (`marginTop = 0`, `marginBottom = 0`) and `2.0em` first-line indent (`textIndent = 2.0 * baseFontSize`), eliminating `ContainerStart`/`ContainerEnd` box allocation overhead and preventing blank vertical gaps between prose/dialogue lines. Explicit CSS margins in publisher stylesheets override this default. Shorthand `margin` and `padding` (1 to 4 token syntax) are fully parsed.
- 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.
@@ -241,6 +247,7 @@ src/
ImageExtensions.h
ImageScaling.h
ImageUrl.h/cpp
TextEncoding.h/cpp
WebImageProvider.h/cpp
comic/
ComicReader.h/cpp
@@ -256,7 +263,8 @@ src/
layout/
ChunkLayoutEngine.h/cpp
CssParser.h/cpp
DomChunkPipeline.h/cpp
DocumentChunkBuilder.h/cpp
DocumentIr.h
HtmlBlockParser.h/cpp
KnuthPlass.h/cpp
state/
@@ -302,6 +310,7 @@ tests/
Fb2ReaderTest.cpp
FolderReaderTest.cpp
ImageUrlTest.cpp
TextEncodingTest.cpp
WebImageProviderTest.cpp
reading/
KnuthPlassRenderingSpecTest.cpp