added txt support

This commit is contained in:
Agel committed 2026-03-15 22:18:26 +01:00
1 parent 64a70bc4cf
commit 21656a3e9c
10 files changed
+441 -120

No files matched your search

+11 -57
View File
@@ -35,57 +35,9 @@ Full target format list (derived from actual library inventory):
> ACSM files are Adobe DRM tokens — not directly readable; skip.
> PPT/XLS and source code files (.py, .cs, etc.) are in the library from programming books; no need to render them.
## Installing Dependencies
## Build & Install
### Linux (Ubuntu/Debian)
```bash
sudo scripts/install-deps-ubuntu.sh
```
Installs: Qt6 dev packages (base, QML/Quick, PDF, SVG, shader tools), uchardet, QuaZip, minizip, DjVuLibre, libwpd.
> **Current status:** Qt6 runtime (6.4.2) is present but dev headers are not yet installed. Run the script above before attempting to build.
### Windows
Run in an elevated PowerShell:
```powershell
scripts\install-deps-windows.ps1
```
Installs: VS Build Tools 2022, CMake, Ninja, Git, vcpkg, and third-party libs via vcpkg. **Qt 6 must be installed manually** via the Qt Online Installer (qt.io/download-open-source) — select MSVC 2022 64-bit + Qt PDF + Qt SVG.
After Qt is installed, pass its path to CMake:
```powershell
cmake -B build -DCMAKE_PREFIX_PATH="C:\Qt\6.x.x\msvc2022_64" `
-DCMAKE_TOOLCHAIN_FILE="C:\vcpkg\scripts\buildsystems\vcpkg.cmake"
```
## Build
```bash
# Configure (Linux — Qt6 found automatically after running install script)
cmake -B build -DCMAKE_BUILD_TYPE=Debug
# Build
cmake --build build --parallel
# Run
./build/asteria-qt # Linux
./build/asteria-qt.exe # Windows
# Release
cmake -B build-release -DCMAKE_BUILD_TYPE=Release
cmake --build build-release --parallel
```
Tests:
```bash
ctest --test-dir build --output-on-failure
```
See [README.md](README.md) for setup instructions, dependency installation, and IDE-specific build guides.
## Test-Driven Development
@@ -114,14 +66,14 @@ ctest --test-dir build --output-on-failure
| Object | Responsibility |
|---|---|
| `BookController` | Open/close book, owns reader (via `ReaderFactory`), exposes metadata (title, author), TOC |
| `ReadingModel` | Current chapter content, position, next/prev navigation, progress % |
| `ReadingModel` | QAbstractListModel exposing chapter chunks (ContentRole), position, next/prev navigation, progress % |
| `AppState` | Window geometry, last file, preferences (`QSettings`) |
Sidebar state, header state, etc. stay as pure QML properties — no C++ needed.
### Content Model
All format readers produce normalized HTML content organized into chapters. The content model is defined in `FormatReader.h`:
All format readers produce normalized HTML content organized into chapters. Each chapter's content is split into chunks (a `QStringList`) at the reader level, where the format structure is known. This enables virtualized rendering via `ListView` in QML. The content model is defined in `FormatReader.h`:
```cpp
struct TocEntry {
@@ -133,7 +85,7 @@ struct TocEntry {
struct Chapter {
int index;
QString title;
QString contentHtml; // normalized HTML
QStringList contentChunks; // standalone HTML fragments
};
```
@@ -147,7 +99,9 @@ struct Chapter {
Chapter mapping by format: TXT = 1 chapter (whole file). FB2 = `<section>` elements. EPUB = spine items. PDF = outline entries or individual pages.
`PageView.qml` renders one chapter at a time via `Text { textFormat: Text.RichText }`. Pagination within a chapter (if ever needed) is a QML-only concern.
**Chunking:** Each format reader splits content into chunks natively — chunking at the reader level is trivial and reliable compared to splitting arbitrary HTML. TxtReader splits raw text at ~4096 character boundaries (preferring `\n`, falling back to whitespace), then converts each chunk to HTML independently. Each chunk is a standalone HTML fragment (contains its own `<p>` tags).
**ReadingModel** is a `QAbstractListModel` exposing chunks via `ContentRole`. `PageView.qml` renders chunks in a `ListView` with `cacheBuffer` for seamless scrolling — no visible seams between chunks.
### Reader Factory
@@ -159,7 +113,7 @@ Chapter mapping by format: TXT = 1 chapter (whole file). FB2 = `<section>` eleme
### Error Handling
`FormatReader::open()` returns `bool`. Failed readers expose `QString lastError()`. `BookController` translates errors to a `QString errorMessage` property + `error(QString)` signal. QML shows an `ErrorBanner.qml` component. Error cases: file not found, unsupported format, corrupt archive, encoding failure, permission denied.
`FormatReader::open()` returns `bool`. Failed readers expose `QString lastError()`. `BookController` translates errors to a `QString errorMessage` property + `error(QString)` signal. QML shows an `ErrorPopup.qml` component. Error cases: file not found, unsupported format, corrupt archive, encoding failure, permission denied.
### File Structure
@@ -190,9 +144,9 @@ src/
components/
Header.qml
SideBar.qml # Renders TOC from BookController
PageView.qml # Renders chapter HTML from ReadingModel
PageView.qml # ListView-based virtualized rendering of ReadingModel chunks
Footer.qml
ErrorBanner.qml # Error display popup
ErrorPopup.qml # Error display popup
pages/
StarterPage.qml
ReaderPage.qml