tesseract  4.00.00dev
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
 
TBOX restricted_bounding_box (bool upper_dots, bool lower_dots) 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() [1/3]

ROW::ROW ( )
inline

Definition at line 36 of file ocrrow.h.

36  {
37  } //empty constructor

◆ ROW() [2/3]

ROW::ROW ( inT32  spline_size,
inT32 xstarts,
double *  coeffs,
float  x_height,
float  ascenders,
float  descenders,
inT16  kern,
inT16  space 
)

Definition at line 35 of file ocrrow.cpp.

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

◆ ROW() [3/3]

ROW::ROW ( TO_ROW row,
inT16  kern,
inT16  space 
)

Definition at line 66 of file ocrrow.cpp.

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

Member Function Documentation

◆ ascenders()

float ROW::ascenders ( ) const
inline

Definition at line 79 of file ocrrow.h.

79  { //return size
80  return ascrise;
81  }

◆ base_line()

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  }

◆ body_size()

float ROW::body_size ( ) const
inline

Definition at line 70 of file ocrrow.h.

70  { //return body size
71  return bodysize;
72  }

◆ bounding_box()

TBOX ROW::bounding_box ( ) const
inline

Definition at line 85 of file ocrrow.h.

85  { //return bounding box
86  return bound_box;
87  }

◆ descenders()

float ROW::descenders ( ) const
inline

Definition at line 82 of file ocrrow.h.

82  { //return size
83  return descdrop;
84  }

◆ has_drop_cap()

bool ROW::has_drop_cap ( ) const
inline

Definition at line 108 of file ocrrow.h.

108  {
109  return has_drop_cap_;
110  }

◆ kern()

inT32 ROW::kern ( ) const
inline

Definition at line 67 of file ocrrow.h.

67  { //return kerning
68  return kerning;
69  }

◆ lmargin()

inT16 ROW::lmargin ( ) const
inline

Definition at line 98 of file ocrrow.h.

98  {
99  return lmargin_;
100  }

◆ move()

void ROW::move ( const ICOORD  vec)

Definition at line 148 of file ocrrow.cpp.

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  bound_box.move (vec);
157  baseline.move (vec);
158 }
void move(const ICOORD vec)
Definition: rect.h:153

◆ operator=()

ROW & ROW::operator= ( const ROW source)

Definition at line 226 of file ocrrow.cpp.

226  {
227  this->ELIST_LINK::operator= (source);
228  kerning = source.kerning;
229  spacing = source.spacing;
230  xheight = source.xheight;
231  bodysize = source.bodysize;
232  ascrise = source.ascrise;
233  descdrop = source.descdrop;
234  if (!words.empty ())
235  words.clear ();
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 }
void operator=(const ELIST_LINK &)
Definition: elst.h:101

◆ para()

PARA* ROW::para ( ) const
inline

Definition at line 115 of file ocrrow.h.

115  {
116  return para_;
117  }

◆ plot() [1/2]

void ROW::plot ( ScrollView window,
ScrollView::Color  colour 
)

Definition at line 188 of file ocrrow.cpp.

191  {
192  WERD *word; //current word
193  WERD_IT it = &words; //words of ROW
194 
195  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
196  word = it.data ();
197  word->plot (window, colour); //all in one colour
198  }
199 }
Definition: werd.h:60
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:297

◆ plot() [2/2]

void ROW::plot ( ScrollView window)

Definition at line 207 of file ocrrow.cpp.

209  {
210  WERD *word; //current word
211  WERD_IT it = &words; //words of ROW
212 
213  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
214  word = it.data ();
215  word->plot (window); //in rainbow colours
216  }
217 }
Definition: werd.h:60
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:297

◆ plot_baseline()

void ROW::plot_baseline ( ScrollView window,
ScrollView::Color  colour 
)
inline

Definition at line 134 of file ocrrow.h.

136  { //colour to draw
137  //draw it
138  baseline.plot (window, colour);
139  }

◆ print()

void ROW::print ( FILE *  fp)

Definition at line 167 of file ocrrow.cpp.

169  {
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 }
#define tprintf(...)
Definition: tprintf.h:31
void print() const
Definition: rect.h:270

◆ recalc_bounding_box()

void ROW::recalc_bounding_box ( )

