fb2 support

This commit is contained in:
Agel committed 2026-10-29 17:31:37 +01:00
1 parent 6fb7798476
commit c5439099f6
18 files changed
+2352 -54

No files matched your search

+12 -4
View File
@@ -23,8 +23,8 @@ Asteria Qt is a cross-platform desktop book/document reader built with Qt6/C++.
## Format Support
Active implementation: **EPUB, CBZ, CBR, Folder of images**
Queued for reimplementation on new render pipeline: **TXT, FB2**
Active implementation: **EPUB, FB2 (.fb2, .fbz, .fb2.zip), CBZ, CBR, Folder of images**
Queued for reimplementation on new render pipeline: **TXT**
Full target format list:
@@ -34,7 +34,7 @@ Full target format list:
| CBZ | Yes | Unzip (`ZipByteSource`) + `ComicReader` + `MangaPagination` (single/dual page spread) |
| CBR | Yes | `libarchive` (`RarByteSource`) + `ComicReader` + `MangaPagination` |
| Folder | Yes | Directory scan (`DirByteSource`) + `ComicReader` + `MangaPagination` |
| FB2 | Queued | `QXmlStreamReader` + convert sections to chunks for `ChunkLayoutEngine` |
| 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` |
| PDF | Planned | `QtPdf` module (`QPdfDocument`, Qt 6.4+) |
| DOC | Planned | `libwpd` or antiword subprocess |
@@ -121,7 +121,7 @@ Backend (C++) handles all file I/O, format parsing, text layout calculation, and
- **Image Providers**:
- `image://fileicon/...`: `FileIconProvider`
- `image://web/...`: `WebImageProvider`
- `image://cbz/...`, `image://cbr/...`, `image://dir/...`, `image://epub/...`: `EntryImageProvider` registered via `FormatRegistry::registerImageProviders`.
- `image://cbz/...`, `image://cbr/...`, `image://dir/...`, `image://epub/...`, `image://fb2/...`: `EntryImageProvider` registered via `FormatRegistry::registerImageProviders`.
- **`AppCoordinator`**: C++ coordinator wiring signals between `Book`, `ReadingModel`, `HistoryModel`, `UiState`, `ReadingPreferences`, and `AppState`.
---
@@ -159,6 +159,8 @@ 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.
- 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.
@@ -194,6 +196,7 @@ public:
Driven by `FormatSpec` table built in `main.cpp`:
- `FormatSpec::comic(ext, matchesDirectory, scheme, makeSource)`
- `FormatSpec::epub(makeSource)`
- `FormatSpec::fb2(ext, makeSource)`
Each format registers its file extension / directory matcher, reader factory, `IByteSource` factory, and image URL scheme in a single table entry.
---
@@ -228,6 +231,8 @@ src/
AuthorAttribution.h/cpp
EntryImageProvider.h/cpp
EpubReader.h/cpp
Fb2Reader.h/cpp
Fb2Types.h
FileIconProvider.h/cpp
FormatRegistry.h/cpp
HtmlEntities.h/cpp
@@ -240,6 +245,7 @@ src/
ComicReader.h/cpp
sources/
DirByteSource.h/cpp
Fb2ByteSource.h/cpp
RarByteSource.h/cpp
ZipByteSource.h/cpp
reading/
@@ -249,6 +255,7 @@ src/
layout/
ChunkLayoutEngine.h/cpp
CssParser.h/cpp
DomChunkPipeline.h/cpp
HtmlBlockParser.h/cpp
KnuthPlass.h/cpp
state/
@@ -291,6 +298,7 @@ tests/
formats/
CbzReaderTest.cpp
EpubReaderTest.cpp
Fb2ReaderTest.cpp
FolderReaderTest.cpp
ImageUrlTest.cpp
WebImageProviderTest.cpp