Finetuning

This commit is contained in:
jpirnay
2026-04-20 12:28:00 +02:00
parent fd72941cd4
commit 5e4f78f7be
3 changed files with 12 additions and 9 deletions
+5 -4
View File
@@ -45,7 +45,7 @@ bool Epub::findContentOpfFile(std::string* contentOpfFile) const {
return true; return true;
} }
bool Epub::parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata) { bool Epub::parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata, bool useCache) {
std::string contentOpfFilePath; std::string contentOpfFilePath;
if (!findContentOpfFile(&contentOpfFilePath)) { if (!findContentOpfFile(&contentOpfFilePath)) {
LOG_ERR("EBP", "Could not find content.opf in zip"); LOG_ERR("EBP", "Could not find content.opf in zip");
@@ -62,7 +62,8 @@ bool Epub::parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata) {
return false; return false;
} }
ContentOpfParser opfParser(getCachePath(), getBasePath(), contentOpfSize, bookMetadataCache.get()); ContentOpfParser opfParser(getCachePath(), getBasePath(), contentOpfSize,
useCache ? bookMetadataCache.get() : nullptr);
if (!opfParser.setup()) { if (!opfParser.setup()) {
LOG_ERR("EBP", "Could not setup content.opf parser"); LOG_ERR("EBP", "Could not setup content.opf parser");
return false; return false;
@@ -352,7 +353,7 @@ bool Epub::load(const bool buildIfMissing, const bool skipLoadingCss) {
LOG_DBG("EBP", "CSS rules cache missing or stale, attempting to parse CSS files"); LOG_DBG("EBP", "CSS rules cache missing or stale, attempting to parse CSS files");
cssParser->deleteCache(); cssParser->deleteCache();
if (!parseContentOpf(bookMetadataCache->coreMetadata)) { if (!parseContentOpf(bookMetadataCache->coreMetadata, false)) {
LOG_ERR("EBP", "Could not parse content.opf from cached bookMetadata for CSS files"); LOG_ERR("EBP", "Could not parse content.opf from cached bookMetadata for CSS files");
// continue anyway - book will work without CSS and we'll still load any inline style CSS // continue anyway - book will work without CSS and we'll still load any inline style CSS
} }
@@ -389,7 +390,7 @@ bool Epub::load(const bool buildIfMissing, const bool skipLoadingCss) {
LOG_ERR("EBP", "Could not begin writing content.opf pass"); LOG_ERR("EBP", "Could not begin writing content.opf pass");
return false; return false;
} }
if (!parseContentOpf(bookMetadata)) { if (!parseContentOpf(bookMetadata, true)) {
LOG_ERR("EBP", "Could not parse content.opf"); LOG_ERR("EBP", "Could not parse content.opf");
return false; return false;
} }
+1 -1
View File
@@ -35,7 +35,7 @@ class Epub {
bool syntheticTocFallbackEnabled = false; bool syntheticTocFallbackEnabled = false;
bool findContentOpfFile(std::string* contentOpfFile) const; bool findContentOpfFile(std::string* contentOpfFile) const;
bool parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata); bool parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata, bool useCache = true);
bool parseTocNcxFile() const; bool parseTocNcxFile() const;
bool parseTocNavFile() const; bool parseTocNavFile() const;
void parseCssFiles() const; void parseCssFiles() const;
+6 -4
View File
@@ -584,17 +584,19 @@ std::optional<uint16_t> Section::getPageForParagraphIndex(const uint16_t pIndex)
return std::nullopt; return std::nullopt;
} }
// Find the first page whose paragraph index >= pIndex. // Find the page that contains the requested paragraph index.
uint16_t resultPage = count - 1; // default to last page // Each entry stores the first paragraph index for that page, so the page
// containing pIndex is the last page whose start paragraph is <= pIndex.
uint16_t resultPage = 0;
for (uint16_t i = 0; i < count; i++) { for (uint16_t i = 0; i < count; i++) {
uint32_t byteOffset; uint32_t byteOffset;
uint16_t pagePIdx; uint16_t pagePIdx;
serialization::readPod(f, byteOffset); serialization::readPod(f, byteOffset);
serialization::readPod(f, pagePIdx); serialization::readPod(f, pagePIdx);
if (pagePIdx >= pIndex) { if (pagePIdx > pIndex) {
resultPage = i;
break; break;
} }
resultPage = i;
} }
f.close(); f.close();