Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROW Class Reference

#include <ocrrow.h>

Inheritance diagram for ROW:
ELIST_LINK

Public Member Functions

 ROW ()
 
 ROW (inT32 spline_size, inT32 *xstarts, double *coeffs, float x_height, float ascenders, float descenders, inT16 kern, inT16 space)
 
 ROW (TO_ROW *row, inT16 kern, inT16 space)
 
WERD_LIST * word_list ()
 
float base_line (float xpos) const
 
float x_height () const
 
void set_x_height (float new_xheight)
 
inT32 kern () const
 
float body_size () const
 
void set_body_size (float new_size)
 
inT32 space () const
 
float ascenders () const
 
float descenders () const
 
TBOX bounding_box () const
 
void set_lmargin (inT16 lmargin)
 
void set_rmargin (inT16 rmargin)
 
inT16 lmargin () const
 
inT16 rmargin () const
 
void set_has_drop_cap (bool has)
 
bool has_drop_cap () const
 
void set_para (PARA *p)
 
PARApara () const
 
void recalc_bounding_box ()
 
void move (const ICOORD vec)
 
void print (FILE *fp)
 
void plot (ScrollView *window, ScrollView::Color colour)
 
void plot (ScrollView *window)
 
void plot_baseline (ScrollView *window, ScrollView::Color colour)
 
ROWoperator= (const ROW &source)
 
- Public Member Functions inherited from ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Friends

void tweak_row_baseline (ROW *, double, double)
 

Detailed Description

Definition at line 32 of file ocrrow.h.

Constructor & Destructor Documentation

ROW::ROW ( )
inline

Definition at line 36 of file ocrrow.h.

36  {
37  } //empty constructor
ROW::ROW ( inT32  spline_size,
inT32 xstarts,
double *  coeffs,
float  x_height,
float  ascenders,
float  descenders,
inT16  kern,
inT16  space 
)

Definition at line 36 of file ocrrow.cpp.

46  : baseline(spline_size, xstarts, coeffs),
47  para_(NULL) {
48  kerning = kern; //just store stuff
49  spacing = space;
50  xheight = x_height;
51  ascrise = ascenders;
52  bodysize = 0.0f;
53  descdrop = descenders;
54  has_drop_cap_ = false;
55  lmargin_ = 0;
56  rmargin_ = 0;
57 }
#define NULL
Definition: host.h:144
inT32 kern() const
Definition: ocrrow.h:67
inT32 space() const
Definition: ocrrow.h:76
float ascenders() const
Definition: ocrrow.h:79
float x_height() const
Definition: ocrrow.h:61
float descenders() const
Definition: ocrrow.h:82
ROW::ROW ( TO_ROW row,
inT16  kern,
inT16  space 
)

Definition at line 67 of file ocrrow.cpp.

71  : para_(NULL) {
72  kerning = kern; //just store stuff
73  spacing = space;
74  xheight = to_row->xheight;
75  bodysize = to_row->body_size;
76  ascrise = to_row->ascrise;
77  descdrop = to_row->descdrop;
78  baseline = to_row->baseline;
79  has_drop_cap_ = false;
80  lmargin_ = 0;
81  rmargin_ = 0;
82 }
#define NULL
Definition: host.h:144
inT32 kern() const
Definition: ocrrow.h:67
inT32 space() const
Definition: ocrrow.h:76

Member Function Documentation

float ROW::ascenders ( ) const
inline

Definition at line 79 of file ocrrow.h.

79  { //return size
80  return ascrise;
81  }
float ROW::base_line ( float  xpos) const
inline

Definition at line 56 of file ocrrow.h.

57  { //at the position
58  //get spline value
59  return (float) baseline.y (xpos);
60  }
float ROW::body_size ( ) const
inline

Definition at line 70 of file ocrrow.h.

70  { //return body size
71  return bodysize;
72  }
TBOX ROW::bounding_box ( ) const
inline

Definition at line 85 of file ocrrow.h.

