Finetuning
This commit is contained in:
+5
-4
@@ -45,7 +45,7 @@ bool Epub::findContentOpfFile(std::string* contentOpfFile) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Epub::parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata) {
|
||||
bool Epub::parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata, bool useCache) {
|
||||
std::string contentOpfFilePath;
|
||||
if (!findContentOpfFile(&contentOpfFilePath)) {
|
||||
LOG_ERR("EBP", "Could not find content.opf in zip");
|
||||
@@ -62,7 +62,8 @@ bool Epub::parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ContentOpfParser opfParser(getCachePath(), getBasePath(), contentOpfSize, bookMetadataCache.get());
|
||||
ContentOpfParser opfParser(getCachePath(), getBasePath(), contentOpfSize,
|
||||
useCache ? bookMetadataCache.get() : nullptr);
|
||||
if (!opfParser.setup()) {
|
||||
LOG_ERR("EBP", "Could not setup content.opf parser");
|
||||
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");
|
||||
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");
|
||||
// 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");
|
||||
return false;
|
||||
}
|
||||
if (!parseContentOpf(bookMetadata)) {
|
||||
if (!parseContentOpf(bookMetadata, true)) {
|
||||
LOG_ERR("EBP", "Could not parse content.opf");
|
||||
return false;
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class Epub {
|
||||
bool syntheticTocFallbackEnabled = false;
|
||||
|
||||
bool findContentOpfFile(std::string* contentOpfFile) const;
|
||||
bool parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata);
|
||||
bool parseContentOpf(BookMetadataCache::BookMetadata& bookMetadata, bool useCache = true);
|
||||
bool parseTocNcxFile() const;
|
||||
bool parseTocNavFile() const;
|
||||
void parseCssFiles() const;
|
||||
|
||||
@@ -584,17 +584,19 @@ std::optional<uint16_t> Section::getPageForParagraphIndex(const uint16_t pIndex)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Find the first page whose paragraph index >= pIndex.
|
||||
uint16_t resultPage = count - 1; // default to last page
|
||||
// Find the page that contains the requested paragraph index.
|
||||
// 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++) {
|
||||
uint32_t byteOffset;
|
||||
uint16_t pagePIdx;
|
||||
serialization::readPod(f, byteOffset);
|
||||
serialization::readPod(f, pagePIdx);
|
||||
if (pagePIdx >= pIndex) {
|
||||
resultPage = i;
|
||||
if (pagePIdx > pIndex) {
|
||||
break;
|
||||
}
|
||||
resultPage = i;
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
||||
Reference in New Issue
Block a user