150 {
155 do {
157 const PAGE_RES_IT *pr_it = it->PageResIt();
158 WERD_RES *word = pr_it->word();
159
160 TBOX word_box = word->word->bounding_box();
161 bool small_word = word_box.height() * 1.5 < line_height;
162 bool tall_word = word_box.height() * 1.125 > line_height;
163
164
165 int padding;
166 if (small_word) {
167 padding = word_box.height();
168 } else if (tall_word) {
169 padding = word_box.height() / 3;
170 } else {
171 padding = word_box.height() / 2;
172 }
173
175
176
177 TBOX upper_box(word_box);
178 upper_box.set_bottom(word_box.top());
179 upper_box.set_top(word_box.top() + padding);
181 EvaluateBox(upper_box,
true, -1, text,
"Upper Word not vertical");
182 TBOX lower_box = word_box;
183 lower_box.set_top(word_box.bottom());
184 lower_box.set_bottom(word_box.bottom() - padding);
185 if (tall_word) {
186 lower_box.move(ICOORD(0, padding / 2));
187 }
189 EvaluateBox(lower_box,
true, -1, text,
"Lower Word not vertical");
190
191
192
193 bool upper_or_lower_out_of_textline =
196 if (!upper_or_lower_out_of_textline) {
199 }
201
202
203
204
205
206 padding = line_height / 4;
207 upper_box.set_top(upper_box.bottom() + padding);
208 TBOX target_box(word_box);
209 if (!small_word) {
210 upper_box.move(ICOORD(0, -padding * 3 / 2));
211 }
212 target_box.set_top(upper_box.bottom());
213 TBOX upper_challenger(upper_box);
214 upper_challenger.set_bottom(upper_box.top());
215 upper_challenger.set_top(upper_box.top() + word_box.height());
216 EvaluateDistance(upper_box, target_box, upper_challenger, text,
"Upper Word");
217 if (tall_word) {
218 lower_box.move(ICOORD(0, padding / 2));
219 }
220 lower_box.set_bottom(lower_box.top() - padding);
221 target_box = word_box;
222 target_box.set_bottom(lower_box.top());
223 TBOX lower_challenger(lower_box);
224 lower_challenger.set_top(lower_box.bottom());
225 lower_challenger.set_bottom(lower_box.bottom() - word_box.height());
226 EvaluateDistance(lower_box, target_box, lower_challenger, text,
"Lower Word");
227
228 delete[] text;
230 delete it;
231 }
#define EXPECT_TRUE(condition)
const int kMinStrongTextValue
int Recognize(ETEXT_DESC *monitor)
MutableIterator * GetMutableIterator()
virtual char * GetUTF8Text(PageIteratorLevel level) const
bool BoxOutOfHTextline(const TBOX &box, const DENORM *denorm, bool debug) const
void EvaluateDistance(const TBOX &box, const TBOX &true_box, const TBOX &false_box, const char *text, const char *message)
void EvaluateBox(const TBOX &box, bool greater_or_equal, int target_value, const char *text, const char *message)
void SetImage(const char *filename)