Review changes

This commit is contained in:
jpirnay
2026-03-04 12:27:33 +01:00
parent 08cdd06c41
commit d0d4dc5c18
2 changed files with 17 additions and 6 deletions
+4 -1
View File
@@ -8,6 +8,8 @@
#include <I18n.h>
#include <Logging.h>
#include <memory>
#include "CrossPointSettings.h"
#include "CrossPointState.h"
#include "EpubReaderChapterSelectionActivity.h"
@@ -22,6 +24,7 @@
#include "fontIds.h"
#include "util/ScreenshotUtil.h"
namespace {
// pagesPerRefresh now comes from SETTINGS.getRefreshFrequency()
constexpr unsigned long skipChapterMs = 700;
@@ -870,7 +873,7 @@ bool EpubReaderActivity::drawCurrentPageToBuffer(const std::string& filePath, Gf
// Load or rebuild the section cache. Rebuilding is needed when the cache is missing or stale
// (e.g. after a firmware update). A no-op popup callback avoids any UI during sleep preparation.
auto section = std::unique_ptr<Section>(new Section(epub, spineIndex, renderer));
auto section = std::make_unique<Section>(epub, spineIndex, renderer);
if (!section->loadSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(),
SETTINGS.extraParagraphSpacing, SETTINGS.paragraphAlignment, viewportWidth,
viewportHeight, SETTINGS.hyphenationEnabled, SETTINGS.embeddedStyle)) {
+13 -5
View File
@@ -56,7 +56,10 @@ size_t parseAndWrapLines(const uint8_t* buffer, size_t chunkSize, size_t fileOff
while (breakPos > 0 && (line[breakPos] & 0xC0) == 0x80) breakPos--;
}
}
if (breakPos == 0) breakPos = 1;
if (breakPos == 0) {
breakPos = 1;
while (breakPos < line.length() && (line[breakPos] & 0xC0) == 0x80) breakPos++;
}
outLines.push_back(line.substr(0, breakPos));
size_t skipChars = breakPos;
if (breakPos < line.length() && line[breakPos] == ' ') skipChars++;
@@ -526,8 +529,9 @@ bool TxtReaderActivity::loadPageIndexCache() {
uint32_t numPages;
serialization::readPod(f, numPages);
if (numPages > MAX_CACHE_PAGES) {
LOG_ERR("TRS", "Cache numPages %u exceeds cap %u, truncating", numPages, MAX_CACHE_PAGES);
numPages = MAX_CACHE_PAGES;
LOG_ERR("TRS", "Cache numPages %u exceeds cap %u, cache invalid", numPages, MAX_CACHE_PAGES);
f.close();
return false;
}
// Read page offsets
@@ -672,8 +676,12 @@ bool TxtReaderActivity::drawCurrentPageToBuffer(const std::string& filePath, Gfx
uint32_t off;
serialization::readPod(cacheFile, off);
if (static_cast<int>(i) == savedPage) {
savedOffset = off;
offsetKnown = true;
if (off < txt.getFileSize()) {
savedOffset = off;
offsetKnown = true;
} else {
LOG_DBG("SLP", "TXT: index.bin offset %u out of range (fileSize=%u), ignoring", off, txt.getFileSize());
}
}
}
} else {