Add easier multidigt navigation
This commit is contained in:
@@ -1301,6 +1301,30 @@ float Epub::calculateProgress(const int currentSpineIndex, const float currentSp
|
||||
return totalProgress / static_cast<float>(bookSize);
|
||||
}
|
||||
|
||||
std::vector<Epub::PrintedPageEntry> Epub::loadPrintedPageList() const {
|
||||
std::vector<PrintedPageEntry> entries;
|
||||
const auto pageListPath = getCachePath() + "/pagelist.bin";
|
||||
if (!Storage.exists(pageListPath.c_str())) {
|
||||
return entries;
|
||||
}
|
||||
FsFile f;
|
||||
if (!Storage.openFileForRead("EBP", pageListPath, f)) {
|
||||
return entries;
|
||||
}
|
||||
uint16_t count = 0;
|
||||
serialization::readPod(f, count);
|
||||
entries.reserve(count);
|
||||
for (uint16_t i = 0; i < count; i++) {
|
||||
PrintedPageEntry e;
|
||||
serialization::readString(f, e.href);
|
||||
serialization::readString(f, e.anchor);
|
||||
serialization::readString(f, e.label);
|
||||
entries.push_back(std::move(e));
|
||||
}
|
||||
f.close();
|
||||
return entries;
|
||||
}
|
||||
|
||||
int Epub::resolveHrefToSpineIndex(const std::string& href) const {
|
||||
if (!bookMetadataCache || !bookMetadataCache->isLoaded()) return -1;
|
||||
|
||||
|
||||
@@ -89,4 +89,15 @@ class Epub {
|
||||
float calculateProgress(int currentSpineIndex, float currentSpineRead) const;
|
||||
CssParser* getCssParser() const { return cssParser.get(); }
|
||||
int resolveHrefToSpineIndex(const std::string& href) const;
|
||||
|
||||
// Printed-page list (from NCX <pageList> / EPUB 3 nav page-list / EPUB 2.01 page-map.xml).
|
||||
// One entry per printed-page anchor: spine href + fragment id + visible label.
|
||||
struct PrintedPageEntry {
|
||||
std::string href;
|
||||
std::string anchor;
|
||||
std::string label;
|
||||
};
|
||||
// Reads <cachePath>/pagelist.bin. Returns empty vector when the book has no printed-page data.
|
||||
// Inexpensive — only invoked from menu paths, not page-turn hot paths.
|
||||
std::vector<PrintedPageEntry> loadPrintedPageList() const;
|
||||
};
|
||||
|
||||
@@ -966,6 +966,18 @@ std::optional<std::string> Section::getPrintedPageLabelFromCache(const std::stri
|
||||
return std::string("(") + labelsOnPage.front() + "/" + labelsOnPage.back() + ")";
|
||||
}
|
||||
|
||||
std::optional<std::string> Section::getNearestPrintedPageLabelAtOrBefore(uint16_t page) const {
|
||||
// pageBreakLabels is built in document order (i.e. ascending pageIndex), so the last
|
||||
// entry whose page is <= `page` is the "you're currently reading at or after this
|
||||
// printed page" hint. Returns the raw label (no parens, no slash-collapsing).
|
||||
std::optional<std::string> best;
|
||||
for (const auto& [labelPage, label] : pageBreakLabels) {
|
||||
if (labelPage > page) break;
|
||||
best = label;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
std::optional<std::string> Section::getPrintedPageLabelForPage(uint16_t page) const {
|
||||
// Collect every printed-page label whose anchor lands on this exact rendered page.
|
||||
// Multiple labels can co-occur when a short device page contains more than one EPUB
|
||||
|
||||
@@ -94,6 +94,11 @@ class Section {
|
||||
// one or more EPUB pagebreak markers / NCX <pageList> / page-map entries land on it.
|
||||
// Returns nullopt when no printed-page anchor falls on this exact page.
|
||||
std::optional<std::string> getPrintedPageLabelForPage(uint16_t page) const;
|
||||
// Like getPrintedPageLabelForPage but returns the most recent printed-page label at or
|
||||
// before `page` (raw label, no parens). Useful for pre-filling jump-to-page dialogs when
|
||||
// the current rendered page doesn't itself carry an anchor. Returns nullopt when no
|
||||
// printed-page anchor exists on this or any earlier page in the section.
|
||||
std::optional<std::string> getNearestPrintedPageLabelAtOrBefore(uint16_t page) const;
|
||||
|
||||
// Standalone lookup that doesn't require a loaded Section. Walks the book's sections cache
|
||||
// directory, finds any cache variant for `spineIndex`, reads its printed-page label map,
|
||||
|
||||
@@ -382,6 +382,10 @@ STR_HW_CONFIRM_LABEL: "Confirm (2nd button)"
|
||||
STR_HW_LEFT_LABEL: "Left (3rd button)"
|
||||
STR_HW_RIGHT_LABEL: "Right (4th button)"
|
||||
STR_GO_TO_PERCENT: "Go to %"
|
||||
STR_GO_TO_PRINTED_PAGE: "Go to printed page"
|
||||
STR_GO_TO_PRINTED_PAGE_RANGE: "Range: %u - %u"
|
||||
STR_GO_TO_PRINTED_PAGE_HINT: "Up/Down: ±1 (x2: ±10) Left/Right: digit"
|
||||
STR_GO_TO_PRINTED_PAGE_NOT_FOUND: "Page %s not found"
|
||||
STR_GO_HOME_BUTTON: "Go Home"
|
||||
STR_SYNC_PROGRESS: "Sync Progress"
|
||||
STR_PUSH_PROGRESS_FROM_THIS_DEVICE: "Push progress from this device"
|
||||
|
||||
Reference in New Issue
Block a user