tesseract  4.0.0-1-g2a2b
ROW Class Reference

#include <ocrrow.h>

Inheritance diagram for ROW:
ELIST_LINK

Public Member Functions

 ROW ()=default
 
 ROW (int32_t spline_size, int32_t *xstarts, double *coeffs, float x_height, float ascenders, float descenders, int16_t kern, int16_t space)
 
 ROW (TO_ROW *row, int16_t kern, int16_t space)
 
WERD_LIST * word_list ()
 
float base_line (float xpos) const
 
float x_height () const
 
void set_x_height (float new_xheight)
 
int32_t kern () const
 
float body_size () const
 
void set_body_size (float new_size)
 
int32_t 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_t lmargin)
 
void set_rmargin (int16_t rmargin)
 
int16_t lmargin () const
 
int16_t 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 36 of file ocrrow.h.

Constructor & Destructor Documentation

◆ ROW() [1/3]

ROW::ROW ( )
default

◆ ROW() [2/3]

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

Definition at line 35 of file ocrrow.cpp.

45  : baseline(spline_size, xstarts, coeffs),
46  para_(nullptr) {
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 }
int32_t space() const
Definition: ocrrow.h:79
float ascenders() const
Definition: ocrrow.h:82
float x_height() const
Definition: ocrrow.h:64
int32_t kern() const
Definition: ocrrow.h:70
float descenders() const
Definition: ocrrow.h:85

◆ ROW() [3/3]

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

Definition at line 66 of file ocrrow.cpp.

70  : para_(nullptr) {
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_t space() const
Definition: ocrrow.h:79
int32_t kern() const
Definition: ocrrow.h:70

Member Function Documentation

◆ ascenders()

float ROW::ascenders ( ) const
inline

Definition at line 82 of file ocrrow.h.

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

◆ base_line()

float ROW::base_line ( float  xpos) const
inline

Definition at line 59 of file ocrrow.h.

60  { //at the position
61  //get spline value
62  return (float) baseline.y (xpos);
63  }

◆ body_size()

float ROW::body_size ( ) const
inline

Definition at line 73 of file ocrrow.h.

73  { //return body size
74  return bodysize;
75  }

◆ bounding_box()

TBOX ROW::bounding_box ( ) const
inline

Definition at line 88 of file ocrrow.h.

88  { //return bounding box
89  return bound_box;
90  }

◆ descenders()

float ROW::descenders ( ) const
inline

Definition at line 85 of file ocrrow.h.

85  { //return size
86  return descdrop;
87  }

◆ has_drop_cap()

bool ROW::has_drop_cap ( ) const
inline

Definition at line 111 of file ocrrow.h.

111  {
112  return has_drop_cap_;
113  }

◆ kern()

int32_t ROW::kern ( ) const
inline

Definition at line 70 of file ocrrow.h.

70  { //return kerning
71  return kerning;
72  }

◆ lmargin()

int16_t ROW::lmargin ( ) const
inline

Definition at line 101 of file ocrrow.h.

101  {
102  return lmargin_;
103  }

◆ 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:157

◆ 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 118 of file ocrrow.h.

118  {
119  return para_;
120  }

◆ 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 }
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:296
Definition: werd.h:59

◆ 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 }
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:296
Definition: werd.h:59

◆ plot_baseline()

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

Definition at line 137 of file ocrrow.h.

139  { //colour to draw
140  //draw it
141  baseline.plot (window, colour);
142  }

◆ 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 }
void print() const
Definition: rect.h:278
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

◆ 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_t left; //of word
105  int16_t 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:51
int word_comparator(const void *word1p, const void *word2p)
Definition: werd.cpp:393
TBOX bounding_box() const
Definition: werd.cpp:159
Definition: werd.h:35
void set_flag(WERD_FLAGS mask, bool value)
Definition: werd.h:127
int16_t left() const
Definition: rect.h:72
#define FALSE
Definition: capi.h:52
Definition: werd.h:59
Definition: werd.h:34

◆ 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:34

◆ rmargin()

int16_t ROW::rmargin ( ) const
inline

Definition at line 104 of file ocrrow.h.

104  {
105  return rmargin_;
106  }

◆ set_body_size()

void ROW::set_body_size ( float  new_size)
inline

Definition at line 76 of file ocrrow.h.

76  { // set body size
77  bodysize = new_size;
78  }

◆ set_has_drop_cap()

void ROW::set_has_drop_cap ( bool  has)
inline

Definition at line 108 of file ocrrow.h.

108  {
109  has_drop_cap_ = has;
110  }

◆ set_lmargin()

void ROW::set_lmargin ( int16_t  lmargin)
inline

Definition at line 95 of file ocrrow.h.

95  {
96  lmargin_ = lmargin;
97  }
int16_t lmargin() const
Definition: ocrrow.h:101

◆ set_para()

void ROW::set_para ( PARA p)
inline

Definition at line 115 of file ocrrow.h.

115  {
116  para_ = p;
117  }

◆ set_rmargin()

void ROW::set_rmargin ( int16_t  rmargin)
inline

Definition at line 98 of file ocrrow.h.

98  {
99  rmargin_ = rmargin;
100  }
int16_t rmargin() const
Definition: ocrrow.h:104

◆ set_x_height()

void ROW::set_x_height ( float  new_xheight)
inline

Definition at line 67 of file ocrrow.h.

67  { // set x height
68  xheight = new_xheight;
69  }

◆ space()

int32_t ROW::space ( ) const
inline

Definition at line 79 of file ocrrow.h.

79  { //return spacing
80  return spacing;
81  }

◆ word_list()

WERD_LIST* ROW::word_list ( )
inline

Definition at line 55 of file ocrrow.h.

55  { //get words
56  return &words;
57  }

◆ x_height()

float ROW::x_height ( ) const
inline

Definition at line 64 of file ocrrow.h.

64  { //return x height
65  return xheight;
66  }

Friends And Related Function Documentation

◆ tweak_row_baseline

void tweak_row_baseline ( ROW ,
double  ,
double   
)
friend

Definition at line 895 of file tordmain.cpp.

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

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