Use localized strings
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
#include "FsHelpers.h"
|
#include "FsHelpers.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr uint8_t BOOK_CACHE_VERSION = 9;
|
constexpr uint8_t BOOK_CACHE_VERSION = 10;
|
||||||
constexpr char bookBinFile[] = "/book.bin";
|
constexpr char bookBinFile[] = "/book.bin";
|
||||||
constexpr char tmpSpineBinFile[] = "/spine.bin.tmp";
|
constexpr char tmpSpineBinFile[] = "/spine.bin.tmp";
|
||||||
constexpr char tmpTocBinFile[] = "/toc.bin.tmp";
|
constexpr char tmpTocBinFile[] = "/toc.bin.tmp";
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <FsHelpers.h>
|
#include <FsHelpers.h>
|
||||||
#include <GfxRenderer.h>
|
#include <GfxRenderer.h>
|
||||||
|
#include <I18n.h>
|
||||||
#include <Logging.h>
|
#include <Logging.h>
|
||||||
#include <Serialization.h>
|
#include <Serialization.h>
|
||||||
|
|
||||||
@@ -17,8 +18,8 @@
|
|||||||
// - uint16_t height
|
// - uint16_t height
|
||||||
// - uint8_t pixels[...] - 2 bits per pixel, packed (4 pixels per byte), row-major order
|
// - 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)
|
ImageBlock::ImageBlock(const std::string& imagePath, int16_t width, int16_t height, const std::string& altText)
|
||||||
: imagePath(imagePath), width(width), height(height) {}
|
: imagePath(imagePath), altText(altText), width(width), height(height) {}
|
||||||
|
|
||||||
bool ImageBlock::imageExists() const { return Storage.exists(imagePath.c_str()); }
|
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);
|
renderer.drawRect(x, y, width, height, BORDER, true);
|
||||||
|
|
||||||
const int lineH = renderer.getLineHeight(UI_10_FONT_ID);
|
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) {
|
if (lineH > 0 && width > PADDING * 2 && height > totalTextH + PADDING * 2) {
|
||||||
const int textX = x + PADDING;
|
const int textX = x + PADDING;
|
||||||
const int textY = y + (height - totalTextH) / 2;
|
const int textY = y + (height - totalTextH) / 2;
|
||||||
renderer.drawText(UI_10_FONT_ID, textX, textY, "Image");
|
renderer.drawText(UI_10_FONT_ID, textX, textY, tr(STR_LARGE_IMAGE));
|
||||||
renderer.drawText(UI_10_FONT_ID, textX, textY + lineH, "Press OK to load");
|
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::writeString(file, imagePath);
|
||||||
serialization::writePod(file, width);
|
serialization::writePod(file, width);
|
||||||
serialization::writePod(file, height);
|
serialization::writePod(file, height);
|
||||||
|
serialization::writeString(file, altText);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,5 +234,7 @@ std::unique_ptr<ImageBlock> ImageBlock::deserialize(FsFile& file) {
|
|||||||
int16_t w, h;
|
int16_t w, h;
|
||||||
serialization::readPod(file, w);
|
serialization::readPod(file, w);
|
||||||
serialization::readPod(file, h);
|
serialization::readPod(file, h);
|
||||||
return std::unique_ptr<ImageBlock>(new ImageBlock(path, w, h));
|
std::string alt;
|
||||||
|
serialization::readString(file, alt);
|
||||||
|
return std::unique_ptr<ImageBlock>(new ImageBlock(path, w, h, alt));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ static constexpr int32_t LARGE_IMAGE_PIXEL_THRESHOLD = 800 * 600;
|
|||||||
|
|
||||||
class ImageBlock final : public Block {
|
class ImageBlock final : public Block {
|
||||||
public:
|
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;
|
~ImageBlock() override = default;
|
||||||
|
|
||||||
const std::string& getImagePath() const { return imagePath; }
|
const std::string& getImagePath() const { return imagePath; }
|
||||||
int16_t getWidth() const { return width; }
|
int16_t getWidth() const { return width; }
|
||||||
int16_t getHeight() const { return height; }
|
int16_t getHeight() const { return height; }
|
||||||
|
const std::string& getAltText() const { return altText; }
|
||||||
|
|
||||||
bool imageExists() const;
|
bool imageExists() const;
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ class ImageBlock final : public Block {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string imagePath;
|
std::string imagePath;
|
||||||
|
std::string altText;
|
||||||
int16_t width;
|
int16_t width;
|
||||||
int16_t height;
|
int16_t height;
|
||||||
|
|
||||||
|
|||||||
@@ -849,7 +849,7 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
|
|||||||
self->currentPageNextY += imageSpacingTop;
|
self->currentPageNextY += imageSpacingTop;
|
||||||
|
|
||||||
// Create ImageBlock and add to page
|
// Create ImageBlock and add to page
|
||||||
auto imageBlock = std::make_shared<ImageBlock>(cachedImagePath, displayWidth, displayHeight);
|
auto imageBlock = std::make_shared<ImageBlock>(cachedImagePath, displayWidth, displayHeight, alt);
|
||||||
if (!imageBlock) {
|
if (!imageBlock) {
|
||||||
LOG_ERR("EHP", "Failed to create ImageBlock");
|
LOG_ERR("EHP", "Failed to create ImageBlock");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ STR_IMAGES_DISPLAY: "Display"
|
|||||||
STR_IMAGES_PLACEHOLDER: "Placeholder"
|
STR_IMAGES_PLACEHOLDER: "Placeholder"
|
||||||
STR_IMAGES_SUPPRESS: "Suppress"
|
STR_IMAGES_SUPPRESS: "Suppress"
|
||||||
STR_LARGE_IMAGE_PLACEHOLDER: "Placeholder for large images"
|
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_DITHERING: "Image Dithering"
|
||||||
STR_IMAGE_DITHER_BAYER: "Bayer"
|
STR_IMAGE_DITHER_BAYER: "Bayer"
|
||||||
STR_IMAGE_DITHER_ATKINSON: "Atkinson"
|
STR_IMAGE_DITHER_ATKINSON: "Atkinson"
|
||||||
|
|||||||
Reference in New Issue
Block a user