21 #include "config_auto.h"
31 #ifndef DISABLED_LEGACY_ENGINE
40 #ifndef DISABLED_LEGACY_ENGINE
63 TBOX &selection_box) {
79 int16_t good_char_qual;
84 if (lstm_recognizer_ ==
nullptr) {
85 #ifndef DISABLED_LEGACY_ENGINE
87 #endif // ndef DISABLED_LEGACY_ENGINE
91 #ifndef DISABLED_LEGACY_ENGINE
95 tprintf(
"\n%d chars; word_blob_quality: %d; outline_errs: %d; "
96 "char_quality: %d; good_char_quality: %d\n",
101 #endif // ndef DISABLED_LEGACY_ENGINE
121 const TBOX& target_word_box,
122 const char* word_config,
124 if (word_config !=
nullptr) {
126 if (backup_config_file_ ==
nullptr) {
128 FILE* config_fp = fopen(backup_config_file_,
"wb");
129 if (config_fp ==
nullptr) {
130 tprintf(
"Error, failed to open file \"%s\"\n", backup_config_file_);
140 if (backup_config_file_ !=
nullptr) {
144 backup_config_file_ =
nullptr;
147 }
else if (pass > 1 && !word_box.
major_overlap(target_word_box)) {
155 const TBOX* target_word_box,
156 const char* word_config,
163 if (target_word_box ==
nullptr ||
165 *target_word_box, word_config, 1)) {
170 for (
int w = 0; w < words->
size(); ++w) {
172 if (w > 0) (*words)[w].prev_word = &(*words)[w - 1];
178 if (pass_n == 1 || !word->
word->
done) {
186 }
else if (pass_n == 2) {
193 for (
int s = 0; s <= sub_langs_.size(); ++s) {
195 Tesseract* lang_t = s < sub_langs_.size() ? sub_langs_[s] :
this;
201 word_res->SetupForRecognition(
222 for (
int w = 0; w < words->
size(); ++w) {
224 if (w > 0) word->
prev_word = &(*words)[w - 1];
225 if (monitor !=
nullptr) {
241 for (; w < words->
size(); ++w) {
255 while (pr_it->
word() !=
nullptr && pr_it->
word() != word->
word)
258 bool make_next_word_fuzzy =
false;
259 #ifndef DISABLED_LEGACY_ENGINE
265 #endif // ndef DISABLED_LEGACY_ENGINE
269 tprintf(
"Pass%d: %s [%s]\n", pass_n,
274 if (make_next_word_fuzzy && pr_it->
word() !=
nullptr) {
304 const TBOX* target_word_box,
305 const char* word_config,
314 if (dopasses==0 || dopasses==1) {
318 #ifndef DISABLED_LEGACY_ENGINE
329 for (
int i = 0; i < sub_langs_.size(); ++i) {
331 sub_langs_[i]->SwitchAdaptiveClassifier();
333 sub_langs_[i]->StartBackupAdaptiveClassifier();
337 #endif // ndef DISABLED_LEGACY_ENGINE
343 #ifndef DISABLED_LEGACY_ENGINE
347 #endif // ndef DISABLED_LEGACY_ENGINE
358 most_recently_used_ =
this;
383 if (dopasses == 1)
return true;
385 #ifndef DISABLED_LEGACY_ENGINE
396 most_recently_used_ =
this;
427 #endif // ndef DISABLED_LEGACY_ENGINE
434 #ifndef DISABLED_LEGACY_ENGINE
440 #endif //ndef DISABLED_LEGACY_ENGINE
442 const auto pageseg_mode =
static_cast<PageSegMode>(
459 if (monitor !=
nullptr) {
465 #ifndef DISABLED_LEGACY_ENGINE
474 while (word_it.
forward() !=
nullptr &&
478 if (!word_it.
word())
break;
485 tprintf(
"Skipping because one of the words is W_REP_CHAR\n");
510 tprintf(
"Top choice \"%s %s\" verified by bigram model.\n",
516 tprintf(
"Examining alt choices for \"%s %s\".\n",
527 float best_rating = 0.0;
530 for (prev_it.mark_cycle_pt(); !prev_it.cycled_list(); prev_it.forward()) {
539 for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
550 if (overrides_word1.
size() == 1 ||
553 best_idx = overrides_word1.
size() - 1;
558 if (!overrides_word1.
empty()) {
561 *overrides_word1[best_idx]) &&
563 *overrides_word2[best_idx])) {
565 tprintf(
"Top choice \"%s %s\" verified (sans case) by bigram "
566 "model.\n", orig_w1_str.
string(), orig_w2_str.
string());
570 const STRING new_w1_str = overrides_word1[best_idx]->unichar_string();
571 const STRING new_w2_str = overrides_word2[best_idx]->unichar_string();
572 if (new_w1_str != orig_w1_str) {
575 if (new_w2_str != orig_w2_str) {
579 STRING choices_description;
580 int num_bigram_choices
581 = overrides_word1.
size() * overrides_word2.
size();
582 if (num_bigram_choices == 1) {
583 choices_description =
"This was the unique bigram choice.";
587 const int kMaxChoicesToPrint = 20;
588 for (
int i = 0; i < overrides_word1.
size() &&
589 i < kMaxChoicesToPrint; i++) {
590 if (i > 0) { bigrams_list +=
", "; }
595 choices_description =
"There were many choices: {";
596 choices_description += bigrams_list;
597 choices_description +=
"}";
599 choices_description.
add_str_int(
"There were ", num_bigram_choices);
600 choices_description +=
" compatible bigrams.";
603 tprintf(
"Replaced \"%s %s\" with \"%s %s\" with bigram model. %s\n",
606 choices_description.
string());
614 const TBOX* target_word_box,
615 const char* word_config) {
624 if (monitor !=
nullptr) {
637 if (target_word_box &&
639 *target_word_box, word_config, 4)) {
653 int16_t all_char_quality;
654 int16_t accepted_all_char_quality;
656 &all_char_quality, &accepted_all_char_quality);
667 (blob_quality == 0) && (outline_errs >= chars_in_word))
675 (
"QUALITY: num_chs= %d num_rejs= %d %5.3f blob_qual= %d %5.3f"
676 " outline_errs= %d %5.3f char_qual= %d %5.3f good_ch_qual= %d %5.3f\n",
690 bool good_quality_doc =
708 #endif // ndef DISABLED_LEGACY_ENGINE
744 float word_x_height = word->
x_height;
745 if (word_x_height < word->best_choice->min_x_height() ||
753 const double small_cap_delta = (x_height - small_cap_xheight) / 2.0;
755 small_cap_xheight - small_cap_delta <= word_x_height &&
756 word_x_height <= small_cap_xheight + small_cap_delta) {
766 if (num_upper > 0 && num_lower == 0)
777 *next_left = INT32_MAX;
778 if (index < words.
size()) {
779 *right = words[index]->word->bounding_box().right();
780 if (index + 1 < words.
size())
781 *next_left = words[index + 1]->word->bounding_box().left();
787 static void EvaluateWordSpan(
const PointerVector<WERD_RES>& words,
788 int first_index,
int end_index,
float* rating,
789 float* certainty,
bool* bad,
790 bool* valid_permuter) {
791 if (end_index <= first_index) {
793 *valid_permuter =
false;
795 for (
int index = first_index; index < end_index && index < words.size();
798 if (choice ==
nullptr) {
801 *rating += choice->
rating();
802 *certainty = std::min(*certainty, choice->
certainty());
804 *valid_permuter =
false;
816 static int SelectBestWords(
double rating_ratio,
817 double certainty_margin,
819 PointerVector<WERD_RES>* new_words,
820 PointerVector<WERD_RES>* best_words) {
826 int num_best = 0, num_new = 0;
827 while (b < best_words->size() || n < new_words->size()) {
829 int start_b = b, start_n = n;
830 while (b < best_words->size() || n < new_words->size()) {
831 int b_right = -INT32_MAX;
832 int next_b_left = INT32_MAX;
833 WordGap(*best_words, b, &b_right, &next_b_left);
834 int n_right = -INT32_MAX;
835 int next_n_left = INT32_MAX;
836 WordGap(*new_words, n, &n_right, &next_n_left);
837 if (std::max(b_right, n_right) < std::min(next_b_left, next_n_left)) {
842 if ((b_right < n_right && b < best_words->size()) ||
843 n == new_words->size())
849 float b_rating = 0.0f, n_rating = 0.0f;
851 float b_certainty = 0.0f, n_certainty = 0.0f;
853 bool b_bad =
false, n_bad =
false;
855 bool b_valid_permuter =
true, n_valid_permuter =
true;
856 const int end_b = b < best_words->size() ? b + 1 : b;
857 const int end_n = n < new_words->size() ? n + 1 : n;
858 EvaluateWordSpan(*best_words, start_b, end_b, &b_rating, &b_certainty,
859 &b_bad, &b_valid_permuter);
860 EvaluateWordSpan(*new_words, start_n, end_n, &n_rating, &n_certainty,
861 &n_bad, &n_valid_permuter);
862 bool new_better =
false;
863 if (!n_bad && (b_bad || (n_certainty > b_certainty &&
864 n_rating < b_rating) ||
865 (!b_valid_permuter && n_valid_permuter &&
866 n_rating < b_rating * rating_ratio &&
867 n_certainty > b_certainty - certainty_margin))) {
869 for (
int i = start_n; i < end_n; ++i) {
871 (*new_words)[i] =
nullptr;
877 for (
int i = start_b; i < end_b; ++i) {
879 (*best_words)[i] =
nullptr;
884 tprintf(
"%d new words %s than %d old words: r: %g v %g c: %g v %g"
885 " valid dict: %d v %d\n",
886 end_n - start_n, new_better ?
"better" :
"worse",
887 end_b - start_b, n_rating, b_rating,
888 n_certainty, b_certainty, n_valid_permuter, b_valid_permuter);
896 for (
int i = 0; i < out_words.
size(); ++i)
897 best_words->push_back(out_words[i]);
898 return num_new - num_best;
909 tprintf(
"Trying word using lang %s, oem %d\n",
914 (this->*recognizer)(word_data, in_word, &new_words);
915 if (new_words.
empty()) {
922 for (
int i = 0; i < new_words.
size(); ++i)
923 new_words[i]->DebugTopChoice(
"Lang result");
929 debug, &new_words, best_words);
934 for (
int w = 0; w < words.
size(); ++w) {
935 if (words[w]->tess_failed || !words[w]->tess_accepted)
return false;
940 #ifndef DISABLED_LEGACY_ENGINE
946 bool* make_next_word_fuzzy) {
947 *make_next_word_fuzzy =
false;
961 &word_wanted, &overlapped_any_blob,
969 int num_overlapped = 0;
970 int num_overlapped_used = 0;
971 for (
int i = 0; i < overlapped_any_blob.
size(); ++i) {
972 if (overlapped_any_blob[i]) {
974 if (word_wanted[i]) ++num_overlapped_used;
978 outlines[i] =
nullptr;
984 int non_overlapped = 0;
985 int non_overlapped_used = 0;
986 for (
int i = 0; i < word_wanted.
size(); ++i) {
987 if (word_wanted[i]) ++non_overlapped_used;
988 if (outlines[i] !=
nullptr) ++non_overlapped_used;
991 tprintf(
"Used %d/%d overlapped %d/%d non-overlaped diacritics on word:",
992 num_overlapped_used, num_overlapped, non_overlapped_used,
998 make_next_word_fuzzy)) {
1003 return num_overlapped_used != 0 || non_overlapped_used != 0;
1025 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
1026 C_BLOB* blob = blob_it.data();
1029 int num_blob_outlines = 0;
1030 for (
int i = 0; i < outlines.
size(); ++i) {
1032 !(*word_wanted)[i]) {
1033 blob_wanted[i] =
true;
1034 (*overlapped_any_blob)[i] =
true;
1035 ++num_blob_outlines;
1039 tprintf(
"%d noise outlines overlap blob at:", num_blob_outlines);
1048 outlines, num_blob_outlines,
1050 for (
int i = 0; i < blob_wanted.
size(); ++i) {
1051 if (blob_wanted[i]) {
1053 (*word_wanted)[i] =
true;
1054 (*target_blobs)[i] = blob;
1072 for (
int i = 0; i < outlines.
size(); ++i) {
1073 if (outlines[i] ==
nullptr)
continue;
1076 int num_blob_outlines = 0;
1077 TBOX total_ol_box(outlines[i]->bounding_box());
1078 while (i < outlines.
size() && outlines[i] !=
nullptr) {
1079 blob_wanted[i] =
true;
1080 total_ol_box += outlines[i]->bounding_box();
1082 ++num_blob_outlines;
1086 while (!blob_it.at_last() &&
1087 blob_it.data_relative(1)->bounding_box().left() <=
1088 total_ol_box.
left()) {
1094 tprintf(
"Num blobless outlines = %d\n", num_blob_outlines);
1095 C_BLOB* left_blob = blob_it.data();
1097 C_BLOB* right_blob = blob_it.at_last() ? nullptr : blob_it.data_relative(1);
1098 if ((left_box.
x_overlap(total_ol_box) || right_blob ==
nullptr ||
1101 outlines, num_blob_outlines,
1104 for (
int j = 0; j < blob_wanted.
size(); ++j) {
1105 if (blob_wanted[j]) {
1106 (*word_wanted)[j] =
true;
1107 (*target_blobs)[j] = left_blob;
1110 }
else if (right_blob !=
nullptr &&
1114 right_blob, outlines,
1115 num_blob_outlines, &blob_wanted)) {
1117 for (
int j = 0; j < blob_wanted.
size(); ++j) {
1118 if (blob_wanted[j]) {
1119 (*word_wanted)[j] =
true;
1120 (*target_blobs)[j] = right_blob;
1124 outlines, num_blob_outlines,
1127 for (
int j = 0; j < blob_wanted.
size(); ++j) {
1128 if (blob_wanted[j]) {
1129 (*word_wanted)[j] =
true;
1130 (*target_blobs)[j] =
nullptr;
1145 float target_cert = certainty_threshold;
1146 if (blob !=
nullptr) {
1150 tprintf(
"No Noise blob classified as %s=%g(%g) at:", best_str.
string(),
1151 target_cert, target_c2);
1161 pr_it, blob, &all_str);
1164 for (
int i = 0; i < test_outlines.
size(); ++i) {
1165 if (test_outlines[i]) ol_box += outlines[i]->bounding_box();
1167 tprintf(
"All Noise blob classified as %s=%g, delta=%g at:",
1168 all_str.
string(), best_cert, best_cert - target_cert);
1174 while (num_outlines > 1 && best_index >= 0 &&
1175 (blob ==
nullptr || best_cert < target_cert || blob !=
nullptr)) {
1178 for (
int i = 0; i < outlines.
size(); ++i) {
1179 if (test_outlines[i]) {
1180 test_outlines[i] =
false;
1186 for (
int j = 0; j < outlines.
size(); ++j) {
1187 if (test_outlines[j]) ol_box += outlines[j]->bounding_box();
1188 tprintf(
"%d", test_outlines[j]);
1190 tprintf(
" blob classified as %s=%g, delta=%g) at:", str.
string(),
1191 cert, cert - target_cert);
1194 if (cert > best_cert) {
1197 best_outlines = test_outlines;
1199 test_outlines[i] =
true;
1202 if (best_index >= 0) {
1203 test_outlines[best_index] =
false;
1207 if (best_cert >= target_cert) {
1209 *ok_outlines = best_outlines;
1211 tprintf(
"%s noise combination ", blob ?
"Adding" :
"New");
1212 for (
int i = 0; i < best_outlines.
size(); ++i) {
1213 tprintf(
"%d", best_outlines[i]);
1215 tprintf(
" yields certainty %g, beating target of %g\n", best_cert,
1232 C_BLOB* local_blob =
nullptr;
1233 if (blob !=
nullptr) {
1235 ol_it.set_to_list(blob->
out_list());
1236 first_to_keep = ol_it.data();
1238 for (
int i = 0; i < ok_outlines.
size(); ++i) {
1239 if (ok_outlines[i]) {
1241 if (blob ==
nullptr) {
1242 local_blob =
new C_BLOB(outlines[i]);
1244 ol_it.set_to_list(blob->
out_list());
1246 ol_it.add_before_stay_put(outlines[i]);
1252 ol_it.move_to_first();
1253 if (first_to_keep ==
nullptr) {
1255 for (; !ol_it.empty(); ol_it.forward()) ol_it.extract();
1260 for (; ol_it.data() != first_to_keep; ol_it.forward()) {
1286 tprintf(
"word xheight=%g, row=%g, range=[%g,%g]\n", word_res->
x_height,
1290 tprintf(
"Got word with null raw choice xheight=%g, row=%g\n", word_res->
x_height,
1298 *c2 = rat > 0.0f ? cert * cert / rat : 0.0f;
1309 #endif // ndef DISABLED_LEGACY_ENGINE
1321 #ifdef DISABLED_LEGACY_ENGINE
1326 #endif // def DISABLED_LEGACY_ENGINE
1332 clock_t start_t = clock();
1335 tprintf(
"%s word with lang %s at:",
1336 word->
done ?
"Already done" :
"Processing",
1346 int sub = sub_langs_.size();
1347 if (most_recently_used_ !=
this) {
1349 for (sub = 0; sub < sub_langs_.size() &&
1350 most_recently_used_ != sub_langs_[sub]; ++sub) {}
1353 *word_data, recognizer, debug, &word_data->
lang_words[sub], &best_words);
1354 Tesseract* best_lang_tess = most_recently_used_;
1355 if (!WordsAcceptable(best_words)) {
1357 if (most_recently_used_ !=
this &&
1361 best_lang_tess =
this;
1363 for (
int i = 0; !WordsAcceptable(best_words) && i < sub_langs_.size();
1365 if (most_recently_used_ != sub_langs_[i] &&
1369 best_lang_tess = sub_langs_[i];
1373 most_recently_used_ = best_lang_tess;
1374 if (!best_words.
empty()) {
1375 if (best_words.
size() == 1 && !best_words[0]->combination) {
1380 word_data->
word = best_words.
back();
1387 clock_t ocr_t = clock();
1389 tprintf(
"%s (ocr took %.2f sec)\n",
1391 static_cast<double>(ocr_t-start_t)/CLOCKS_PER_SEC);
1404 ROW* row = word_data.
row;
1408 #ifndef ANDROID_BUILD
1409 #ifdef DISABLED_LEGACY_ENGINE
1414 #endif // def DISABLED_LEGACY_ENGINE
1417 if (!out_words->
empty())
1426 #ifndef DISABLED_LEGACY_ENGINE
1433 #endif // ndef DISABLED_LEGACY_ENGINE
1435 #endif // ndef ANDROID_BUILD
1437 #ifndef DISABLED_LEGACY_ENGINE
1458 #endif // ndef DISABLED_LEGACY_ENGINE
1464 tprintf(
"New XHT Match:%s = %s ",
1475 new_x_ht > 0.1 ?
"STILL DOUBT" :
"OK",
1476 accept_new_word ?
"ACCEPTED" :
"");
1479 #ifndef DISABLED_LEGACY_ENGINE
1487 if (original_misfits == 0)
1489 float baseline_shift = 0.0f;
1491 if (baseline_shift != 0.0f) {
1497 if (original_misfits > 0) {
1498 float new_baseline_shift;
1520 float baseline_shift,
float new_x_ht,
1522 bool accept_new_x_ht =
false;
1539 tprintf(
"Old misfits=%d with x-height %f, new=%d with x-height %f\n",
1541 new_misfits, new_x_ht);
1542 tprintf(
"Old rating= %f, certainty=%f, new=%f, %f\n",
1548 accept_new_x_ht = new_misfits < original_misfits &&
1557 if (accept_new_x_ht) {
1564 #endif // ndef DISABLED_LEGACY_ENGINE
1579 #ifndef DISABLED_LEGACY_ENGINE
1580 ROW* row = word_data.
row;
1607 #ifndef GRAPHICS_DISABLED
1621 #endif // ndef DISABLED_LEGACY_ENGINE
1624 #ifndef DISABLED_LEGACY_ENGINE
1642 tprintf(
"POST FIX_QUOTES FAIL String:\"%s\"; Strlen=%d;"
1659 #endif // ndef DISABLED_LEGACY_ENGINE
1670 if (choice !=
nullptr) {
1671 if (best_choice ==
nullptr || choice->
rating() < best_choice->
rating())
1672 best_choice = choice;
1681 static void CorrectRepcharChoices(
BLOB_CHOICE* blob_choice,
1687 if (choice ==
nullptr) {
1689 choice_it.add_before_stay_put(
new BLOB_CHOICE(*blob_choice));
1693 for (
int i = 0; i < word->
length(); ++i) {
1712 for (
int i = 0; i < word.
length(); ++i) {
1718 int max_count = rep_ch.
MaxCount(&maxch_id);
1720 BLOB_CHOICE* best_choice = FindBestMatchingChoice(maxch_id, word_res);
1721 if (best_choice ==
nullptr) {
1722 tprintf(
"Failed to find a choice for %s, occurring %d times\n",
1726 word_res->
done =
true;
1732 C_BLOB* prev_blob = blob_it.data();
1733 for (blob_it.forward(); !blob_it.at_first(); blob_it.forward()) {
1734 C_BLOB* blob = blob_it.data();
1741 CorrectRepcharChoices(best_choice, word_res);
1746 const UNICHARSET& char_set,
const char *s,
const char *lengths) {
1749 int leading_punct_count;
1750 int upper_count = 0;
1751 int hyphen_pos = -1;
1754 if (strlen (lengths) > 20)
1760 offset += lengths[i++];
1761 leading_punct_count = i;
1764 while (s[offset] !=
'\0' && char_set.
get_isupper(s + offset, lengths[i])) {
1765 offset += lengths[i++];
1768 if (upper_count > 1) {
1772 while (s[offset] !=
'\0' && char_set.
get_islower(s + offset, lengths[i])) {
1773 offset += lengths[i++];
1781 if (lengths[i] == 1 && s[offset] ==
'-') {
1783 offset += lengths[i++];
1784 if (s[offset] !=
'\0') {
1785 while ((s[offset] !=
'\0') &&
1787 offset += lengths[i++];
1789 if (i < hyphen_pos + 3)
1794 if (lengths[i] == 1 && (s[offset] ==
'\'') &&
1795 lengths[i + 1] == 1 && (s[offset + lengths[i]] ==
's')) {
1796 offset += lengths[i++];
1797 offset += lengths[i++];
1800 if (upper_count > 0)
1807 if (lengths[i] == 1 && s[offset] !=
'\0' &&
1809 offset += lengths[i++];
1810 if (lengths[i] == 1 && s[offset] !=
'\0' && i > 0 &&
1811 s[offset - lengths[i - 1]] != s[offset] &&
1813 offset += lengths[i++];
1815 if (s[offset] !=
'\0')
1824 if (s[0] !=
'\0' && char_set.
get_isupper(s, lengths[0])) {
1826 while (s[offset] !=
'\0' &&
1828 lengths[i + 1] == 1 && s[offset + lengths[i]] ==
'.') {
1829 offset += lengths[i++];
1830 offset += lengths[i++];
1833 else if (s[0] !=
'\0' && char_set.
get_islower(s, lengths[0])) {
1835 while (s[offset] !=
'\0' &&
1837 lengths[i + 1] == 1 && s[offset + lengths[i]] ==
'.') {
1838 offset += lengths[i++];
1839 offset += lengths[i++];
1842 if (s[offset] !=
'\0')
1850 bool show_map_detail =
false;
1867 tprintf (
"classify_word_pass1 start\n");
1871 tprintf (
"make_reject_map: initial map");
1874 tprintf (
"make_reject_map: after NN");
1877 tprintf (
"classify_word_pass2 - START");
1880 tprintf (
"classify_word_pass2 - Pre Xht");
1883 tprintf (
"classify_word_pass2 - END");
1884 show_map_detail =
true;
1896 tprintf (
"After Poor quality rejection");
1899 tprintf (
"unrej_good_quality_words - START");
1902 tprintf (
"unrej_good_quality_words - END");
1905 tprintf (
"Write results pass");
1906 show_map_detail =
true;
1913 if (show_map_detail) {
1921 tprintf(
"null best choice\n");
1924 tprintf (
"Done flag: %s\n\n", word->
done ?
"TRUE" :
"FALSE");
1936 static void find_modal_font(
1945 font =
static_cast<int16_t
>(fonts->
mode ());
1948 *font_count =
count < INT8_MAX ?
count : INT8_MAX;
1949 fonts->
add (font, -*font_count);
1968 #ifndef DISABLED_LEGACY_ENGINE
1970 if (fontinfo_size == 0)
return;
1976 tprintf(
"Examining fonts in %s\n",
1981 if (choice ==
nullptr)
continue;
1983 for (
int f = 0; f < fonts.
size(); ++f) {
1984 const int fontinfo_id = fonts[f].fontinfo_id;
1985 if (0 <= fontinfo_id && fontinfo_id < fontinfo_size) {
1986 font_total_score[fontinfo_id] += fonts[f].score;
1991 int score1 = 0, score2 = 0;
1992 int16_t font_id1 = -1, font_id2 = -1;
1993 for (
int f = 0; f < fontinfo_size; ++f) {
1995 tprintf(
"Font %s, total score = %d\n",
1998 if (font_total_score[f] > score1) {
2000 font_id2 = font_id1;
2001 score1 = font_total_score[f];
2003 }
else if (font_total_score[f] > score2) {
2004 score2 = font_total_score[f];
2018 tprintf(
"Word modal font=%s, score=%d, 2nd choice %s/%d\n",
2023 tprintf(
"Word modal font=%s, score=%d. No 2nd choice\n",
2028 #endif // ndef DISABLED_LEGACY_ENGINE
2031 #ifndef DISABLED_LEGACY_ENGINE
2040 STATS doc_fonts(0, font_table_size_);
2045 word = page_res_it.
word();
2054 int8_t doc_font_count;
2055 find_modal_font(&doc_fonts, &doc_font, &doc_font_count);
2056 if (doc_font_count == 0)
2059 const FontInfo* modal_font =
nullptr;
2062 word = page_res_it.
word();
2077 word = page_res_it.
word();
2081 if (!(
count == length || (length > 3 &&
count >= length * 3 / 4))) {
2088 #endif // ndef DISABLED_LEGACY_ENGINE
2097 if (word->best_choices.singleton())
2101 if (word->tesseract->getDict().valid_word(*best) != 0)
2104 WERD_CHOICE_IT choice_it(&word->best_choices);
2105 for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
2106 choice_it.forward()) {
2108 if (word->tesseract->getDict().valid_word(*alternate)) {
2111 tprintf(
"Dictionary correction replaces best choice '%s' with '%s'\n",
2116 word->ReplaceBestChoice(alternate);