Skip to content

Commit

Permalink
preserve interword spaces patch - Issue 1409
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenop committed Jan 27, 2015
1 parent e0441d0 commit 36883b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
12 changes: 10 additions & 2 deletions ccmain/resultiterator.cpp
Expand Up @@ -34,6 +34,12 @@ ResultIterator::ResultIterator(const LTRResultIterator &resit)
: LTRResultIterator(resit) {
in_minor_direction_ = false;
at_beginning_of_minor_run_ = false;

BoolParam *p = ParamUtils::FindParam<BoolParam>(
"preserve_interword_spaces", GlobalParams()->bool_params,
tesseract_->params()->bool_params);
if (p != NULL) preserve_interword_spaces_ = (bool)(*p);

current_paragraph_is_ltr_ = CurrentParagraphIsLtr();
MoveToLogicalStartOfTextline();
}
Expand Down Expand Up @@ -629,14 +635,16 @@ void ResultIterator::IterateAndAppendUTF8TextlineText(STRING *text) {

int words_appended = 0;
do {
int numSpaces = preserve_interword_spaces_ ? it_->word()->word->space() : 1;
for(int i = 0 ; i < numSpaces ; ++i) {
*text += " ";
}
AppendUTF8WordText(text);
words_appended++;
*text += " ";
} while (Next(RIL_WORD) && !IsAtBeginningOf(RIL_TEXTLINE));
if (BidiDebug(1)) {
tprintf("%d words printed\n", words_appended);
}
text->truncate_at(text->length() - 1);
*text += line_separator_;
// If we just finished a paragraph, add an extra newline.
if (it_->block() == NULL || IsAtBeginningOf(RIL_PARA))
Expand Down
12 changes: 9 additions & 3 deletions ccmain/resultiterator.h
Expand Up @@ -46,8 +46,8 @@ class TESS_API ResultIterator : public LTRResultIterator {
virtual ~ResultIterator() {}

// ============= Moving around within the page ============.
/**
* Moves the iterator to point to the start of the page to begin
/**
* Moves the iterator to point to the start of the page to begin
* an iteration.
*/
virtual void Begin();
Expand Down Expand Up @@ -181,7 +181,7 @@ class TESS_API ResultIterator : public LTRResultIterator {
void MoveToLogicalStartOfTextline();

/**
* Precondition: current_paragraph_is_ltr_ and in_minor_direction_
* Precondition: current_paragraph_is_ltr_ and in_minor_direction_
* are set.
*/
void MoveToLogicalStartOfWord();
Expand Down Expand Up @@ -231,6 +231,12 @@ class TESS_API ResultIterator : public LTRResultIterator {

/** Is the currently pointed-at character in a minor-direction sequence? */
bool in_minor_direction_;

/**
* Should detected inter-word spaces be preserved, or "compressed" to a single
* space character (default behavior).
*/
bool preserve_interword_spaces_ = false;
};

} // namespace tesseract.
Expand Down
2 changes: 2 additions & 0 deletions ccmain/tesseractclass.cpp
Expand Up @@ -440,6 +440,8 @@ Tesseract::Tesseract()
this->params()),
INT_MEMBER(tessedit_parallelize, 0, "Run in parallel where possible",
this->params()),
BOOL_MEMBER(preserve_interword_spaces, false,
"Preserve multiple interword spaces", this->params()),

// The following parameters were deprecated and removed from their original
// locations. The parameters are temporarily kept here to give Tesseract
Expand Down
1 change: 1 addition & 0 deletions ccmain/tesseractclass.h
Expand Up @@ -1009,6 +1009,7 @@ class Tesseract : public Wordrec {
double_VAR_H(textord_tabfind_aligned_gap_fraction, 0.75,
"Fraction of height used as a minimum gap for aligned blobs.");
INT_VAR_H(tessedit_parallelize, 0, "Run in parallel where possible");
BOOL_VAR_H(preserve_interword_spaces, false, "Preserve multiple interword spaces");

// The following parameters were deprecated and removed from their original
// locations. The parameters are temporarily kept here to give Tesseract
Expand Down

0 comments on commit 36883b4

Please sign in to comment.