feat: add RTL support in epub and txt readers (#1700)
Co-authored-by: Zach Nelson <zach@zdnelson.com>
This commit is contained in:
co-authored by
Zach Nelson
parent
cc2079a578
commit
f5bc554ae7
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user