85  { //return bounding box
86  return bound_box;
87  }
float ROW::descenders ( ) const
inline

Definition at line 82 of file ocrrow.h.

82  { //return size
83  return descdrop;
84  }
bool ROW::has_drop_cap ( ) const
inline

Definition at line 105 of file ocrrow.h.

105  {
106  return has_drop_cap_;
107  }
inT32 ROW::kern ( ) const
inline

Definition at line 67 of file ocrrow.h.

67  { //return kerning
68  return kerning;
69  }
inT16 ROW::lmargin ( ) const
inline

Definition at line 95 of file ocrrow.h.

95  {
96  return lmargin_;
97  }
void ROW::move ( const ICOORD  vec)

Definition at line 138 of file ocrrow.cpp.

140  {
141  WERD_IT it(&words); // word iterator
142 
143  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
144  it.data ()->move (vec);
145 
146  bound_box.move (vec);
147  baseline.move (vec);
148 }
void move(const ICOORD vec)
Definition: rect.h:146
ROW & ROW::operator= ( const ROW source)

Definition at line 216 of file ocrrow.cpp.

216  {
217  this->ELIST_LINK::operator= (source);
218  kerning = source.kerning;
219  spacing = source.spacing;
220  xheight = source.xheight;
221  bodysize = source.bodysize;
222  ascrise = source.ascrise;
223  descdrop = source.descdrop;
224  if (!words.empty ())
225  words.clear ();
226  baseline = source.baseline; //QSPLINES must do =
227  bound_box = source.bound_box;
228  has_drop_cap_ = source.has_drop_cap_;
229  lmargin_ = source.lmargin_;
230  rmargin_ = source.rmargin_;
231  para_ = source.para_;
232  return *this;
233 }
void operator=(const ELIST_LINK &)
Definition: elst.h:102
PARA* ROW::para ( ) const
inline

Definition at line 112 of file ocrrow.h.

112  {
113  return para_;
114  }
void ROW::plot ( ScrollView window,
ScrollView::Color  colour 
)

Definition at line 178 of file ocrrow.cpp.

181  {
182  WERD *word; //current word
183  WERD_IT it = &words; //words of ROW
184 
185  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
186  word = it.data ();
187  word->plot (window, colour); //all in one colour
188  }
189 }
Definition: werd.h:60
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:287
void ROW::plot ( ScrollView window)

Definition at line 197 of file ocrrow.cpp.

199  {
200  WERD *word; //current word
201  WERD_IT it = &words; //words of ROW
202 
203  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
204  word = it.data ();
205  word->plot (window); //in rainbow colours
206  }
207 }
Definition: werd.h:60
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:287
void ROW::plot_baseline ( ScrollView window,
ScrollView::Color  colour 
)
inline

Definition at line 131 of file ocrrow.h.

133  { //colour to draw
134  //draw it
135  baseline.plot (window, colour);
136  }
void ROW::print ( FILE *  fp)

Definition at line 157 of file ocrrow.cpp.

159  {
160  tprintf("Kerning= %d\n", kerning);
161  tprintf("Spacing= %d\n", spacing);
162  bound_box.print();
163  tprintf("Xheight= %f\n", xheight);
164  tprintf("Ascrise= %f\n", ascrise);
165  tprintf("Descdrop= %f\n", descdrop);
166  tprintf("has_drop_cap= %d\n", has_drop_cap_);
167  tprintf("lmargin= %d, rmargin= %d\n", lmargin_, rmargin_);
168 }
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void print() const
Definition: rect.h:263
void ROW::recalc_bounding_box ( )

Definition at line 91 of file ocrrow.cpp.

