Merge branch 'master' of https://github.com/jpirnay/crosspoint-reader into feat-expose-override
This commit is contained in:
@@ -19,13 +19,16 @@
|
||||
#include <esp_system.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "CrossPointSettings.h"
|
||||
#include "CrossPointState.h"
|
||||
#include "EpubReaderChapterSelectionActivity.h"
|
||||
#include "EpubReaderFootnotesActivity.h"
|
||||
#include "EpubReaderPercentSelectionActivity.h"
|
||||
#include "EpubReaderPrintedPageInputActivity.h"
|
||||
#include "EpubRenderBenchmarkActivity.h"
|
||||
#include "FinishedBookActivity.h"
|
||||
#include "GlobalBookmarkIndex.h"
|
||||
@@ -48,6 +51,20 @@
|
||||
namespace {
|
||||
// pagesPerRefresh now comes from SETTINGS.getRefreshFrequency()
|
||||
constexpr unsigned long skipChapterMs = 700;
|
||||
|
||||
// Parse a printed-page label as a non-negative integer. Returns nullopt for empty strings,
|
||||
// strings with non-digit characters (e.g. roman "iv"), and overflow. Used both to gate the
|
||||
// "go to printed page" menu item and to compute min/max for the numeric input.
|
||||
std::optional<int> parsePrintedPageLabel(const std::string& label) {
|
||||
if (label.empty()) return std::nullopt;
|
||||
int value = 0;
|
||||
for (char c : label) {
|
||||
if (c < '0' || c > '9') return std::nullopt;
|
||||
value = value * 10 + (c - '0');
|
||||
if (value > 999999) return std::nullopt; // sanity
|
||||
}
|
||||
return value;
|
||||
}
|
||||
// pages per minute, first item is 1 to prevent division by zero if accessed
|
||||
constexpr int PAGE_TURN_LABELS[] = {1, 1, 3, 6, 12};
|
||||
|
||||
@@ -105,6 +122,30 @@ void logReaderMemSnapshot(const char* stage) {
|
||||
inline void logReaderMemSnapshot(const char*) {}
|
||||
#endif
|
||||
|
||||
// Integrity bisector. Logs at every probe site (unconditional, not gated) and
|
||||
// fires an ERR when integrity transitions from ok -> fail so we can pinpoint
|
||||
// which render phase corrupts the heap. Free/contig included so we can see if
|
||||
// the corruption coincides with a specific allocation pattern. Calling
|
||||
// heap_caps_check_integrity_all is ~O(blocks) — not free but fine at phase
|
||||
// boundaries during onEnter / first render.
|
||||
void logIntegrityProbe(const char* stage) {
|
||||
static bool sLastOk = true;
|
||||
const bool ok = heap_caps_check_integrity_all(true);
|
||||
const uint32_t freeHeap = esp_get_free_heap_size();
|
||||
const uint32_t contigHeap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT);
|
||||
if (ok != sLastOk) {
|
||||
if (ok) {
|
||||
LOG_DBG("INTG", "[%s] integrity recovered (free=%lu contig=%lu)", stage, freeHeap, contigHeap);
|
||||
} else {
|
||||
LOG_ERR("INTG", "[%s] integrity FAIL — corruption introduced here (free=%lu contig=%lu)", stage, freeHeap,
|
||||
contigHeap);
|
||||
}
|
||||
sLastOk = ok;
|
||||
} else {
|
||||
LOG_DBG("INTG", "[%s] %s free=%lu contig=%lu", stage, ok ? "ok" : "fail", freeHeap, contigHeap);
|
||||
}
|
||||
}
|
||||
|
||||
// Tiled grayscale: render each plane band-by-band into a small scratch and
|
||||
// stream straight to the controller, leaving the BW framebuffer intact so no
|
||||
// storeBwBuffer / restoreBwBuffer is needed. Controller RAM is re-synced from
|
||||
@@ -157,15 +198,20 @@ bool runTiledGrayscalePass(GfxRenderer& renderer, const Page& page, int fontId,
|
||||
}
|
||||
};
|
||||
|
||||
logIntegrityProbe("tiledGray_after_scratchAlloc");
|
||||
renderPlane(GfxRenderer::GRAYSCALE_LSB, true);
|
||||
logIntegrityProbe("tiledGray_after_lsbPlane");
|
||||
renderPlane(GfxRenderer::GRAYSCALE_MSB, false);
|
||||
logIntegrityProbe("tiledGray_after_msbPlane");
|
||||
|
||||
renderer.setRenderMode(GfxRenderer::BW);
|
||||
renderer.displayGrayBuffer();
|
||||
logIntegrityProbe("tiledGray_after_displayGrayBuffer");
|
||||
|
||||
// BW framebuffer is intact; re-sync controller RAM for the next differential
|
||||
// page turn directly from it.
|
||||
renderer.cleanupGrayscaleWithFrameBuffer();
|
||||
logIntegrityProbe("tiledGray_after_cleanup");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -254,6 +300,7 @@ int getImageOnlyPageYOffset(const Page& page, const int viewportHeight) {
|
||||
void EpubReaderActivity::onEnter() {
|
||||
Activity::onEnter();
|
||||
logReaderMemSnapshot("onEnter_begin");
|
||||
logIntegrityProbe("onEnter_begin");
|
||||
|
||||
// Drop any input events that arrived from the activity that launched us (e.g. a wake-up power
|
||||
// button hold) before they reach detectPageTurn() — see ReaderUtils::InputDrainGuard.
|
||||
@@ -273,10 +320,13 @@ void EpubReaderActivity::onEnter() {
|
||||
|
||||
epub->setupCacheDir();
|
||||
logReaderMemSnapshot("onEnter_after_setupCacheDir");
|
||||
applyPendingSyncSession();
|
||||
applyPendingBookmarkJump();
|
||||
logReaderMemSnapshot("onEnter_after_pending_sync");
|
||||
|
||||
// Load the persistent baseline (progress.bin) first. Pending session state
|
||||
// (sync result, bookmark jump) is then overlaid on top — this is the only order
|
||||
// that lets a Kind::Paragraph / Kind::ListItem navTarget set by applyPendingSyncSession
|
||||
// survive into render(). The previous order (apply then load) clobbered the LUT
|
||||
// target with Kind::Page from progress.bin, which is why XPath-precision sync
|
||||
// silently degraded to the rough page estimate.
|
||||
FsFile f;
|
||||
if (Storage.openFileForRead("ERS", epub->getCachePath() + "/progress.bin", f)) {
|
||||
uint8_t data[6];
|
||||
@@ -301,6 +351,10 @@ void EpubReaderActivity::onEnter() {
|
||||
navTarget = NavigationTarget::makePage(0);
|
||||
}
|
||||
|
||||
applyPendingSyncSession();
|
||||
applyPendingBookmarkJump();
|
||||
logReaderMemSnapshot("onEnter_after_pending_sync");
|
||||
|
||||
if (currentSpineIndex == 0) {
|
||||
int textSpineIndex = epub->getSpineIndexForTextReference();
|
||||
if (textSpineIndex != 0) {
|
||||
@@ -684,6 +738,67 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction
|
||||
});
|
||||
break;
|
||||
}
|
||||
case EpubReaderMenuActivity::MenuAction::GO_TO_PRINTED_PAGE: {
|
||||
if (!epub) break;
|
||||
auto entries = epub->loadPrintedPageList();
|
||||
// Compute the integer label range from parseable entries; non-integer labels are
|
||||
// ignored (the dialog is numeric-only).
|
||||
int minLabel = std::numeric_limits<int>::max();
|
||||
int maxLabel = std::numeric_limits<int>::min();
|
||||
for (const auto& entry : entries) {
|
||||
if (const auto n = parsePrintedPageLabel(entry.label)) {
|
||||
if (*n < minLabel) minLabel = *n;
|
||||
if (*n > maxLabel) maxLabel = *n;
|
||||
}
|
||||
}
|
||||
if (maxLabel < minLabel) break; // no integer labels — shouldn't happen if menu item was shown
|
||||
|
||||
// Pre-fill with the printed page the reader is currently on (or the nearest one before
|
||||
// it — rendered device pages rarely carry an anchor themselves, but they sit between
|
||||
// two printed pages, so the closest prior anchor is the "you're here" hint). Falls
|
||||
// back to the lowest integer label in the book if no prior anchor exists.
|
||||
int initialValue = minLabel;
|
||||
if (section) {
|
||||
if (const auto rawLabel =
|
||||
section->getNearestPrintedPageLabelAtOrBefore(static_cast<uint16_t>(section->currentPage))) {
|
||||
if (const auto n = parsePrintedPageLabel(*rawLabel)) {
|
||||
initialValue = *n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startActivityForResult(
|
||||
std::make_unique<EpubReaderPrintedPageInputActivity>(renderer, mappedInput, initialValue, minLabel, maxLabel),
|
||||
[this, entries = std::move(entries)](const ActivityResult& result) {
|
||||
if (result.isCancelled) return;
|
||||
const auto& pick = std::get<PrintedPageResult>(result.data);
|
||||
// Resolve the typed label back to a (href, anchor) by linear scan. Entries are
|
||||
// small (typically <500 even for long books) and this fires once per user action.
|
||||
for (const auto& entry : entries) {
|
||||
const auto entryLabelValue = parsePrintedPageLabel(entry.label);
|
||||
const auto pickLabelValue = parsePrintedPageLabel(pick.label);
|
||||
if (entry.label == pick.label ||
|
||||
(entryLabelValue && pickLabelValue && *entryLabelValue == *pickLabelValue)) {
|
||||
const int spineIdx = epub->resolveHrefToSpineIndex(entry.href);
|
||||
if (spineIdx < 0) {
|
||||
LOG_DBG("ERS", "printed-page jump: could not resolve spine for href=%s", entry.href.c_str());
|
||||
return;
|
||||
}
|
||||
{
|
||||
RenderLock lock(*this);
|
||||
currentSpineIndex = spineIdx;
|
||||
navTarget =
|
||||
entry.anchor.empty() ? NavigationTarget::makePage(0) : NavigationTarget::makeAnchor(entry.anchor);
|
||||
section.reset();
|
||||
}
|
||||
requestUpdate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG_DBG("ERS", "printed-page jump: label '%s' not found in pagelist", pick.label.c_str());
|
||||
});
|
||||
break;
|
||||
}
|
||||
case EpubReaderMenuActivity::MenuAction::DISPLAY_QR: {
|
||||
if (section && section->currentPage >= 0 && section->currentPage < section->pageCount) {
|
||||
auto p = section->loadPageFromSectionFile();
|
||||
@@ -1186,7 +1301,9 @@ void EpubReaderActivity::applyPendingSyncSession() {
|
||||
restorePage = 0;
|
||||
}
|
||||
|
||||
// Build the navigation target from the sync result.
|
||||
// Build the navigation target from the sync result. For LUT-anchored targets the
|
||||
// estimated restorePage is plumbed through as fallbackPage so a LUT miss in the
|
||||
// target spine still lands the user on a sensible page rather than page 0.
|
||||
NavigationTarget restoreTarget;
|
||||
if (sync.outcome == KOReaderSyncOutcomeState::APPLIED_REMOTE) {
|
||||
const int spineCount = epub->getSpineItemsCount();
|
||||
@@ -1199,11 +1316,11 @@ void EpubReaderActivity::applyPendingSyncSession() {
|
||||
restorePage = sync.resultPage;
|
||||
}
|
||||
if (sync.resultHasListItemIndex) {
|
||||
restoreTarget = NavigationTarget::makeListItem(sync.resultListItemIndex);
|
||||
restoreTarget = NavigationTarget::makeListItem(sync.resultListItemIndex, restorePage);
|
||||
LOG_DBG("ERS", "Applied synced remote position: spine=%d page=%d li[%u]", restoreSpineIndex, restorePage,
|
||||
sync.resultListItemIndex);
|
||||
} else if (sync.resultHasParagraphIndex) {
|
||||
restoreTarget = NavigationTarget::makeParagraph(sync.resultParagraphIndex);
|
||||
restoreTarget = NavigationTarget::makeParagraph(sync.resultParagraphIndex, restorePage);
|
||||
LOG_DBG("ERS", "Applied synced remote position: spine=%d page=%d p[%u]", restoreSpineIndex, restorePage,
|
||||
sync.resultParagraphIndex);
|
||||
} else {
|
||||
@@ -1217,21 +1334,26 @@ void EpubReaderActivity::applyPendingSyncSession() {
|
||||
|
||||
// sync.totalPagesInSpine is the page count of the local spine at launch time.
|
||||
// When the restore targets a different spine, that count is meaningless for
|
||||
// rescaling. Store 0 to disable rescaling; the LUT lookup handles precise positioning.
|
||||
// rescaling the fallbackPage estimate (which was estimated from cross-spine
|
||||
// density anyway). Store 0 to disable rescaling — the LUT lookup is the precise
|
||||
// path, and the cross-spine fallback can't usefully be rescaled here.
|
||||
const int restorePageCount = (restoreSpineIndex == sync.spineIndex) ? sync.totalPagesInSpine : 0;
|
||||
restoreTarget.cachedPageCount = restorePageCount;
|
||||
restoreTarget.cachedSpineIdx = restoreSpineIndex;
|
||||
|
||||
// Transient write — the next render's saveProgress() supplies the real percent before the user
|
||||
// can return to the home screen, so a placeholder 0 here is harmless.
|
||||
if (writeReaderProgressCache(epub->getCachePath(), restoreSpineIndex, restorePage, restorePageCount, 0)) {
|
||||
navTarget = restoreTarget;
|
||||
// Seed live state directly — the previous write-then-reload-from-disk pattern relied
|
||||
// on progress.bin being read after this function ran, which clobbered the LUT target.
|
||||
// Live-state seeding is authoritative; the persistent write below is just for crash
|
||||
// recovery so a power loss before the next saveProgress() doesn't lose the synced
|
||||
// spine/page. The next render's saveProgress() supplies the real percent before
|
||||
// the user can return to the home screen.
|
||||
currentSpineIndex = restoreSpineIndex;
|
||||
navTarget = restoreTarget;
|
||||
if (!writeReaderProgressCache(epub->getCachePath(), restoreSpineIndex, restorePage, restorePageCount, 0)) {
|
||||
LOG_ERR("ERS", "Failed to persist sync restore to progress.bin; live state still seeded");
|
||||
} else {
|
||||
LOG_DBG("ERS", "Prepared progress.bin for sync restore: spine=%d page=%d/%d", restoreSpineIndex, restorePage,
|
||||
sync.totalPagesInSpine);
|
||||
} else {
|
||||
// Fall back to directly seeding live state if cache write fails.
|
||||
currentSpineIndex = restoreSpineIndex;
|
||||
navTarget = restoreTarget;
|
||||
}
|
||||
|
||||
sync.clear();
|
||||
@@ -1250,14 +1372,13 @@ void EpubReaderActivity::applyPendingBookmarkJump() {
|
||||
jump.spineIndex = 0;
|
||||
jump.pageNumber = 0;
|
||||
}
|
||||
// Transient write before initializeReader; saveProgress() overwrites with the real percent.
|
||||
if (writeReaderProgressCache(epub->getCachePath(), jump.spineIndex, jump.pageNumber, 0, 0)) {
|
||||
navTarget = NavigationTarget::makePage(jump.pageNumber);
|
||||
navTarget.cachedSpineIdx = jump.spineIndex;
|
||||
} else {
|
||||
currentSpineIndex = jump.spineIndex;
|
||||
navTarget = NavigationTarget::makePage(jump.pageNumber);
|
||||
navTarget.cachedSpineIdx = jump.spineIndex;
|
||||
// Seed live state directly; the persistent write is for crash recovery only.
|
||||
// saveProgress() on the next render overwrites with the real percent.
|
||||
currentSpineIndex = jump.spineIndex;
|
||||
navTarget = NavigationTarget::makePage(jump.pageNumber);
|
||||
navTarget.cachedSpineIdx = jump.spineIndex;
|
||||
if (!writeReaderProgressCache(epub->getCachePath(), jump.spineIndex, jump.pageNumber, 0, 0)) {
|
||||
LOG_ERR("ERS", "Failed to persist bookmark jump to progress.bin; live state still seeded");
|
||||
}
|
||||
jump.clear();
|
||||
APP_STATE.saveToFile();
|
||||
@@ -1502,58 +1623,95 @@ int EpubReaderActivity::getEffectiveReaderFontId() const {
|
||||
}
|
||||
|
||||
void EpubReaderActivity::NavigationTarget::resolveInto(Section& sec, int spineIndex) const {
|
||||
if (kind == Kind::LastPage) {
|
||||
sec.currentPage = (sec.pageCount > 0) ? sec.pageCount - 1 : 0;
|
||||
return;
|
||||
}
|
||||
if (kind == Kind::TocIndex) {
|
||||
if (const auto p = sec.getPageForTocIndex(tocIndex)) sec.currentPage = *p;
|
||||
return;
|
||||
}
|
||||
if (kind == Kind::Anchor) {
|
||||
if (const auto p = sec.getPageForAnchor(anchorStr)) {
|
||||
sec.currentPage = *p;
|
||||
LOG_DBG("ERS", "Resolved anchor '%s' -> page %d", anchorStr.c_str(), *p);
|
||||
} else {
|
||||
LOG_DBG("ERS", "Anchor '%s' not found in section", anchorStr.c_str());
|
||||
// Resolve to a baseline page first. Each branch records whether it produced a
|
||||
// precise page (LUT/anchor hit, percent jump, explicit page) or only an estimate.
|
||||
// The estimate path runs cross-spine rescale + clamp at the end; the precise path
|
||||
// skips both because LUT pages are already in the target spine's coordinate system.
|
||||
bool isEstimate = false;
|
||||
|
||||
switch (kind) {
|
||||
case Kind::LastPage: {
|
||||
sec.currentPage = (sec.pageCount > 0) ? sec.pageCount - 1 : 0;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (kind == Kind::ListItem) {
|
||||
if (const auto p = sec.getPageForListItemIndex(lutIndex)) {
|
||||
sec.currentPage = *p;
|
||||
LOG_DBG("ERS", "Resolved li[%u] -> page %d", lutIndex, *p);
|
||||
} else {
|
||||
LOG_DBG("ERS", "Li index %u not found in section LUT", lutIndex);
|
||||
|
||||
case Kind::TocIndex: {
|
||||
if (const auto p = sec.getPageForTocIndex(tocIndex)) {
|
||||
sec.currentPage = *p;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (kind == Kind::Paragraph) {
|
||||
if (const auto p = sec.getPageForParagraphIndex(lutIndex)) {
|
||||
sec.currentPage = *p;
|
||||
LOG_DBG("ERS", "Resolved p[%u] -> page %d", lutIndex, *p);
|
||||
} else {
|
||||
LOG_DBG("ERS", "Paragraph LUT miss, using page %d", sec.currentPage);
|
||||
|
||||
case Kind::Anchor: {
|
||||
if (const auto p = sec.getPageForAnchor(anchorStr)) {
|
||||
sec.currentPage = *p;
|
||||
LOG_DBG("ERS", "Resolved anchor '%s' -> page %d", anchorStr.c_str(), *p);
|
||||
} else {
|
||||
LOG_DBG("ERS", "Anchor '%s' not found; using fallback page %d", anchorStr.c_str(), fallbackPage);
|
||||
sec.currentPage = fallbackPage;
|
||||
isEstimate = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (kind == Kind::Percent) {
|
||||
if (sec.pageCount > 0) {
|
||||
int newPage = static_cast<int>(spineProgress * static_cast<float>(sec.pageCount));
|
||||
if (newPage >= sec.pageCount) newPage = sec.pageCount - 1;
|
||||
sec.currentPage = newPage;
|
||||
|
||||
case Kind::ListItem: {
|
||||
if (const auto p = sec.getPageForListItemIndex(lutIndex)) {
|
||||
sec.currentPage = *p;
|
||||
LOG_DBG("ERS", "Resolved li[%u] -> page %d", lutIndex, *p);
|
||||
} else if (const auto pp = sec.getPageForParagraphIndex(lutIndex)) {
|
||||
// Some <li>-anchored XPaths land in books where the LI LUT is empty (no <li>
|
||||
// inside <body>'s direct children, or all <li>s skipped). Fall back to the
|
||||
// paragraph LUT — the running indices coincide often enough to help, and
|
||||
// it's strictly better than dropping back to the estimate.
|
||||
sec.currentPage = *pp;
|
||||
LOG_DBG("ERS", "Li LUT miss for li[%u]; paragraph LUT -> page %d", lutIndex, *pp);
|
||||
} else {
|
||||
LOG_DBG("ERS", "Li[%u] not in LUT; using fallback page %d", lutIndex, fallbackPage);
|
||||
sec.currentPage = fallbackPage;
|
||||
isEstimate = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Kind::Page — apply baseline, then cross-font rescale if we have a cached page count.
|
||||
sec.currentPage = page;
|
||||
if (cachedPageCount > 0 && cachedSpineIdx == spineIndex) {
|
||||
if (sec.pageCount != cachedPageCount) {
|
||||
const float progress = static_cast<float>(sec.currentPage) / static_cast<float>(cachedPageCount);
|
||||
sec.currentPage = static_cast<int>(progress * static_cast<float>(sec.pageCount));
|
||||
|
||||
case Kind::Paragraph: {
|
||||
if (const auto p = sec.getPageForParagraphIndex(lutIndex)) {
|
||||
sec.currentPage = *p;
|
||||
LOG_DBG("ERS", "Resolved p[%u] -> page %d", lutIndex, *p);
|
||||
} else {
|
||||
LOG_DBG("ERS", "Paragraph LUT miss for p[%u]; using fallback page %d", lutIndex, fallbackPage);
|
||||
sec.currentPage = fallbackPage;
|
||||
isEstimate = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Kind::Percent: {
|
||||
if (sec.pageCount > 0) {
|
||||
int newPage = static_cast<int>(spineProgress * static_cast<float>(sec.pageCount));
|
||||
if (newPage >= sec.pageCount) newPage = sec.pageCount - 1;
|
||||
sec.currentPage = newPage;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Kind::Page: {
|
||||
sec.currentPage = page;
|
||||
isEstimate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Safety clamp.
|
||||
|
||||
// Cross-font / cross-spine rescaling: only for estimated pages. cachedPageCount
|
||||
// is the page count at the time the estimate was made — when it disagrees with
|
||||
// the section's current page count (reflow / different spine entirely), rescale
|
||||
// the estimate proportionally before clamping.
|
||||
if (isEstimate && cachedPageCount > 0 && cachedSpineIdx == spineIndex && sec.pageCount != cachedPageCount) {
|
||||
const float progress = static_cast<float>(sec.currentPage) / static_cast<float>(cachedPageCount);
|
||||
sec.currentPage = static_cast<int>(progress * static_cast<float>(sec.pageCount));
|
||||
}
|
||||
|
||||
// Safety clamp for all paths — a LUT-derived page is also defensively clamped in
|
||||
// case the cache is somehow stale.
|
||||
if (sec.currentPage < 0) {
|
||||
LOG_DBG("ERS", "Clamping negative page %d to 0 (spine=%d cachedPageCount=%d)", sec.currentPage, spineIndex,
|
||||
cachedPageCount);
|
||||
@@ -1635,6 +1793,7 @@ void EpubReaderActivity::render(RenderLock&& lock) {
|
||||
if (!epub) {
|
||||
return;
|
||||
}
|
||||
logIntegrityProbe("render_entry");
|
||||
|
||||
const int spineCount = epub->getSpineItemsCount();
|
||||
if (spineCount <= 0) {
|
||||
@@ -1779,11 +1938,13 @@ void EpubReaderActivity::render(RenderLock&& lock) {
|
||||
auto p = section->loadPageFromSectionFile();
|
||||
section->currentPage = savedPage;
|
||||
if (p && !p->hasImages()) {
|
||||
logIntegrityProbe("preRender_before_renderPageContentOnly");
|
||||
section->currentPage = nextPage;
|
||||
renderPageContentOnly(*p, orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft);
|
||||
section->currentPage = savedPage;
|
||||
preRenderedPage = {true, currentSpineIndex, nextPage};
|
||||
LOG_DBG("ERS", "Pre-rendered page %d/%d", nextPage, section->pageCount - 1);
|
||||
logIntegrityProbe("preRender_after_renderPageContentOnly");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1866,6 +2027,7 @@ void EpubReaderActivity::render(RenderLock&& lock) {
|
||||
LOG_DBG("ERS", "Cache found, skipping build...");
|
||||
}
|
||||
lastRenderStats.sectionLoadMs = millis() - sectionStart;
|
||||
logIntegrityProbe("render_after_sectionLoad");
|
||||
|
||||
if (section->isTruncatedCache() && currentSpineIndex != lastWarnedTruncatedSpineIndex) {
|
||||
lastWarnedTruncatedSpineIndex = currentSpineIndex;
|
||||
@@ -1903,6 +2065,7 @@ void EpubReaderActivity::render(RenderLock&& lock) {
|
||||
const unsigned long pageLoadStart = millis();
|
||||
auto p = section->loadPageFromSectionFile();
|
||||
lastRenderStats.pageLoadMs = millis() - pageLoadStart;
|
||||
logIntegrityProbe("render_after_pageLoad");
|
||||
if (!p) {
|
||||
LOG_ERR("ERS", "Failed to load page from SD - clearing section cache");
|
||||
section->clearCache();
|
||||
@@ -1929,8 +2092,10 @@ void EpubReaderActivity::render(RenderLock&& lock) {
|
||||
truncatedSectionHintRendersRemaining--;
|
||||
}
|
||||
LOG_DBG("ERS", "Rendered page in %dms", lastRenderStats.requestRenderMs);
|
||||
logIntegrityProbe("render_after_renderContents");
|
||||
}
|
||||
silentIndexNextChapterIfNeeded(viewportWidth, viewportHeight);
|
||||
logIntegrityProbe("render_after_silentIndex");
|
||||
pendingProgressSave.spineIndex = currentSpineIndex;
|
||||
pendingProgressSave.page = section->currentPage;
|
||||
pendingProgressSave.pageCount = section->pageCount;
|
||||
@@ -2010,6 +2175,7 @@ void EpubReaderActivity::renderContents(std::unique_ptr<Page> page, const int or
|
||||
const int orientedMarginLeft) {
|
||||
const auto t0 = millis();
|
||||
logReaderMemSnapshot("render_start");
|
||||
logIntegrityProbe("renderContents_entry");
|
||||
auto* fcm = renderer.getFontCacheManager();
|
||||
fcm->resetStats();
|
||||
|
||||
@@ -2025,6 +2191,7 @@ void EpubReaderActivity::renderContents(std::unique_ptr<Page> page, const int or
|
||||
const bool warmForceLoad = forceLoadLargeImages || !SETTINGS.largeImagePlaceholder;
|
||||
page->warmImageCaches(renderer, orientedMarginLeft, contentTop, warmForceLoad);
|
||||
renderer.clearScreen();
|
||||
logIntegrityProbe("renderContents_after_warmImages");
|
||||
|
||||
logReaderMemSnapshot("prewarm_begin");
|
||||
|
||||
@@ -2044,6 +2211,7 @@ void EpubReaderActivity::renderContents(std::unique_ptr<Page> page, const int or
|
||||
LOG_DBG("ERS", "Heap: before=%lu (contig=%lu) after=%lu (contig=%lu) delta=%ld", heapBefore, contigBefore, heapAfter,
|
||||
contigAfter, (int32_t)heapAfter - (int32_t)heapBefore);
|
||||
logReaderMemSnapshot("prewarm_end");
|
||||
logIntegrityProbe("renderContents_after_fontPrewarm");
|
||||
|
||||
const bool aaConfigured = getEffectiveTextAntiAliasing();
|
||||
bool aaEnabledForThisRender = aaConfigured;
|
||||
@@ -2095,6 +2263,7 @@ void EpubReaderActivity::renderContents(std::unique_ptr<Page> page, const int or
|
||||
fcm->logStats("bw_render");
|
||||
const auto tBwRender = millis();
|
||||
logReaderMemSnapshot("after_bw_render");
|
||||
logIntegrityProbe("renderContents_after_bwRender");
|
||||
|
||||
if (imagePageWithAA) {
|
||||
// Double FAST_REFRESH with selective image blanking (pablohc's technique):
|
||||
@@ -2142,6 +2311,7 @@ void EpubReaderActivity::renderContents(std::unique_ptr<Page> page, const int or
|
||||
uint32_t tiledGrayMs = 0;
|
||||
if (aaEnabledForThisRender) {
|
||||
logReaderMemSnapshot("tiled_gray_begin");
|
||||
logIntegrityProbe("renderContents_before_tiledGray");
|
||||
const auto tTiledBegin = millis();
|
||||
grayscaleDone = runTiledGrayscalePass(renderer, *page, getEffectiveReaderFontId(), orientedMarginLeft, contentTop,
|
||||
SETTINGS.fastAntiAliasing);
|
||||
@@ -2149,6 +2319,7 @@ void EpubReaderActivity::renderContents(std::unique_ptr<Page> page, const int or
|
||||
tiledGrayMs = millis() - tTiledBegin;
|
||||
fcm->logStats("tiled_gray");
|
||||
logReaderMemSnapshot("tiled_gray_end");
|
||||
logIntegrityProbe("renderContents_after_tiledGray");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2405,7 +2576,13 @@ void EpubReaderActivity::renderStatusBar() const {
|
||||
|
||||
const bool isStarred = section && bookmarkStore.has(static_cast<uint16_t>(currentSpineIndex),
|
||||
static_cast<uint16_t>(section->currentPage));
|
||||
GUI.drawStatusBar(renderer, bookProgress, currentPage, pageCount, title, 0, isStarred);
|
||||
std::string printedPageLabel;
|
||||
if (section) {
|
||||
if (const auto label = section->getPrintedPageLabelForPage(static_cast<uint16_t>(section->currentPage))) {
|
||||
printedPageLabel = *label;
|
||||
}
|
||||
}
|
||||
GUI.drawStatusBar(renderer, bookProgress, currentPage, pageCount, title, 0, isStarred, printedPageLabel);
|
||||
|
||||
lastStatusBarPage = currentPage;
|
||||
lastStatusBarBattery = SETTINGS.statusBarBattery ? static_cast<int>(powerManager.getBatteryPercentage()) : -1;
|
||||
@@ -2629,6 +2806,11 @@ void EpubReaderActivity::openQuickOverrides() {
|
||||
void EpubReaderActivity::openReaderMenu() {
|
||||
const int currentPage = section ? section->currentPage + 1 : 0;
|
||||
const int totalPages = section ? section->pageCount : 0;
|
||||
|
||||
if (!epub) {
|
||||
return;
|
||||
}
|
||||
|
||||
float bookProgress = 0.0f;
|
||||
if (epub->getBookSize() > 0 && section && section->pageCount > 0) {
|
||||
const float chapterProgress = static_cast<float>(section->currentPage) / static_cast<float>(section->pageCount);
|
||||
@@ -2637,13 +2819,22 @@ void EpubReaderActivity::openReaderMenu() {
|
||||
const int bookProgressPercent = clampPercent(static_cast<int>(bookProgress + 0.5f));
|
||||
const bool isCurrentPageStarred = section && bookmarkStore.has(static_cast<uint16_t>(currentSpineIndex),
|
||||
static_cast<uint16_t>(section->currentPage));
|
||||
|
||||
// Show the "Go to printed page" item only when this book has at least one integer-labelled
|
||||
// entry in pagelist.bin. Roman-only or empty page lists are excluded — the numeric input
|
||||
// dialog can't address them anyway.
|
||||
const auto printedPageList = epub->loadPrintedPageList();
|
||||
const bool hasPrintedPages = std::any_of(printedPageList.begin(), printedPageList.end(), [](const auto& entry) {
|
||||
return parsePrintedPageLabel(entry.label).has_value();
|
||||
});
|
||||
|
||||
ReaderUtils::enforceExitFullRefresh(renderer);
|
||||
startActivityForResult(
|
||||
std::make_unique<EpubReaderMenuActivity>(
|
||||
renderer, mappedInput, epub->getTitle(), currentPage, totalPages, bookProgressPercent, SETTINGS.orientation,
|
||||
!currentPageFootnotes.empty(), bookEmbeddedStyleOverride, bookImageRenderingOverride, bookFontFamilyOverride,
|
||||
bookSdFontFamilyOverride, bookFontSizeOverride, SETTINGS.textDarkness, getEffectiveBionicReading(),
|
||||
bookParagraphAlignmentOverride, !bookmarkStore.isEmpty(), isCurrentPageStarred),
|
||||
bookParagraphAlignmentOverride, !bookmarkStore.isEmpty(), isCurrentPageStarred, hasPrintedPages),
|
||||
[this](const ActivityResult& result) {
|
||||
const auto& menu = std::get<MenuResult>(result.data);
|
||||
applyOrientation(menu.orientation);
|
||||
|
||||
Reference in New Issue
Block a user