Definition at line 101 of file ocrrow.cpp.

101  { //recalculate BB
102  WERD *word; //current word
103  WERD_IT it = &words; //words of ROW
104  inT16 left; //of word
105  inT16 prev_left; //old left
106 
107  if (!it.empty ()) {
108  word = it.data ();
109  prev_left = word->bounding_box ().left ();
110  it.forward ();
111  while (!it.at_first ()) {
112  word = it.data ();
113  left = word->bounding_box ().left ();
114  if (left < prev_left) {
115  it.move_to_first ();
116  //words in BB order
117  it.sort (word_comparator);
118  break;
119  }
120  prev_left = left;
121  it.forward ();
122  }
123  }
124  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
125  word = it.data ();
126  if (it.at_first ())
127  word->set_flag (W_BOL, TRUE);
128  else
129  //not start of line
130  word->set_flag (W_BOL, FALSE);
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  //extend BB as reqd
137  bound_box += word->bounding_box ();
138  }
139 }
#define TRUE
Definition: capi.h:45
int word_comparator(const void *word1p, const void *word2p)
Definition: werd.cpp:394
Definition: werd.h:36
void set_flag(WERD_FLAGS mask, BOOL8 value)
Definition: werd.h:129
TBOX bounding_box() const
Definition: werd.cpp:160
int16_t inT16
Definition: host.h:36
inT16 left() const
Definition: rect.h:68
#define FALSE
Definition: capi.h:46
Definition: werd.h:35
Definition: werd.h:60

◆ restricted_bounding_box()

TBOX ROW::restricted_bounding_box ( bool  upper_dots,
bool  lower_dots 
) const

Definition at line 85 of file ocrrow.cpp.

85  {
86  TBOX box;
87  // This is a read-only iteration of the words in the row.
88  WERD_IT it(const_cast<WERD_LIST *>(&words));
89  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
90  box += it.data()->restricted_bounding_box(upper_dots, lower_dots);
91  }
92  return box;
93 }
Definition: rect.h:30

◆ rmargin()

inT16 ROW::rmargin ( ) const
inline

Definition at line 101 of file ocrrow.h.

101  {
102  return rmargin_;
103  }

◆ set_body_size()

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  }

◆ set_has_drop_cap()

void ROW::set_has_drop_cap ( bool  has)
inline

Definition at line 105 of file ocrrow.h.

105  {
106  has_drop_cap_ = has;
107  }

◆ set_lmargin()

void ROW::set_lmargin ( inT16  lmargin)
inline

Definition at line 92 of file ocrrow.h.

92  {
93  lmargin_ = lmargin;
94  }
inT16 lmargin() const
Definition: ocrrow.h:98

◆ set_para()

void ROW::set_para ( PARA p)
inline

Definition at line 112 of file ocrrow.h.

112  {
113  para_ = p;
114  }

◆ set_rmargin()

void ROW::set_rmargin ( inT16  rmargin)
inline

Definition at line 95 of file ocrrow.h.

95  {
96  rmargin_ = rmargin;
97  }
inT16 rmargin() const
Definition: ocrrow.h:101

◆ set_x_height()

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  }

◆ space()

inT32 ROW::space ( ) const
inline

Definition at line 76 of file ocrrow.h.

76  { //return spacing
77  return spacing;
78  }

◆ word_list()

WERD_LIST* ROW::word_list ( )
inline

Definition at line 52 of file ocrrow.h.

52  { //get words
53  return &words;
54  }

◆ x_height()

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

◆ tweak_row_baseline

void tweak_row_baseline ( ROW ,
double  ,
double   
)
friend

Definition at line 885 of file tordmain.cpp.