91  { //recalculate BB
92  WERD *word; //current word
93  WERD_IT it = &words; //words of ROW
94  inT16 left; //of word
95  inT16 prev_left; //old left
96 
97  if (!it.empty ()) {
98  word = it.data ();
99  prev_left = word->bounding_box ().left ();
100  it.forward ();
101  while (!it.at_first ()) {
102  word = it.data ();
103  left = word->bounding_box ().left ();
104  if (left < prev_left) {
105  it.move_to_first ();
106  //words in BB order
107  it.sort (word_comparator);
108  break;
109  }
110  prev_left = left;
111  it.forward ();
112  }
113  }
114  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
115  word = it.data ();
116  if (it.at_first ())
117  word->set_flag (W_BOL, TRUE);
118  else
119  //not start of line
120  word->set_flag (W_BOL, FALSE);
121  if (it.at_last ())
122  word->set_flag (W_EOL, TRUE);
123  else
124  //not end of line
125  word->set_flag (W_EOL, FALSE);
126  //extend BB as reqd
127  bound_box += word->bounding_box ();
128  }
129 }
TBOX bounding_box()
Definition: werd.cpp:164
inT16 left() const
Definition: rect.h:67
#define FALSE
Definition: capi.h:28
Definition: werd.h:35
void set_flag(WERD_FLAGS mask, BOOL8 value)
Definition: werd.h:123
int word_comparator(const void *word1p, const void *word2p)
Definition: werd.cpp:384
Definition: werd.h:60
short inT16
Definition: host.h:100
Definition: werd.h:36
#define TRUE
Definition: capi.h:27
inT16 ROW::rmargin ( ) const
inline

Definition at line 98 of file ocrrow.h.

98  {
99  return rmargin_;
100  }
void ROW::set_body_size ( float  new_size)
inline

Definition at line 73 of file ocrrow.h.

73  { // set body size
74  bodysize = new_size;
75  }
void ROW::set_has_drop_cap ( bool  has)
inline

Definition at line 102 of file ocrrow.h.

102  {
103  has_drop_cap_ = has;
104  }
void ROW::set_lmargin ( inT16  lmargin)
inline

Definition at line 89 of file ocrrow.h.

89  {
90  lmargin_ = lmargin;
91  }
inT16 lmargin() const
Definition: ocrrow.h:95
void ROW::set_para ( PARA p)
inline

Definition at line 109 of file ocrrow.h.

109  {
110  para_ = p;
111  }
void ROW::set_rmargin ( inT16  rmargin)
inline

Definition at line 92 of file ocrrow.h.

92  {
93  rmargin_ = rmargin;
94  }
inT16 rmargin() const
Definition: ocrrow.h:98
void ROW::set_x_height ( float  new_xheight)
inline

Definition at line 64 of file ocrrow.h.

64  { // set x height
65  xheight = new_xheight;
66  }
inT32 ROW::space ( ) const
inline

Definition at line 76 of file ocrrow.h.

76  { //return spacing
77  return spacing;
78  }
WERD_LIST* ROW::word_list ( )
inline

Definition at line 52 of file ocrrow.h.

52  { //get words
53  return &words;
54  }
float ROW::x_height ( ) const
inline

Definition at line 61 of file ocrrow.h.

61  { //return x height
62  return xheight;
63  }

Friends And Related Function Documentation

void tweak_row_baseline ( ROW ,
double  ,
double   
)
friend

Definition at line 680 of file tordmain.cpp.

