diff --git a/lib/Epub/Epub/Page.cpp b/lib/Epub/Epub/Page.cpp index 33379f26..c156b584 100644 --- a/lib/Epub/Epub/Page.cpp +++ b/lib/Epub/Epub/Page.cpp @@ -207,6 +207,14 @@ void Page::render(GfxRenderer& renderer, const int fontId, const int xOffset, co } } +void Page::renderTextOnly(GfxRenderer& renderer, const int fontId, const int xOffset, const int yOffset) const { + for (auto& element : elements) { + if (element->getTag() == TAG_PageLine) { + element->render(renderer, fontId, xOffset, yOffset); + } + } +} + bool Page::serialize(FsFile& file) const { const uint16_t count = elements.size(); serialization::writePod(file, count); diff --git a/lib/Epub/Epub/Page.h b/lib/Epub/Epub/Page.h index 828868ff..8d3fdff6 100644 --- a/lib/Epub/Epub/Page.h +++ b/lib/Epub/Epub/Page.h @@ -129,6 +129,7 @@ class Page { } void render(GfxRenderer& renderer, int fontId, int xOffset, int yOffset) const; + void renderTextOnly(GfxRenderer& renderer, int fontId, int xOffset, int yOffset) const; bool serialize(FsFile& file) const; static std::unique_ptr deserialize(FsFile& file); diff --git a/lib/Epub/Epub/blocks/ImageBlock.cpp b/lib/Epub/Epub/blocks/ImageBlock.cpp index 26669c34..3e331572 100644 --- a/lib/Epub/Epub/blocks/ImageBlock.cpp +++ b/lib/Epub/Epub/blocks/ImageBlock.cpp @@ -105,7 +105,7 @@ void ImageBlock::render(GfxRenderer& renderer, const int x, const int y) { // Bounds check render position using logical screen dimensions if (x < 0 || y < 0 || x + width > screenWidth || y + height > screenHeight) { - LOG_ERR("IMG", "Invalid render position: (%d,%d) size (%dx%d) screen (%dx%d)", x, y, width, height, screenWidth, + LOG_ERR("IMG", "Render bounds rejected: (%d,%d) size (%dx%d) screen (%dx%d)", x, y, width, height, screenWidth, screenHeight); return; } diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index 3aefbc0f..3dc0c968 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -75,7 +75,7 @@ constexpr int NUM_UNDERLINE_TAGS = sizeof(UNDERLINE_TAGS) / sizeof(UNDERLINE_TAG const char* STRIKETHROUGH_TAGS[] = {"s", "del", "strike"}; constexpr int NUM_STRIKETHROUGH_TAGS = sizeof(STRIKETHROUGH_TAGS) / sizeof(STRIKETHROUGH_TAGS[0]); -const char* IMAGE_TAGS[] = {"img"}; +const char* IMAGE_TAGS[] = {"img", "image"}; constexpr int NUM_IMAGE_TAGS = sizeof(IMAGE_TAGS) / sizeof(IMAGE_TAGS[0]); const char* SKIP_TAGS[] = {"head"}; @@ -520,8 +520,13 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* std::string alt; if (atts != nullptr) { for (int i = 0; atts[i]; i += 2) { - if (strcmp(atts[i], "src") == 0) { - src = atts[i + 1]; + if (strcmp(atts[i], "src") == 0 || strcmp(atts[i], "href") == 0 || strcmp(atts[i], "xlink:href") == 0) { + if (src.empty()) { + src = atts[i + 1]; + // Strip fragment anchors (e.g. "cover.jpg#xywh=0,0,100,100") + auto hash = src.find('#'); + if (hash != std::string::npos) src.erase(hash); + } } else if (strcmp(atts[i], "alt") == 0) { alt = atts[i + 1]; } diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index 3eb31507..7ea867ca 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -1847,7 +1847,7 @@ void EpubReaderActivity::renderContents(std::unique_ptr page, const int or // Font prewarm: scan pass accumulates text, then prewarm, then real render const uint32_t heapBefore = esp_get_free_heap_size(); auto scope = fcm->createPrewarmScope(); - page->render(renderer, getEffectiveReaderFontId(), orientedMarginLeft, contentTop); // scan pass + page->renderTextOnly(renderer, getEffectiveReaderFontId(), orientedMarginLeft, contentTop); // scan pass scope.endScanAndPrewarm(); const uint32_t heapAfter = esp_get_free_heap_size(); fcm->logStats("prewarm"); @@ -1984,7 +1984,7 @@ void EpubReaderActivity::renderContents(std::unique_ptr page, const int or logReaderMemSnapshot("gray_lsb_begin"); renderer.clearScreen(0x00); renderer.setRenderMode(GfxRenderer::GRAYSCALE_LSB); - page->render(renderer, getEffectiveReaderFontId(), orientedMarginLeft, contentTop); + page->renderTextOnly(renderer, getEffectiveReaderFontId(), orientedMarginLeft, contentTop); renderer.copyGrayscaleLsbBuffers(); const auto tGrayLsb = millis(); logReaderMemSnapshot("gray_lsb_end"); @@ -1993,7 +1993,7 @@ void EpubReaderActivity::renderContents(std::unique_ptr page, const int or logReaderMemSnapshot("gray_msb_begin"); renderer.clearScreen(0x00); renderer.setRenderMode(GfxRenderer::GRAYSCALE_MSB); - page->render(renderer, getEffectiveReaderFontId(), orientedMarginLeft, contentTop); + page->renderTextOnly(renderer, getEffectiveReaderFontId(), orientedMarginLeft, contentTop); renderer.copyGrayscaleMsbBuffers(); const auto tGrayMsb = millis(); logReaderMemSnapshot("gray_msb_end");