Add TXT file reader support

- Add Txt library for loading and parsing plain text files
- Create TxtReaderActivity with streaming page rendering
  - Uses 8KB chunks to handle large files without memory issues
  - Page index caching for fast re-open after sleep
  - Progress bar during initial indexing
  - Word wrapping with UTF-8 support
- Support cover images for TXT files
  - Priority: same filename as TXT (e.g., book.jpg for book.txt)
  - Fallback: cover.bmp/jpg/jpeg in same folder
  - Converts JPG to BMP using existing converter
- Update SleepActivity to show TXT cover images in Cover mode
- Add .txt extension to file browser filter
This commit is contained in:
Eunchurn Park
2026-01-04 21:19:30 +09:00
parent 14972b34cb
commit 98f14da65a
8 changed files with 977 additions and 2 deletions

33
lib/Txt/Txt.h Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include <SDCardManager.h>
#include <memory>
#include <string>
class Txt {
std::string filepath;
std::string cacheBasePath;
std::string cachePath;
bool loaded = false;
size_t fileSize = 0;
public:
explicit Txt(std::string path, std::string cacheBasePath);
bool load();
[[nodiscard]] const std::string& getPath() const { return filepath; }
[[nodiscard]] const std::string& getCachePath() const { return cachePath; }
[[nodiscard]] std::string getTitle() const;
[[nodiscard]] size_t getFileSize() const { return fileSize; }
void setupCacheDir() const;
// Cover image support - looks for cover.bmp/jpg/jpeg/png in same folder as txt file
[[nodiscard]] std::string getCoverBmpPath() const;
[[nodiscard]] bool generateCoverBmp() const;
[[nodiscard]] std::string findCoverImage() const;
// Read content from file
[[nodiscard]] bool readContent(uint8_t* buffer, size_t offset, size_t length) const;
};