diff --git a/lib/Epub/Epub.cpp b/lib/Epub/Epub.cpp index 68255df4..7c1120f9 100644 --- a/lib/Epub/Epub.cpp +++ b/lib/Epub/Epub.cpp @@ -7,13 +7,11 @@ #include #include -#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; } diff --git a/lib/Epub/Epub.h b/lib/Epub/Epub.h index 943eaeb5..7ea0034a 100644 --- a/lib/Epub/Epub.h +++ b/lib/Epub/Epub.h @@ -31,6 +31,8 @@ class Epub { std::vector 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; diff --git a/src/activities/reader/ReaderActivity.cpp b/src/activities/reader/ReaderActivity.cpp index 2164a7f6..6a62cb70 100644 --- a/src/activities/reader/ReaderActivity.cpp +++ b/src/activities/reader/ReaderActivity.cpp @@ -37,6 +37,7 @@ std::unique_ptr ReaderActivity::loadEpub(const std::string& path) { } auto epub = std::unique_ptr(new Epub(path, "/.crosspoint")); + epub->setSyntheticTocFallbackEnabled(SETTINGS.syntheticTocFallback != 0); if (epub->load(true, SETTINGS.embeddedStyle == 0)) { return epub; }