Skip to content

Commit

Permalink
Important fix to RTL languages saves last space on each line, which w…
Browse files Browse the repository at this point in the history
…as previously lost
  • Loading branch information
theraysmith committed Jul 20, 2017
1 parent 3f77354 commit 4e8018d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ccmain/resultiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,12 @@ bool ResultIterator::IsAtFinalElement(PageIteratorLevel level,
return true;
}

// Returns the number of blanks before the current word.
int ResultIterator::BlanksBeforeWord() const {
if (CurrentParagraphIsLtr()) return LTRResultIterator::BlanksBeforeWord();
return IsAtBeginningOf(RIL_TEXTLINE) ? 0 : 1;
}

/**
* Returns the null terminated UTF-8 encoded text string for the current
* object at the given level. Use delete [] to free after use.
Expand Down Expand Up @@ -585,7 +591,7 @@ char* ResultIterator::GetUTF8Text(PageIteratorLevel level) const {
if (at_beginning_of_minor_run_) {
text += reading_direction_is_ltr ? kLRM : kRLM;
}
text = it_->word()->BestUTF8(blob_index_, !reading_direction_is_ltr);
text = it_->word()->BestUTF8(blob_index_, false);
if (IsAtFinalSymbolOfWord()) AppendSuffixMarks(&text);
}
break;
Expand All @@ -608,7 +614,7 @@ void ResultIterator::AppendUTF8WordText(STRING *text) const {
GenericVector<int> blob_order;
CalculateBlobOrder(&blob_order);
for (int i = 0; i < blob_order.size(); i++) {
*text += it_->word()->BestUTF8(blob_order[i], !reading_direction_is_ltr);
*text += it_->word()->BestUTF8(blob_order[i], false);
}
AppendSuffixMarks(text);
}
Expand Down Expand Up @@ -643,6 +649,9 @@ void ResultIterator::IterateAndAppendUTF8TextlineText(STRING *text) {
}
AppendUTF8WordText(text);
words_appended++;
if (BidiDebug(2)) {
tprintf("Num spaces=%d, text=%s\n", numSpaces, text->string());
}
} while (Next(RIL_WORD) && !IsAtBeginningOf(RIL_TEXTLINE));
if (BidiDebug(1)) {
tprintf("%d words printed\n", words_appended);
Expand Down
4 changes: 4 additions & 0 deletions ccmain/resultiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class TESS_API ResultIterator : public LTRResultIterator {
virtual bool IsAtFinalElement(PageIteratorLevel level,
PageIteratorLevel element) const;

// ============= Functions that refer to words only ============.
// Returns the number of blanks before the current word.
int BlanksBeforeWord() const;

// ============= Accessing data ==============.

/**
Expand Down

0 comments on commit 4e8018d

Please sign in to comment.