Skip to content

Commit 4e8018d

Browse files
committed
Important fix to RTL languages saves last space on each line, which was previously lost
1 parent 3f77354 commit 4e8018d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

ccmain/resultiterator.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ bool ResultIterator::IsAtFinalElement(PageIteratorLevel level,
549549
return true;
550550
}
551551

552+
// Returns the number of blanks before the current word.
553+
int ResultIterator::BlanksBeforeWord() const {
554+
if (CurrentParagraphIsLtr()) return LTRResultIterator::BlanksBeforeWord();
555+
return IsAtBeginningOf(RIL_TEXTLINE) ? 0 : 1;
556+
}
557+
552558
/**
553559
* Returns the null terminated UTF-8 encoded text string for the current
554560
* object at the given level. Use delete [] to free after use.
@@ -585,7 +591,7 @@ char* ResultIterator::GetUTF8Text(PageIteratorLevel level) const {
585591
if (at_beginning_of_minor_run_) {
586592
text += reading_direction_is_ltr ? kLRM : kRLM;
587593
}
588-
text = it_->word()->BestUTF8(blob_index_, !reading_direction_is_ltr);
594+
text = it_->word()->BestUTF8(blob_index_, false);
589595
if (IsAtFinalSymbolOfWord()) AppendSuffixMarks(&text);
590596
}
591597
break;
@@ -608,7 +614,7 @@ void ResultIterator::AppendUTF8WordText(STRING *text) const {
608614
GenericVector<int> blob_order;
609615
CalculateBlobOrder(&blob_order);
610616
for (int i = 0; i < blob_order.size(); i++) {
611-
*text += it_->word()->BestUTF8(blob_order[i], !reading_direction_is_ltr);
617+
*text += it_->word()->BestUTF8(blob_order[i], false);
612618
}
613619
AppendSuffixMarks(text);
614620
}
@@ -643,6 +649,9 @@ void ResultIterator::IterateAndAppendUTF8TextlineText(STRING *text) {
643649
}
644650
AppendUTF8WordText(text);
645651
words_appended++;
652+
if (BidiDebug(2)) {
653+
tprintf("Num spaces=%d, text=%s\n", numSpaces, text->string());
654+
}
646655
} while (Next(RIL_WORD) && !IsAtBeginningOf(RIL_TEXTLINE));
647656
if (BidiDebug(1)) {
648657
tprintf("%d words printed\n", words_appended);

ccmain/resultiterator.h

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class TESS_API ResultIterator : public LTRResultIterator {
8282
virtual bool IsAtFinalElement(PageIteratorLevel level,
8383
PageIteratorLevel element) const;
8484

85+
// ============= Functions that refer to words only ============.
86+
// Returns the number of blanks before the current word.
87+
int BlanksBeforeWord() const;
88+
8589
// ============= Accessing data ==============.
8690

8791
/**

0 commit comments

Comments
 (0)