682  {
683  TBOX blob_box; //bounding box
684  C_BLOB *blob; //current blob
685  WERD *word; //current word
686  inT32 blob_count; //no of blobs
687  inT32 src_index; //source segment
688  inT32 dest_index; //destination segment
689  inT32 *xstarts; //spline segments
690  double *coeffs; //spline coeffs
691  float ydiff; //baseline error
692  float x_centre; //centre of blob
693  //words of row
694  WERD_IT word_it = row->word_list ();
695  C_BLOB_IT blob_it; //blob iterator
696 
697  blob_count = 0;
698  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {
699  word = word_it.data (); //current word
700  //get total blobs
701  blob_count += word->cblob_list ()->length ();
702  }
703  if (blob_count == 0)
704  return;
705  xstarts =
706  (inT32 *) alloc_mem ((blob_count + row->baseline.segments + 1) *
707  sizeof (inT32));
708  coeffs =
709  (double *) alloc_mem ((blob_count + row->baseline.segments) * 3 *
710  sizeof (double));
711 
712  src_index = 0;
713  dest_index = 0;
714  xstarts[0] = row->baseline.xcoords[0];
715  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {
716  word = word_it.data (); //current word
717  //blobs in word
718  blob_it.set_to_list (word->cblob_list ());
719  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
720  blob_it.forward ()) {
721  blob = blob_it.data ();
722  blob_box = blob->bounding_box ();
723  x_centre = (blob_box.left () + blob_box.right ()) / 2.0;
724  ydiff = blob_box.bottom () - row->base_line (x_centre);
725  if (ydiff < 0)
726  ydiff = -ydiff / row->x_height ();
727  else
728  ydiff = ydiff / row->x_height ();
729  if (ydiff < blshift_maxshift
730  && blob_box.height () / row->x_height () > blshift_xfraction) {
731  if (xstarts[dest_index] >= x_centre)
732  xstarts[dest_index] = blob_box.left ();
733  coeffs[dest_index * 3] = 0;
734  coeffs[dest_index * 3 + 1] = 0;
735  coeffs[dest_index * 3 + 2] = blob_box.bottom ();
736  //shift it
737  dest_index++;
738  xstarts[dest_index] = blob_box.right () + 1;
739  }
740  else {
741  if (xstarts[dest_index] <= x_centre) {
742  while (row->baseline.xcoords[src_index + 1] <= x_centre
743  && src_index < row->baseline.segments - 1) {
744  if (row->baseline.xcoords[src_index + 1] >
745  xstarts[dest_index]) {
746  coeffs[dest_index * 3] =
747  row->baseline.quadratics[src_index].a;
748  coeffs[dest_index * 3 + 1] =
749  row->baseline.quadratics[src_index].b;
750  coeffs[dest_index * 3 + 2] =
751  row->baseline.quadratics[src_index].c;
752  dest_index++;
753  xstarts[dest_index] =
754  row->baseline.xcoords[src_index + 1];
755  }
756  src_index++;
757  }
758  coeffs[dest_index * 3] =
759  row->baseline.quadratics[src_index].a;
760  coeffs[dest_index * 3 + 1] =
761  row->baseline.quadratics[src_index].b;
762  coeffs[dest_index * 3 + 2] =
763  row->baseline.quadratics[src_index].c;
764  dest_index++;
765  xstarts[dest_index] = row->baseline.xcoords[src_index + 1];
766  }
767  }
768  }
769  }
770  while (src_index < row->baseline.segments
771  && row->baseline.xcoords[src_index + 1] <= xstarts[dest_index])
772  src_index++;
773  while (src_index < row->baseline.segments) {
774  coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
775  coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
776  coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
777  dest_index++;
778  src_index++;
779  xstarts[dest_index] = row->baseline.xcoords[src_index];
780  }
781  //turn to spline
782  row->baseline = QSPLINE (dest_index, xstarts, coeffs);
783  free_mem(xstarts);
784  free_mem(coeffs);
785 }
float b
Definition: quadratc.h:59
float c
Definition: quadratc.h:60
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
void free_mem(void *oldchunk)
Definition: memry.cpp:56
inT16 left() const
Definition: rect.h:67
int inT32
Definition: host.h:102
Definition: rect.h:29
inT16 right() const
Definition: rect.h:74
void * alloc_mem(inT32 count)
Definition: memry.cpp:48
double a
Definition: quadratc.h:58
float base_line(float xpos) const
Definition: ocrrow.h:56
float x_height() const
Definition: ocrrow.h:61
Definition: werd.h:60
WERD_LIST * word_list()
Definition: ocrrow.h:52
TBOX bounding_box()
Definition: stepblob.cpp:192
inT16 height() const
Definition: rect.h:97
inT16 bottom() const
Definition: rect.h:60

The documentation for this class was generated from the following files: