tesseract  4.00.00dev
resultiterator.h
Go to the documentation of this file.
1 // File: resultiterator.h
3 // Description: Iterator for tesseract results that is capable of
4 // iterating in proper reading order over Bi Directional
5 // (e.g. mixed Hebrew and English) text.
6 // Author: David Eger
7 // Created: Fri May 27 13:58:06 PST 2011
8 //
9 // (C) Copyright 2011, Google Inc.
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 // http://www.apache.org/licenses/LICENSE-2.0
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 //
21 
22 #ifndef TESSERACT_CCMAIN_RESULT_ITERATOR_H_
23 #define TESSERACT_CCMAIN_RESULT_ITERATOR_H_
24 
25 #include "platform.h"
26 #include "ltrresultiterator.h"
27 
28 template <typename T> class GenericVector;
29 template <typename T> class GenericVectorEqEq;
30 class BLOB_CHOICE_IT;
31 class WERD_RES;
32 class STRING;
33 
34 namespace tesseract {
35 
36 class Tesseract;
37 
39  public:
40  static ResultIterator *StartOfParagraph(const LTRResultIterator &resit);
41 
46  virtual ~ResultIterator() {}
47 
48  // ============= Moving around within the page ============.
53  virtual void Begin();
54 
67  virtual bool Next(PageIteratorLevel level);
68 
75  virtual bool IsAtBeginningOf(PageIteratorLevel level) const;
76 
82  virtual bool IsAtFinalElement(PageIteratorLevel level,
83  PageIteratorLevel element) const;
84 
85  // ============= Accessing data ==============.
86 
91  virtual char* GetUTF8Text(PageIteratorLevel level) const;
92 
97  bool ParagraphIsLtr() const;
98 
99  // ============= Exposed only for testing =============.
100 
123  static void CalculateTextlineOrder(
124  bool paragraph_is_ltr,
125  const GenericVector<StrongScriptDirection> &word_dirs,
126  GenericVectorEqEq<int> *reading_order);
127 
128  static const int kMinorRunStart;
129  static const int kMinorRunEnd;
130  static const int kComplexWord;
131 
132  protected:
139  TESS_LOCAL explicit ResultIterator(const LTRResultIterator &resit);
140 
141  private:
146  bool CurrentParagraphIsLtr() const;
147 
159  void CalculateTextlineOrder(bool paragraph_is_ltr,
160  const LTRResultIterator &resit,
161  GenericVectorEqEq<int> *indices) const;
163  void CalculateTextlineOrder(bool paragraph_is_ltr,
164  const LTRResultIterator &resit,
166  GenericVectorEqEq<int> *indices) const;
167 
172  int LTRWordIndex() const;
173 
178  void CalculateBlobOrder(GenericVector<int> *blob_indices) const;
179 
181  void MoveToLogicalStartOfTextline();
182 
187  void MoveToLogicalStartOfWord();
188 
190  bool IsAtFinalSymbolOfWord() const;
191 
193  bool IsAtFirstSymbolOfWord() const;
194 
199  void AppendSuffixMarks(STRING *text) const;
200 
202  void AppendUTF8WordText(STRING *text) const;
203 
211  void IterateAndAppendUTF8TextlineText(STRING *text);
212 
219  void AppendUTF8ParagraphText(STRING *text) const;
220 
222  bool BidiDebug(int min_level) const;
223 
224  bool current_paragraph_is_ltr_;
225 
230  bool at_beginning_of_minor_run_;
231 
233  bool in_minor_direction_;
234 
239  bool preserve_interword_spaces_;
240 };
241 
242 } // namespace tesseract.
243 
244 #endif // TESSERACT_CCMAIN_RESULT_ITERATOR_H_
#define TESS_API
Definition: platform.h:81
static const int kComplexWord
Definition: strngs.h:45
static const int kMinorRunStart
#define TESS_LOCAL
Definition: platform.h:82
static const int kMinorRunEnd