Fix css mismatch after koreader sync
This commit is contained in:
@@ -60,7 +60,7 @@ constexpr uint32_t FNV_OFFSET_BASIS = 0x811C9DC5; // 2166136261
|
||||
#endif
|
||||
|
||||
#ifndef SCT_EMBEDDED_STYLE_MIN_CONTIG_HEAP_BYTES
|
||||
#define SCT_EMBEDDED_STYLE_MIN_CONTIG_HEAP_BYTES (56 * 1024)
|
||||
#define SCT_EMBEDDED_STYLE_MIN_CONTIG_HEAP_BYTES (36 * 1024)
|
||||
#endif
|
||||
|
||||
constexpr uint32_t EMBEDDED_STYLE_MIN_FREE_HEAP_BYTES = SCT_EMBEDDED_STYLE_MIN_FREE_HEAP_BYTES;
|
||||
@@ -244,6 +244,7 @@ bool Section::loadSectionFile(const int fontId, const float lineCompression, con
|
||||
const uint16_t viewportHeight, const bool hyphenationEnabled, const bool embeddedStyle,
|
||||
const bool bionicReadingEnabled, const uint8_t imageRendering) {
|
||||
truncatedCache = false;
|
||||
embeddedStyleFallback = false;
|
||||
uint32_t propertyHash =
|
||||
calculatePropertyHash(fontId, lineCompression, extraParagraphSpacing, paragraphAlignment, viewportWidth,
|
||||
viewportHeight, hyphenationEnabled, embeddedStyle, bionicReadingEnabled, imageRendering);
|
||||
@@ -260,6 +261,7 @@ bool Section::loadSectionFile(const int fontId, const float lineCompression, con
|
||||
if (Storage.openFileForRead("SCT", fallbackPath, file)) {
|
||||
filePath = fallbackPath;
|
||||
usingEmbeddedStyleFallback = true;
|
||||
embeddedStyleFallback = true;
|
||||
LOG_INF("SCT", "Using no-CSS section cache fallback: %s", filePath.c_str());
|
||||
} else {
|
||||
return false;
|
||||
@@ -419,6 +421,13 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reset build state — createSectionFile may be called on a Section that previously
|
||||
// loaded a cache (e.g. fallback no-CSS file). pageCount must start at 0 so that
|
||||
// onPageComplete() numbering and paragraphLutPerPage stay in lockstep.
|
||||
file.close();
|
||||
pageCount = 0;
|
||||
this->lut.clear();
|
||||
|
||||
if (!Storage.openFileForWrite("SCT", filePath, file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ class Section {
|
||||
FsFile file;
|
||||
std::vector<uint32_t> lut; // Cached page byte-offsets; loaded once, avoids per-page LUT seek
|
||||
bool truncatedCache = false;
|
||||
bool embeddedStyleFallback = false;
|
||||
|
||||
void writeSectionFileHeader(int fontId, float lineCompression, bool extraParagraphSpacing, uint8_t paragraphAlignment,
|
||||
uint16_t viewportWidth, uint16_t viewportHeight, bool hyphenationEnabled,
|
||||
@@ -70,6 +71,7 @@ class Section {
|
||||
const std::function<void(int)>& progressFn = nullptr, bool skipEviction = false);
|
||||
std::unique_ptr<Page> loadPageFromSectionFile();
|
||||
bool isTruncatedCache() const { return truncatedCache; }
|
||||
bool isEmbeddedStyleFallback() const { return embeddedStyleFallback; }
|
||||
|
||||
// Given a page in this section, return the TOC index for that page.
|
||||
int getTocIndexForPage(int page) const;
|
||||
|
||||
@@ -1604,6 +1604,30 @@ void EpubReaderActivity::render(RenderLock&& lock) {
|
||||
section.reset();
|
||||
return;
|
||||
}
|
||||
} else if (section->isEmbeddedStyleFallback()) {
|
||||
LOG_INF("ERS", "No-CSS fallback loaded; rebuilding with embedded CSS...");
|
||||
lastRenderStats.cacheRebuilt = true;
|
||||
|
||||
Rect popupRect{};
|
||||
const auto progressFn = [this, &popupRect](int progress) {
|
||||
if (popupRect.width == 0) {
|
||||
popupRect = GUI.drawPopup(renderer, tr(STR_INDEXING));
|
||||
return;
|
||||
}
|
||||
GUI.fillPopupProgress(renderer, popupRect, progress);
|
||||
};
|
||||
|
||||
renderer.clearSdCardFontAccumulation();
|
||||
if (!section->createSectionFile(getEffectiveReaderFontId(), getEffectiveReaderLineCompression(),
|
||||
SETTINGS.extraParagraphSpacing, getEffectiveParagraphAlignment(), viewportWidth,
|
||||
viewportHeight, SETTINGS.hyphenationEnabled, embeddedStyle,
|
||||
bookBionicReadingOverride, imageRendering, progressFn)) {
|
||||
LOG_ERR("ERS", "Failed to rebuild CSS section cache; keeping fallback");
|
||||
section->loadSectionFile(getEffectiveReaderFontId(), getEffectiveReaderLineCompression(),
|
||||
SETTINGS.extraParagraphSpacing, getEffectiveParagraphAlignment(), viewportWidth,
|
||||
viewportHeight, SETTINGS.hyphenationEnabled, embeddedStyle, bookBionicReadingOverride,
|
||||
imageRendering);
|
||||
}
|
||||
} else {
|
||||
LOG_DBG("ERS", "Cache found, skipping build...");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user