887  {
888  TBOX blob_box; //bounding box
889  C_BLOB *blob; //current blob
890  WERD *word; //current word
891  inT32 blob_count; //no of blobs
892  inT32 src_index; //source segment
893  inT32 dest_index; //destination segment
894  inT32 *xstarts; //spline segments
895  double *coeffs; //spline coeffs
896  float ydiff; //baseline error
897  float x_centre; //centre of blob
898  //words of row
899  WERD_IT word_it = row->word_list ();
900  C_BLOB_IT blob_it; //blob iterator
901 
902  blob_count = 0;
903  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {
904  word = word_it.data (); //current word
905  //get total blobs
906  blob_count += word->cblob_list ()->length ();
907  }
908  if (blob_count == 0)
909  return;
910  xstarts =
911  (inT32 *) alloc_mem ((blob_count + row->baseline.segments + 1) *
912  sizeof (inT32));
913  coeffs =
914  (double *) alloc_mem ((blob_count + row->baseline.segments) * 3 *
915  sizeof (double));
916 
917  src_index = 0;
918  dest_index = 0;
919  xstarts[0] = row->baseline.xcoords[0];
920  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {
921  word = word_it.data (); //current word
922  //blobs in word
923  blob_it.set_to_list (word->cblob_list ());
924  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
925  blob_it.forward ()) {
926  blob = blob_it.data ();
927  blob_box = blob->bounding_box ();
928  x_centre = (blob_box.left () + blob_box.right ()) / 2.0;
929  ydiff = blob_box.bottom () - row->base_line (x_centre);
930  if (ydiff < 0)
931  ydiff = -ydiff / row->x_height ();
932  else
933  ydiff = ydiff / row->x_height ();
934  if (ydiff < blshift_maxshift
935  && blob_box.height () / row->x_height () > blshift_xfraction) {
936  if (xstarts[dest_index] >= x_centre)
937  xstarts[dest_index] = blob_box.left ();
938  coeffs[dest_index * 3] = 0;
939  coeffs[dest_index * 3 + 1] = 0;
940  coeffs[dest_index * 3 + 2] = blob_box.bottom ();
941  //shift it
942  dest_index++;
943  xstarts[dest_index] = blob_box.right () + 1;
944  }
945  else {
946  if (xstarts[dest_index] <= x_centre) {
947  while (row->baseline.xcoords[src_index + 1] <= x_centre
948  && src_index < row->baseline.segments - 1) {
949  if (row->baseline.xcoords[src_index + 1] >
950  xstarts[dest_index]) {
951  coeffs[dest_index * 3] =
952  row->baseline.quadratics[src_index].a;
953  coeffs[dest_index * 3 + 1] =
954  row->baseline.quadratics[src_index].b;
955  coeffs[dest_index * 3 + 2] =
956  row->baseline.quadratics[src_index].c;
957  dest_index++;
958  xstarts[dest_index] =
959  row->baseline.xcoords[src_index + 1];
960  }
961  src_index++;
962  }
963  coeffs[dest_index * 3] =
964  row->baseline.quadratics[src_index].a;
965  coeffs[dest_index * 3 + 1] =
966  row->baseline.quadratics[src_index].b;
967  coeffs[dest_index * 3 + 2] =
968  row->baseline.quadratics[src_index].c;
969  dest_index++;
970  xstarts[dest_index] = row->baseline.xcoords[src_index + 1];
971  }
972  }
973  }
974  }
975  while (src_index < row->baseline.segments
976  && row->baseline.xcoords[src_index + 1] <= xstarts[dest_index])
977  src_index++;
978  while (src_index < row->baseline.segments) {
979  coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
980  coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
981  coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
982  dest_index++;
983  src_index++;
984  xstarts[dest_index] = row->baseline.xcoords[src_index];
985  }
986  //turn to spline
987  row->baseline = QSPLINE (dest_index, xstarts, coeffs);
988  free_mem(xstarts);
989  free_mem(coeffs);
990 }
void free_mem(void *oldchunk)
Definition: memry.cpp:47
int32_t inT32
Definition: host.h:38
WERD_LIST * word_list()
Definition: ocrrow.h:52
float x_height() const
Definition: ocrrow.h:61
inT16 left() const
Definition: rect.h:68
void * alloc_mem(inT32 count)
Definition: memry.cpp:39
double a
Definition: quadratc.h:58
Definition: rect.h:30
TBOX bounding_box() const
Definition: stepblob.cpp:250
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
inT16 height() const
Definition: rect.h:104
float c
Definition: quadratc.h:60
inT16 right() const
Definition: rect.h:75
inT16 bottom() const
Definition: rect.h:61
float base_line(float xpos) const
Definition: ocrrow.h:56
Definition: werd.h:60
float b
Definition: quadratc.h:59

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