tesseract
3.03
|
00001 /********************************************************************** 00002 * File: ocrrow.cpp (Formerly row.c) 00003 * Description: Code for the ROW class. 00004 * Author: Ray Smith 00005 * Created: Tue Oct 08 15:58:04 BST 1991 00006 * 00007 * (C) Copyright 1991, Hewlett-Packard Ltd. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #include "ocrrow.h" 00021 #include "blobbox.h" 00022 00023 // Include automatically generated configuration file if running autoconf. 00024 #ifdef HAVE_CONFIG_H 00025 #include "config_auto.h" 00026 #endif 00027 00028 ELISTIZE (ROW) 00029 /********************************************************************** 00030 * ROW::ROW 00031 * 00032 * Constructor to build a ROW. Only the stats stuff are given here. 00033 * The words are added directly. 00034 **********************************************************************/ 00035 ROW::ROW ( //constructor 00036 inT32 spline_size, //no of segments 00037 inT32 * xstarts, //segment boundaries 00038 double *coeffs, //coefficients 00039 float x_height, //line height 00040 float ascenders, //ascender size 00041 float descenders, //descender drop 00042 inT16 kern, //char gap 00043 inT16 space //word gap 00044 ) 00045 : baseline(spline_size, xstarts, coeffs), 00046 para_(NULL) { 00047 kerning = kern; //just store stuff 00048 spacing = space; 00049 xheight = x_height; 00050 ascrise = ascenders; 00051 bodysize = 0.0f; 00052 descdrop = descenders; 00053 has_drop_cap_ = false; 00054 lmargin_ = 0; 00055 rmargin_ = 0; 00056 } 00057 00058 00059 /********************************************************************** 00060 * ROW::ROW 00061 * 00062 * Constructor to build a ROW. Only the stats stuff are given here. 00063 * The words are added directly. 00064 **********************************************************************/ 00065 00066 ROW::ROW( //constructor 00067 TO_ROW *to_row, //source row 00068 inT16 kern, //char gap 00069 inT16 space //word gap 00070 ) : para_(NULL) { 00071 kerning = kern; //just store stuff 00072 spacing = space; 00073 xheight = to_row->xheight; 00074 bodysize = to_row->body_size; 00075 ascrise = to_row->ascrise; 00076 descdrop = to_row->descdrop; 00077 baseline = to_row->baseline; 00078 has_drop_cap_ = false; 00079 lmargin_ = 0; 00080 rmargin_ = 0; 00081 } 00082 00083 00084 /********************************************************************** 00085 * ROW::recalc_bounding_box 00086 * 00087 * Set the bounding box correctly 00088 **********************************************************************/ 00089 00090 void ROW::recalc_bounding_box() { //recalculate BB 00091 WERD *word; //current word 00092 WERD_IT it = &words; //words of ROW 00093 inT16 left; //of word 00094 inT16 prev_left; //old left 00095 00096 if (!it.empty ()) { 00097 word = it.data (); 00098 prev_left = word->bounding_box ().left (); 00099 it.forward (); 00100 while (!it.at_first ()) { 00101 word = it.data (); 00102 left = word->bounding_box ().left (); 00103 if (left < prev_left) { 00104 it.move_to_first (); 00105 //words in BB order 00106 it.sort (word_comparator); 00107 break; 00108 } 00109 prev_left = left; 00110 it.forward (); 00111 } 00112 } 00113 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) { 00114 word = it.data (); 00115 if (it.at_first ()) 00116 word->set_flag (W_BOL, TRUE); 00117 else 00118 //not start of line 00119 word->set_flag (W_BOL, FALSE); 00120 if (it.at_last ()) 00121 word->set_flag (W_EOL, TRUE); 00122 else 00123 //not end of line 00124 word->set_flag (W_EOL, FALSE); 00125 //extend BB as reqd 00126 bound_box += word->bounding_box (); 00127 } 00128 } 00129 00130 00131 /********************************************************************** 00132 * ROW::move 00133 * 00134 * Reposition row by vector 00135 **********************************************************************/ 00136 00137 void ROW::move( // reposition row 00138 const ICOORD vec // by vector 00139 ) { 00140 WERD_IT it(&words); // word iterator 00141 00142 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) 00143 it.data ()->move (vec); 00144 00145 bound_box.move (vec); 00146 baseline.move (vec); 00147 } 00148 00149 00150 /********************************************************************** 00151 * ROW::print 00152 * 00153 * Display members 00154 **********************************************************************/ 00155 00156 void ROW::print( //print 00157 FILE *fp //file to print on 00158 ) { 00159 tprintf("Kerning= %d\n", kerning); 00160 tprintf("Spacing= %d\n", spacing); 00161 bound_box.print(); 00162 tprintf("Xheight= %f\n", xheight); 00163 tprintf("Ascrise= %f\n", ascrise); 00164 tprintf("Descdrop= %f\n", descdrop); 00165 tprintf("has_drop_cap= %d\n", has_drop_cap_); 00166 tprintf("lmargin= %d, rmargin= %d\n", lmargin_, rmargin_); 00167 } 00168 00169 00170 /********************************************************************** 00171 * ROW::plot 00172 * 00173 * Draw the ROW in the given colour. 00174 **********************************************************************/ 00175 00176 #ifndef GRAPHICS_DISABLED 00177 void ROW::plot( //draw it 00178 ScrollView* window, //window to draw in 00179 ScrollView::Color colour //colour to draw in 00180 ) { 00181 WERD *word; //current word 00182 WERD_IT it = &words; //words of ROW 00183 00184 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) { 00185 word = it.data (); 00186 word->plot (window, colour); //all in one colour 00187 } 00188 } 00189 00190 /********************************************************************** 00191 * ROW::plot 00192 * 00193 * Draw the ROW in rainbow colours. 00194 **********************************************************************/ 00195 00196 void ROW::plot( //draw it 00197 ScrollView* window //window to draw in 00198 ) { 00199 WERD *word; //current word 00200 WERD_IT it = &words; //words of ROW 00201 00202 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) { 00203 word = it.data (); 00204 word->plot (window); //in rainbow colours 00205 } 00206 } 00207 #endif // GRAPHICS_DISABLED 00208 00209 /********************************************************************** 00210 * ROW::operator= 00211 * 00212 * Assign rows by duplicating the row structure but NOT the WERDLIST 00213 **********************************************************************/ 00214 00215 ROW & ROW::operator= (const ROW & source) { 00216 this->ELIST_LINK::operator= (source); 00217 kerning = source.kerning; 00218 spacing = source.spacing; 00219 xheight = source.xheight; 00220 bodysize = source.bodysize; 00221 ascrise = source.ascrise; 00222 descdrop = source.descdrop; 00223 if (!words.empty ()) 00224 words.clear (); 00225 baseline = source.baseline; //QSPLINES must do = 00226 bound_box = source.bound_box; 00227 has_drop_cap_ = source.has_drop_cap_; 00228 lmargin_ = source.lmargin_; 00229 rmargin_ = source.rmargin_; 00230 para_ = source.para_; 00231 return *this; 00232 }