No blank trailing page
This commit is contained in:
@@ -245,6 +245,7 @@ bool ChapterHtmlSlimParser::ensureHeapForTextLayout(const char* phase) {
|
|||||||
|
|
||||||
LOG_ERR("EHP", "Low heap (%u free, %u max alloc), aborting parse before %s", freeHeap, maxAllocHeap, phase);
|
LOG_ERR("EHP", "Low heap (%u free, %u max alloc), aborting parse before %s", freeHeap, maxAllocHeap, phase);
|
||||||
streamFailed = true;
|
streamFailed = true;
|
||||||
|
layoutFailed = true;
|
||||||
if (activeParser) {
|
if (activeParser) {
|
||||||
XML_StopParser(activeParser, XML_FALSE);
|
XML_StopParser(activeParser, XML_FALSE);
|
||||||
}
|
}
|
||||||
@@ -1637,6 +1638,7 @@ bool ChapterHtmlSlimParser::setup(const size_t totalInflatedSize) {
|
|||||||
bytesStreamed = 0;
|
bytesStreamed = 0;
|
||||||
lastReportedProgress = -1;
|
lastReportedProgress = -1;
|
||||||
streamFailed = false;
|
streamFailed = false;
|
||||||
|
layoutFailed = false;
|
||||||
streamStartTimeMs = millis();
|
streamStartTimeMs = millis();
|
||||||
|
|
||||||
// Choose progress granularity by chapter size. Each callback drives a full-screen
|
// Choose progress granularity by chapter size. Each callback drives a full-screen
|
||||||
@@ -1741,11 +1743,13 @@ bool ChapterHtmlSlimParser::finalize() {
|
|||||||
// success scenario still flushes whatever pages were produced.
|
// success scenario still flushes whatever pages were produced.
|
||||||
if (currentTextBlock) {
|
if (currentTextBlock) {
|
||||||
makePages();
|
makePages();
|
||||||
if (!pendingAnchorId.empty()) {
|
if (!layoutFailed) {
|
||||||
anchorData.push_back({std::move(pendingAnchorId), static_cast<uint16_t>(completedPageCount)});
|
if (!pendingAnchorId.empty()) {
|
||||||
pendingAnchorId.clear();
|
anchorData.push_back({std::move(pendingAnchorId), static_cast<uint16_t>(completedPageCount)});
|
||||||
|
pendingAnchorId.clear();
|
||||||
|
}
|
||||||
|
emitPage(0u); // post-parse: no byte offset available
|
||||||
}
|
}
|
||||||
emitPage(0u); // post-parse: no byte offset available
|
|
||||||
currentPage.reset();
|
currentPage.reset();
|
||||||
currentTextBlock.reset();
|
currentTextBlock.reset();
|
||||||
}
|
}
|
||||||
@@ -1793,6 +1797,11 @@ ParsedText::LineProcessResult ChapterHtmlSlimParser::addLineToPage(std::shared_p
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ChapterHtmlSlimParser::makePages() {
|
void ChapterHtmlSlimParser::makePages() {
|
||||||
|
if (layoutFailed) {
|
||||||
|
currentTextBlock.reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!currentTextBlock) {
|
if (!currentTextBlock) {
|
||||||
LOG_ERR("EHP", "!! No text block to make pages for !!");
|
LOG_ERR("EHP", "!! No text block to make pages for !!");
|
||||||
return;
|
return;
|
||||||
@@ -1824,6 +1833,8 @@ void ChapterHtmlSlimParser::makePages() {
|
|||||||
(horizontalInset < viewportWidth) ? static_cast<uint16_t>(viewportWidth - horizontalInset) : viewportWidth;
|
(horizontalInset < viewportWidth) ? static_cast<uint16_t>(viewportWidth - horizontalInset) : viewportWidth;
|
||||||
|
|
||||||
if (!ensureHeapForTextLayout("paragraph layout")) {
|
if (!ensureHeapForTextLayout("paragraph layout")) {
|
||||||
|
layoutFailed = true;
|
||||||
|
currentTextBlock.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ class ChapterHtmlSlimParser final : public Print {
|
|||||||
std::vector<std::pair<int, FootnoteEntry>> pendingFootnotes; // <wordIndex, entry>
|
std::vector<std::pair<int, FootnoteEntry>> pendingFootnotes; // <wordIndex, entry>
|
||||||
int wordsExtractedInBlock = 0;
|
int wordsExtractedInBlock = 0;
|
||||||
bool bionicReadingEnabled = false;
|
bool bionicReadingEnabled = false;
|
||||||
|
bool layoutFailed = false;
|
||||||
|
|
||||||
// Per-chapter caches: resolveStyle and parseInlineStyle are called for every HTML element;
|
// Per-chapter caches: resolveStyle and parseInlineStyle are called for every HTML element;
|
||||||
// caching by (tag|classAttr) and styleAttr avoids repeated string operations and hash lookups.
|
// caching by (tag|classAttr) and styleAttr avoids repeated string operations and hash lookups.
|
||||||
|
|||||||
Reference in New Issue
Block a user