ccstruct/ocrrow.cpp

Go to the documentation of this file.
00001 
00020 #include "mfcpch.h"
00021 #include          "ocrrow.h"
00022 #include          "blobbox.h"
00023 
00024 ELISTIZE_S (ROW)
00031 ROW::ROW (                       //constructor
00032 INT32 spline_size,               //no of segments
00033 INT32 * xstarts,                 //segment boundaries
00034 double *coeffs,                  //coefficients
00035 float x_height,                  //line height
00036 float ascenders,                 //ascender size
00037 float descenders,                //descender drop
00038 INT16 kern,                      //char gap
00039 INT16 space                      //word gap
00040 ):
00041 baseline(spline_size, xstarts, coeffs) { 
00042   kerning = kern;                //just store stuff
00043   spacing = space;
00044   xheight = x_height;
00045   ascrise = ascenders;
00046   descdrop = descenders;
00047 }
00048 
00049 
00056 ROW::ROW(                 //constructor
00057          TO_ROW *to_row,  //source row
00058          INT16 kern,      //char gap
00059          INT16 space      //word gap
00060         ) {
00061   kerning = kern;                //just store stuff
00062   spacing = space;
00063   xheight = to_row->xheight;
00064   ascrise = to_row->ascrise;
00065   descdrop = to_row->descdrop;
00066   baseline = to_row->baseline;
00067 }
00068 
00069 
00073 void ROW::recalc_bounding_box() {  //recalculate BB
00074   WERD *word;                    //current word
00075   WERD_IT it = &words;           //words of ROW
00076   INT16 left;                    //of word
00077   INT16 prev_left;               //old left
00078 
00079   if (!it.empty ()) {
00080     word = it.data ();
00081     prev_left = word->bounding_box ().left ();
00082     it.forward ();
00083     while (!it.at_first ()) {
00084       word = it.data ();
00085       left = word->bounding_box ().left ();
00086       if (left < prev_left) {
00087         it.move_to_first ();
00088                                  //words in BB order
00089         it.sort (word_comparator);
00090         break;
00091       }
00092       prev_left = left;
00093       it.forward ();
00094     }
00095   }
00096   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00097     word = it.data ();
00098     if (it.at_first ())
00099       word->set_flag (W_BOL, TRUE);
00100     else
00101                                  //not start of line
00102       word->set_flag (W_BOL, FALSE);
00103     if (it.at_last ())
00104       word->set_flag (W_EOL, TRUE);
00105     else
00106                                  //not end of line
00107       word->set_flag (W_EOL, FALSE);
00108                                  //extend BB as reqd
00109     bound_box += word->bounding_box ();
00110   }
00111 }
00112 
00113 
00117 void ROW::move(                  // reposition row
00118                const ICOORD vec  // by vector ROW::move()
00119               ) {
00120   WERD_IT it(&words);  // word iterator
00121 
00122   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
00123     it.data ()->move (vec);
00124 
00125   bound_box.move (vec);
00126   baseline.move (vec);
00127 }
00128 
00129 
00133 void ROW::print(          //print
00134                 FILE *fp  //file to print on
00135                ) {
00136   tprintf ("Kerning= %d\n", kerning);
00137   tprintf ("Spacing= %d\n", spacing);
00138   bound_box.print ();
00139   tprintf ("Xheight= %f\n", xheight);
00140   tprintf ("Ascrise= %f\n", ascrise);
00141   tprintf ("Descdrop= %f\n", descdrop);
00142 }
00143 
00144 
00148 #ifndef GRAPHICS_DISABLED
00149 void ROW::plot(                //draw it
00150                WINDOW window,  //window to draw in
00151                COLOUR colour   //colour to draw in
00152               ) {
00153   WERD *word;                    //current word
00154   WERD_IT it = &words;           //words of ROW
00155 
00156   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00157     word = it.data ();
00158     word->plot (window, colour); //all in one colour
00159   }
00160 }
00161 #endif
00162 
00166 #ifndef GRAPHICS_DISABLED
00167 void ROW::plot(               //draw it
00168                WINDOW window  //window to draw in
00169               ) {
00170   WERD *word;                    //current word
00171   WERD_IT it = &words;           //words of ROW
00172 
00173   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00174     word = it.data ();
00175     word->plot (window);         //in rainbow colours
00176   }
00177 }
00178 #endif
00179 
00183 ROW & ROW::operator= (           //assignment
00184 const ROW & source               //from this
00185 ) {
00186   this->ELIST_LINK::operator= (source);
00187   kerning = source.kerning;
00188   spacing = source.spacing;
00189   xheight = source.xheight;
00190   ascrise = source.ascrise;
00191   descdrop = source.descdrop;
00192   if (!words.empty ())
00193     words.clear ();
00194   baseline = source.baseline;    //QSPLINES must do =
00195   bound_box = source.bound_box;
00196   return *this;
00197 }

Generated on Wed Feb 28 19:49:08 2007 for Tesseract by  doxygen 1.5.1