Refactor to a more generic unobstrusive approach

This commit is contained in:
jpirnay
2026-03-27 17:06:30 +01:00
parent 3f8a87e907
commit a51fd3953d
3 changed files with 8 additions and 6 deletions
+4 -6
View File
@@ -7,13 +7,11 @@
#include <PngToBmpConverter.h>
#include <ZipFile.h>
#include "CrossPointSettings.h"
#include "Epub/parsers/ContainerParser.h"
#include "Epub/parsers/ContentOpfParser.h"
#include "Epub/parsers/TocNavParser.h"
#include "Epub/parsers/TocNcxParser.h"
bool Epub::findContentOpfFile(std::string* contentOpfFile) const {
const auto containerPath = "META-INF/container.xml";
size_t containerSize;
@@ -770,7 +768,7 @@ BookMetadataCache::TocEntry Epub::getTocItem(const int tocIndex) const {
return {};
}
if (SETTINGS.syntheticTocFallback && !hasReliableToc()) {
if (syntheticTocFallbackEnabled && !hasReliableToc()) {
const int spineCount = bookMetadataCache->getSpineCount();
if (tocIndex < 0 || tocIndex >= spineCount) {
LOG_DBG("EBP", "getTocItem synthetic index:%d is out of range", tocIndex);
@@ -795,7 +793,7 @@ int Epub::getTocItemsCount() const {
return 0;
}
if (SETTINGS.syntheticTocFallback && !hasReliableToc()) {
if (syntheticTocFallbackEnabled && !hasReliableToc()) {
return bookMetadataCache->getSpineCount();
}
@@ -809,7 +807,7 @@ int Epub::getSpineIndexForTocIndex(const int tocIndex) const {
return 0;
}
if (SETTINGS.syntheticTocFallback && !hasReliableToc()) {
if (syntheticTocFallbackEnabled && !hasReliableToc()) {
if (tocIndex < 0 || tocIndex >= bookMetadataCache->getSpineCount()) {
LOG_ERR("EBP", "getSpineIndexForTocIndex synthetic tocIndex %d out of range", tocIndex);
return 0;
@@ -885,7 +883,7 @@ int Epub::getTocIndexForSpineIndex(const int spineIndex) const {
return 0;
}
if (SETTINGS.syntheticTocFallback && !hasReliableToc()) {
if (syntheticTocFallbackEnabled && !hasReliableToc()) {
return spineIndex;
}
+3
View File
@@ -31,6 +31,8 @@ class Epub {
std::vector<std::string> cssFiles;
// -1 unknown, 0 unreliable, 1 reliable
mutable int tocReliabilityState = -1;
// Library-level option: app code can override this per-book instance.
bool syntheticTocFallbackEnabled = false;
bool findContentOpfFile(std::string* contentOpfFile) const;
bool parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata);
@@ -69,6 +71,7 @@ class Epub {
int getSpineIndexForTocIndex(int tocIndex) const;
int getTocIndexForSpineIndex(int spineIndex) const;
bool hasReliableToc() const;
void setSyntheticTocFallbackEnabled(bool enabled) { syntheticTocFallbackEnabled = enabled; }
size_t getCumulativeSpineItemSize(int spineIndex) const;
int getSpineIndexForTextReference() const;
+1
View File
@@ -37,6 +37,7 @@ std::unique_ptr<Epub> ReaderActivity::loadEpub(const std::string& path) {
}
auto epub = std::unique_ptr<Epub>(new Epub(path, "/.crosspoint"));
epub->setSyntheticTocFallbackEnabled(SETTINGS.syntheticTocFallback != 0);
if (epub->load(true, SETTINGS.embeddedStyle == 0)) {
return epub;
}