feat: add RTL support in epub and txt readers (#1700)

Co-authored-by: Zach Nelson <zach@zdnelson.com>
This commit is contained in:
Uri Tauber
2026-05-29 03:25:17 -04:00
committed by GitHub
co-authored by Zach Nelson
parent cc2079a578
commit f5bc554ae7
27 changed files with 1621 additions and 119 deletions
+9 -3
View File
@@ -1,5 +1,6 @@
#include "TxtReaderActivity.h"
#include <BidiUtils.h>
#include <FontCacheManager.h>
#include <GfxRenderer.h>
#include <HalStorage.h>
@@ -358,20 +359,25 @@ void TxtReaderActivity::renderPage() {
for (const auto& line : currentPageLines) {
if (!line.empty()) {
int x = cachedOrientedMarginLeft;
const bool lineIsRtl = BidiUtils::startsWithRtl(line.c_str(), BidiUtils::RTL_PARAGRAPH_PROBE_DEPTH);
uint8_t effectiveAlignment = cachedParagraphAlignment;
if (lineIsRtl && (effectiveAlignment == CrossPointSettings::LEFT_ALIGN ||
effectiveAlignment == CrossPointSettings::JUSTIFIED)) {
effectiveAlignment = CrossPointSettings::RIGHT_ALIGN;
}
const int textWidth = renderer.getTextAdvanceX(cachedFontId, line.c_str(), EpdFontFamily::REGULAR);
// Apply text alignment
switch (cachedParagraphAlignment) {
switch (effectiveAlignment) {
case CrossPointSettings::LEFT_ALIGN:
default:
// x already set to left margin
break;
case CrossPointSettings::CENTER_ALIGN: {
int textWidth = renderer.getTextAdvanceX(cachedFontId, line.c_str(), EpdFontFamily::REGULAR);
x = cachedOrientedMarginLeft + (contentWidth - textWidth) / 2;
break;
}
case CrossPointSettings::RIGHT_ALIGN: {
int textWidth = renderer.getTextAdvanceX(cachedFontId, line.c_str(), EpdFontFamily::REGULAR);
x = cachedOrientedMarginLeft + contentWidth - textWidth;
break;
}