Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/ccstruct/ocrrow.cpp @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /********************************************************************** | |
| 2 * File: ocrrow.cpp (Formerly row.c) | |
| 3 * Description: Code for the ROW class. | |
| 4 * Author: Ray Smith | |
| 5 * | |
| 6 * (C) Copyright 1991, Hewlett-Packard Ltd. | |
| 7 ** Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 ** you may not use this file except in compliance with the License. | |
| 9 ** You may obtain a copy of the License at | |
| 10 ** http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 ** Unless required by applicable law or agreed to in writing, software | |
| 12 ** distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 ** See the License for the specific language governing permissions and | |
| 15 ** limitations under the License. | |
| 16 * | |
| 17 **********************************************************************/ | |
| 18 | |
| 19 // Include automatically generated configuration file if running autoconf. | |
| 20 #ifdef HAVE_CONFIG_H | |
| 21 # include "config_auto.h" | |
| 22 #endif | |
| 23 | |
| 24 #include "blobbox.h" | |
| 25 #include "ocrrow.h" | |
| 26 | |
| 27 namespace tesseract { | |
| 28 | |
| 29 /********************************************************************** | |
| 30 * ROW::ROW | |
| 31 * | |
| 32 * Constructor to build a ROW. Only the stats stuff are given here. | |
| 33 * The words are added directly. | |
| 34 **********************************************************************/ | |
| 35 ROW::ROW( // constructor | |
| 36 int32_t spline_size, // no of segments | |
| 37 int32_t *xstarts, // segment boundaries | |
| 38 double *coeffs, // coefficients | |
| 39 float x_height, // line height | |
| 40 float ascenders, // ascender size | |
| 41 float descenders, // descender drop | |
| 42 int16_t kern, // char gap | |
| 43 int16_t space // word gap | |
| 44 ) | |
| 45 : baseline(spline_size, xstarts, coeffs), para_(nullptr) { | |
| 46 kerning = kern; // just store stuff | |
| 47 spacing = space; | |
| 48 xheight = x_height; | |
| 49 ascrise = ascenders; | |
| 50 bodysize = 0.0f; | |
| 51 descdrop = descenders; | |
| 52 has_drop_cap_ = false; | |
| 53 lmargin_ = 0; | |
| 54 rmargin_ = 0; | |
| 55 } | |
| 56 | |
| 57 /********************************************************************** | |
| 58 * ROW::ROW | |
| 59 * | |
| 60 * Constructor to build a ROW. Only the stats stuff are given here. | |
| 61 * The words are added directly. | |
| 62 **********************************************************************/ | |
| 63 | |
| 64 ROW::ROW( // constructor | |
| 65 TO_ROW *to_row, // source row | |
| 66 int16_t kern, // char gap | |
| 67 int16_t space // word gap | |
| 68 ) | |
| 69 : para_(nullptr) { | |
| 70 kerning = kern; // just store stuff | |
| 71 spacing = space; | |
| 72 xheight = to_row->xheight; | |
| 73 bodysize = to_row->body_size; | |
| 74 ascrise = to_row->ascrise; | |
| 75 descdrop = to_row->descdrop; | |
| 76 baseline = to_row->baseline; | |
| 77 has_drop_cap_ = false; | |
| 78 lmargin_ = 0; | |
| 79 rmargin_ = 0; | |
| 80 } | |
| 81 | |
| 82 // Returns the bounding box including the desired combination of upper and | |
| 83 // lower noise/diacritic elements. | |
| 84 TBOX ROW::restricted_bounding_box(bool upper_dots, bool lower_dots) const { | |
| 85 TBOX box; | |
| 86 // This is a read-only iteration of the words in the row. | |
| 87 WERD_IT it(const_cast<WERD_LIST *>(&words)); | |
| 88 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) { | |
| 89 box += it.data()->restricted_bounding_box(upper_dots, lower_dots); | |
| 90 } | |
| 91 return box; | |
| 92 } | |
| 93 | |
| 94 /********************************************************************** | |
| 95 * ROW::recalc_bounding_box | |
| 96 * | |
| 97 * Set the bounding box correctly | |
| 98 **********************************************************************/ | |
| 99 | |
| 100 void ROW::recalc_bounding_box() { // recalculate BB | |
| 101 WERD *word; // current word | |
| 102 WERD_IT it = &words; // words of ROW | |
| 103 int16_t left; // of word | |
| 104 int16_t prev_left; // old left | |
| 105 | |
| 106 if (!it.empty()) { | |
| 107 word = it.data(); | |
| 108 prev_left = word->bounding_box().left(); | |
| 109 it.forward(); | |
| 110 while (!it.at_first()) { | |
| 111 word = it.data(); | |
| 112 left = word->bounding_box().left(); | |
| 113 if (left < prev_left) { | |
| 114 it.move_to_first(); | |
| 115 // words in BB order | |
| 116 it.sort(word_comparator); | |
| 117 break; | |
| 118 } | |
| 119 prev_left = left; | |
| 120 it.forward(); | |
| 121 } | |
| 122 } | |
| 123 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) { | |
| 124 word = it.data(); | |
| 125 if (it.at_first()) { | |
| 126 word->set_flag(W_BOL, true); | |
| 127 } else { | |
| 128 // not start of line | |
| 129 word->set_flag(W_BOL, false); | |
| 130 } | |
| 131 if (it.at_last()) { | |
| 132 word->set_flag(W_EOL, true); | |
| 133 } else { | |
| 134 // not end of line | |
| 135 word->set_flag(W_EOL, false); | |
| 136 } | |
| 137 // extend BB as reqd | |
| 138 bound_box += word->bounding_box(); | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 /********************************************************************** | |
| 143 * ROW::move | |
| 144 * | |
| 145 * Reposition row by vector | |
| 146 **********************************************************************/ | |
| 147 | |
| 148 void ROW::move( // reposition row | |
| 149 const ICOORD vec // by vector | |
| 150 ) { | |
| 151 WERD_IT it(&words); // word iterator | |
| 152 | |
| 153 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) { | |
| 154 it.data()->move(vec); | |
| 155 } | |
| 156 | |
| 157 bound_box.move(vec); | |
| 158 baseline.move(vec); | |
| 159 } | |
| 160 | |
| 161 /********************************************************************** | |
| 162 * ROW::print | |
| 163 * | |
| 164 * Display members | |
| 165 **********************************************************************/ | |
| 166 | |
| 167 void ROW::print( // print | |
| 168 FILE *fp // file to print on | |
| 169 ) const { | |
| 170 tprintf("Kerning= %d\n", kerning); | |
| 171 tprintf("Spacing= %d\n", spacing); | |
| 172 bound_box.print(); | |
| 173 tprintf("Xheight= %f\n", xheight); | |
| 174 tprintf("Ascrise= %f\n", ascrise); | |
| 175 tprintf("Descdrop= %f\n", descdrop); | |
| 176 tprintf("has_drop_cap= %d\n", has_drop_cap_); | |
| 177 tprintf("lmargin= %d, rmargin= %d\n", lmargin_, rmargin_); | |
| 178 } | |
| 179 | |
| 180 /********************************************************************** | |
| 181 * ROW::plot | |
| 182 * | |
| 183 * Draw the ROW in the given colour. | |
| 184 **********************************************************************/ | |
| 185 | |
| 186 #ifndef GRAPHICS_DISABLED | |
| 187 void ROW::plot( // draw it | |
| 188 ScrollView *window, // window to draw in | |
| 189 ScrollView::Color colour // colour to draw in | |
| 190 ) { | |
| 191 WERD *word; // current word | |
| 192 WERD_IT it = &words; // words of ROW | |
| 193 | |
| 194 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) { | |
| 195 word = it.data(); | |
| 196 word->plot(window, colour); // all in one colour | |
| 197 } | |
| 198 } | |
| 199 | |
| 200 /********************************************************************** | |
| 201 * ROW::plot | |
| 202 * | |
| 203 * Draw the ROW in rainbow colours. | |
| 204 **********************************************************************/ | |
| 205 | |
| 206 void ROW::plot( // draw it | |
| 207 ScrollView *window // window to draw in | |
| 208 ) { | |
| 209 WERD *word; // current word | |
| 210 WERD_IT it = &words; // words of ROW | |
| 211 | |
| 212 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) { | |
| 213 word = it.data(); | |
| 214 word->plot(window); // in rainbow colours | |
| 215 } | |
| 216 } | |
| 217 #endif // !GRAPHICS_DISABLED | |
| 218 | |
| 219 /********************************************************************** | |
| 220 * ROW::operator= | |
| 221 * | |
| 222 * Assign rows by duplicating the row structure but NOT the WERDLIST | |
| 223 **********************************************************************/ | |
| 224 | |
| 225 ROW &ROW::operator=(const ROW &source) { | |
| 226 this->ELIST_LINK::operator=(source); | |
| 227 kerning = source.kerning; | |
| 228 spacing = source.spacing; | |
| 229 xheight = source.xheight; | |
| 230 bodysize = source.bodysize; | |
| 231 ascrise = source.ascrise; | |
| 232 descdrop = source.descdrop; | |
| 233 if (!words.empty()) { | |
| 234 words.clear(); | |
| 235 } | |
| 236 baseline = source.baseline; // QSPLINES must do = | |
| 237 bound_box = source.bound_box; | |
| 238 has_drop_cap_ = source.has_drop_cap_; | |
| 239 lmargin_ = source.lmargin_; | |
| 240 rmargin_ = source.rmargin_; | |
| 241 para_ = source.para_; | |
| 242 return *this; | |
| 243 } | |
| 244 | |
| 245 } // namespace tesseract |
