mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-06 07:37:37 +03:00
## Summary * **What is the goal of this PR?** Add support for reading plain text (.txt) files, enabling users to browse, read, and track progress in TXT documents alongside existing EPUB and XTC formats. * **What changes are included?** - New Txt library for loading and parsing plain text files - New TxtReaderActivity with streaming page rendering using 8KB chunks to handle large files without memory issues on ESP32-C3 - Page index caching system (index.bin) for instant re-open after sleep or app restart - Progress bar UI during initial file indexing (matching EPUB style) - Word wrapping with proper UTF-8 support - Cover image support for TXT files: - Primary: image with same filename as TXT (e.g., book.jpg for book.txt) - Fallback: cover.bmp/jpg/jpeg in the same folder - JPG to BMP conversion using existing converter - Sleep screen cover mode now works with TXT files - File browser now shows .txt files ## Additional Context * Add any other information that might be helpful for the reviewer * Memory constraints: The streaming approach was necessary because ESP32-C3 only has 320KB RAM. A 700KB TXT file cannot be loaded entirely into memory, so we read 8KB chunks and build a page offset index instead. * Cache invalidation: The page index cache automatically invalidates when file size, viewport width, or lines per page changes (e.g., font size or orientation change). * Performance: First open requires indexing (with progress bar), subsequent opens load from cache instantly. * Cover image format: PNG is detected but not supported for conversion (no PNG decoder available). Only BMP and JPG/JPEG work.
35 lines
1.3 KiB
C++
35 lines
1.3 KiB
C++
#pragma once
|
|
#include <memory>
|
|
|
|
#include "../ActivityWithSubactivity.h"
|
|
|
|
class Epub;
|
|
class Xtc;
|
|
class Txt;
|
|
|
|
class ReaderActivity final : public ActivityWithSubactivity {
|
|
std::string initialBookPath;
|
|
std::string currentBookPath; // Track current book path for navigation
|
|
const std::function<void()> onGoBack;
|
|
static std::unique_ptr<Epub> loadEpub(const std::string& path);
|
|
static std::unique_ptr<Xtc> loadXtc(const std::string& path);
|
|
static std::unique_ptr<Txt> loadTxt(const std::string& path);
|
|
static bool isXtcFile(const std::string& path);
|
|
static bool isTxtFile(const std::string& path);
|
|
|
|
static std::string extractFolderPath(const std::string& filePath);
|
|
void onSelectBookFile(const std::string& path);
|
|
void onGoToFileSelection(const std::string& fromBookPath = "");
|
|
void onGoToEpubReader(std::unique_ptr<Epub> epub);
|
|
void onGoToXtcReader(std::unique_ptr<Xtc> xtc);
|
|
void onGoToTxtReader(std::unique_ptr<Txt> txt);
|
|
|
|
public:
|
|
explicit ReaderActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string initialBookPath,
|
|
const std::function<void()>& onGoBack)
|
|
: ActivityWithSubactivity("Reader", renderer, mappedInput),
|
|
initialBookPath(std::move(initialBookPath)),
|
|
onGoBack(onGoBack) {}
|
|
void onEnter() override;
|
|
};
|