From f6847f4f83fb63b234d7577ac20760dda879d92d Mon Sep 17 00:00:00 2001 From: Martin Brook Date: Wed, 28 Jan 2026 19:35:28 +0000 Subject: [PATCH] fix: allow images to share first chapter page with title Only force a page break before an image when it won't fit in the remaining page space, instead of unconditionally breaking whenever the page has any content. --- lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index 4375e4ff..2fd6d1e2 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -176,8 +176,9 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* Serial.printf("[%lu] [EHP] Display size: %dx%d (scale %.2f)\n", millis(), displayWidth, displayHeight, scale); - // Create page for image - if (self->currentPage && !self->currentPage->elements.empty()) { + // Create page for image - only break if image won't fit remaining space + if (self->currentPage && !self->currentPage->elements.empty() && + (self->currentPageNextY + displayHeight > self->viewportHeight)) { self->completePageFn(std::move(self->currentPage)); self->currentPage.reset(new Page()); if (!self->currentPage) {