From ee0a2556acf3d0865dcb0a51af982b672bc2c199 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Tue, 19 May 2026 12:41:26 +0200 Subject: [PATCH] Use localized strings --- lib/Epub/Epub/BookMetadataCache.cpp | 2 +- lib/Epub/Epub/blocks/ImageBlock.cpp | 21 +++++++++++++------ lib/Epub/Epub/blocks/ImageBlock.h | 4 +++- .../Epub/parsers/ChapterHtmlSlimParser.cpp | 2 +- lib/I18n/translations/english.yaml | 2 ++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/Epub/Epub/BookMetadataCache.cpp b/lib/Epub/Epub/BookMetadataCache.cpp index 7e597a4b..06a5ffd4 100644 --- a/lib/Epub/Epub/BookMetadataCache.cpp +++ b/lib/Epub/Epub/BookMetadataCache.cpp @@ -11,7 +11,7 @@ #include "FsHelpers.h" namespace { -constexpr uint8_t BOOK_CACHE_VERSION = 9; +constexpr uint8_t BOOK_CACHE_VERSION = 10; constexpr char bookBinFile[] = "/book.bin"; constexpr char tmpSpineBinFile[] = "/spine.bin.tmp"; constexpr char tmpTocBinFile[] = "/toc.bin.tmp"; diff --git a/lib/Epub/Epub/blocks/ImageBlock.cpp b/lib/Epub/Epub/blocks/ImageBlock.cpp index 5cc6728b..17e37da8 100644 --- a/lib/Epub/Epub/blocks/ImageBlock.cpp +++ b/lib/Epub/Epub/blocks/ImageBlock.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -17,8 +18,8 @@ // - uint16_t height // - uint8_t pixels[...] - 2 bits per pixel, packed (4 pixels per byte), row-major order -ImageBlock::ImageBlock(const std::string& imagePath, int16_t width, int16_t height) - : imagePath(imagePath), width(width), height(height) {} +ImageBlock::ImageBlock(const std::string& imagePath, int16_t width, int16_t height, const std::string& altText) + : imagePath(imagePath), altText(altText), width(width), height(height) {} bool ImageBlock::imageExists() const { return Storage.exists(imagePath.c_str()); } @@ -135,13 +136,18 @@ void ImageBlock::renderPlaceholder(GfxRenderer& renderer, const int x, const int renderer.drawRect(x, y, width, height, BORDER, true); const int lineH = renderer.getLineHeight(UI_10_FONT_ID); - const int totalTextH = lineH * 2; + const bool hasAlt = !altText.empty(); + const int lineCount = hasAlt ? 3 : 2; + const int totalTextH = lineH * lineCount; if (lineH > 0 && width > PADDING * 2 && height > totalTextH + PADDING * 2) { const int textX = x + PADDING; const int textY = y + (height - totalTextH) / 2; - renderer.drawText(UI_10_FONT_ID, textX, textY, "Image"); - renderer.drawText(UI_10_FONT_ID, textX, textY + lineH, "Press OK to load"); + renderer.drawText(UI_10_FONT_ID, textX, textY, tr(STR_LARGE_IMAGE)); + if (hasAlt) { + renderer.drawText(UI_10_FONT_ID, textX, textY + lineH, altText.c_str()); + } + renderer.drawText(UI_10_FONT_ID, textX, textY + lineH * (lineCount - 1), tr(STR_PRESS_CONFIRM_TO_LOAD)); } } @@ -218,6 +224,7 @@ bool ImageBlock::serialize(FsFile& file) { serialization::writeString(file, imagePath); serialization::writePod(file, width); serialization::writePod(file, height); + serialization::writeString(file, altText); return true; } @@ -227,5 +234,7 @@ std::unique_ptr ImageBlock::deserialize(FsFile& file) { int16_t w, h; serialization::readPod(file, w); serialization::readPod(file, h); - return std::unique_ptr(new ImageBlock(path, w, h)); + std::string alt; + serialization::readString(file, alt); + return std::unique_ptr(new ImageBlock(path, w, h, alt)); } diff --git a/lib/Epub/Epub/blocks/ImageBlock.h b/lib/Epub/Epub/blocks/ImageBlock.h index 03149bcb..7145adc0 100644 --- a/lib/Epub/Epub/blocks/ImageBlock.h +++ b/lib/Epub/Epub/blocks/ImageBlock.h @@ -13,12 +13,13 @@ static constexpr int32_t LARGE_IMAGE_PIXEL_THRESHOLD = 800 * 600; class ImageBlock final : public Block { public: - ImageBlock(const std::string& imagePath, int16_t width, int16_t height); + ImageBlock(const std::string& imagePath, int16_t width, int16_t height, const std::string& altText = ""); ~ImageBlock() override = default; const std::string& getImagePath() const { return imagePath; } int16_t getWidth() const { return width; } int16_t getHeight() const { return height; } + const std::string& getAltText() const { return altText; } bool imageExists() const; @@ -39,6 +40,7 @@ class ImageBlock final : public Block { private: std::string imagePath; + std::string altText; int16_t width; int16_t height; diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index fefde980..df6c5d73 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -849,7 +849,7 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* self->currentPageNextY += imageSpacingTop; // Create ImageBlock and add to page - auto imageBlock = std::make_shared(cachedImagePath, displayWidth, displayHeight); + auto imageBlock = std::make_shared(cachedImagePath, displayWidth, displayHeight, alt); if (!imageBlock) { LOG_ERR("EHP", "Failed to create ImageBlock"); return; diff --git a/lib/I18n/translations/english.yaml b/lib/I18n/translations/english.yaml index 146d3ea5..6310742f 100644 --- a/lib/I18n/translations/english.yaml +++ b/lib/I18n/translations/english.yaml @@ -103,6 +103,8 @@ STR_IMAGES_DISPLAY: "Display" STR_IMAGES_PLACEHOLDER: "Placeholder" STR_IMAGES_SUPPRESS: "Suppress" STR_LARGE_IMAGE_PLACEHOLDER: "Placeholder for large images" +STR_LARGE_IMAGE: "Large Image" +STR_PRESS_CONFIRM_TO_LOAD: "Press Confirm to load" STR_IMAGE_DITHERING: "Image Dithering" STR_IMAGE_DITHER_BAYER: "Bayer" STR_IMAGE_DITHER_ATKINSON: "Atkinson"