tesseract  5.0.0-alpha-619-ge9db
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 35 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 32 of file ocrrow.cpp.

44  : baseline(spline_size, xstarts, coeffs),
45  para_(nullptr) {
46  kerning = kern; //just store stuff
47  spacing = space;
48  xheight = x_height;
49  ascrise = ascenders;
50  bodysize = 0.0f;
51  descdrop = descenders;
52  has_drop_cap_ = false;
53  lmargin_ = 0;

◆ ROW() [3/3]

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

Definition at line 62 of file ocrrow.cpp.

69  : para_(nullptr) {
70  kerning = kern; //just store stuff
71  spacing = space;
72  xheight = to_row->xheight;
73  bodysize = to_row->body_size;
74  ascrise = to_row->ascrise;
75  descdrop = to_row->descdrop;
76  baseline = to_row->baseline;
77  has_drop_cap_ = false;

Member Function Documentation

◆ ascenders()

float ROW::ascenders ( ) const
inline

Definition at line 81 of file ocrrow.h.

82  { //return size
83  return ascrise;

◆ base_line()

float ROW::base_line ( float  xpos) const
inline

Definition at line 58 of file ocrrow.h.

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

◆ body_size()

float ROW::body_size ( ) const
inline

Definition at line 72 of file ocrrow.h.

73  { //return body size
74  return bodysize;

◆ bounding_box()

TBOX ROW::bounding_box ( ) const
inline

Definition at line 87 of file ocrrow.h.

88  { //return bounding box
89  return bound_box;

◆ descenders()

float ROW::descenders ( ) const
inline

Definition at line 84 of file ocrrow.h.

85  { //return size
86  return descdrop;

◆ has_drop_cap()

bool ROW::has_drop_cap ( ) const
inline

Definition at line 110 of file ocrrow.h.

111  {
112  return has_drop_cap_;

◆ kern()

int32_t ROW::kern ( ) const
inline

Definition at line 69 of file ocrrow.h.

70  { //return kerning
71  return kerning;

◆ lmargin()

int16_t ROW::lmargin ( ) const
inline

Definition at line 100 of file ocrrow.h.

101  {
102  return lmargin_;

◆ move()

void ROW::move ( const ICOORD  vec)

Definition at line 142 of file ocrrow.cpp.

149  {
150  WERD_IT it(&words); // word iterator
151 
152  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())

◆ operator=()

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

Definition at line 216 of file ocrrow.cpp.

225  {
226  this->ELIST_LINK::operator= (source);
227  kerning = source.kerning;
228  spacing = source.spacing;
229  xheight = source.xheight;
230  bodysize = source.bodysize;
231  ascrise = source.ascrise;
232  descdrop = source.descdrop;
233  if (!words.empty ())

◆ para()

PARA* ROW::para ( ) const
inline

Definition at line 117 of file ocrrow.h.

118  {
119  return para_;

◆ plot() [1/2]

void ROW::plot ( ScrollView window)

Definition at line 198 of file ocrrow.cpp.

208  {

◆ plot() [2/2]

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

Definition at line 180 of file ocrrow.cpp.

190  {
191  WERD *word; //current word

◆ plot_baseline()

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

Definition at line 136 of file ocrrow.h.

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

◆ print()

void ROW::print ( FILE *  fp)

Definition at line 160 of file ocrrow.cpp.

168  {
169  tprintf("Kerning= %d\n", kerning);
170  tprintf("Spacing= %d\n", spacing);
171  bound_box.print();

◆ recalc_bounding_box()

void ROW::recalc_bounding_box ( )

Definition at line 96 of file ocrrow.cpp.

100  { //recalculate BB
101  WERD *word; //current word
102  WERD_IT it = &words; //words of ROW
103  int16_t left; //of word
104  int16_t prev_left; //old left
105 
106  if (!it.empty ()) {
107  word = it.data ();
108  prev_left = word->bounding_box ().left ();
109  it.forward ();
110  while (!it.at_first ()) {
111  word = it.data ();
112  left = word->bounding_box ().left ();
113  if (left < prev_left) {
114  it.move_to_first ();
115  //words in BB order
116  it.sort (word_comparator);
117  break;
118  }
119  prev_left = left;
120  it.forward ();
121  }
122  }
123  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
124  word = it.data ();
125  if (it.at_first ())
126  word->set_flag (W_BOL, true);
127  else
128  //not start of line
129  word->set_flag (W_BOL, false);
130  if (it.at_last ())
131  word->set_flag(W_EOL, true);
132  else
133  //not end of line
134  word->set_flag(W_EOL, false);

◆ restricted_bounding_box()

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

Definition at line 81 of file ocrrow.cpp.

84  {
85  TBOX box;
86  // This is a read-only iteration of the words in the row.
87  WERD_IT it(const_cast<WERD_LIST *>(&words));
88  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
89  box += it.data()->restricted_bounding_box(upper_dots, lower_dots);

◆ rmargin()

int16_t ROW::rmargin ( ) const
inline

Definition at line 103 of file ocrrow.h.

104  {
105  return rmargin_;

◆ set_body_size()

void ROW::set_body_size ( float  new_size)
inline

Definition at line 75 of file ocrrow.h.

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

◆ set_has_drop_cap()

void ROW::set_has_drop_cap ( bool  has)
inline

Definition at line 107 of file ocrrow.h.

108  {
109  has_drop_cap_ = has;

◆ set_lmargin()

void ROW::set_lmargin ( int16_t  lmargin)
inline

Definition at line 94 of file ocrrow.h.

95  {
96  lmargin_ = lmargin;

◆ set_para()

void ROW::set_para ( PARA p)
inline

Definition at line 114 of file ocrrow.h.

115  {
116  para_ = p;

◆ set_rmargin()

void ROW::set_rmargin ( int16_t  rmargin)
inline

Definition at line 97 of file ocrrow.h.

98  {
99  rmargin_ = rmargin;

◆ set_x_height()

void ROW::set_x_height ( float  new_xheight)
inline

Definition at line 66 of file ocrrow.h.

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

◆ space()

int32_t ROW::space ( ) const
inline

Definition at line 78 of file ocrrow.h.

79  { //return spacing
80  return spacing;

◆ word_list()

WERD_LIST* ROW::word_list ( )
inline

Definition at line 54 of file ocrrow.h.

55  { //get words
56  return &words;

◆ x_height()

float ROW::x_height ( ) const
inline

Definition at line 63 of file ocrrow.h.

64  { //return x height
65  return xheight;

Friends And Related Function Documentation

◆ tweak_row_baseline

void tweak_row_baseline ( ROW ,
double  ,
double   
)
friend

Definition at line 893 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

The documentation for this class was generated from the following files:
C_BLOB::bounding_box
TBOX bounding_box() const
Definition: stepblob.cpp:247
ROW::base_line
float base_line(float xpos) const
Definition: ocrrow.h:58
ROW::descenders
float descenders() const
Definition: ocrrow.h:84
QUAD_COEFFS::a
double a
Definition: quadratc.h:71
ROW::rmargin
int16_t rmargin() const
Definition: ocrrow.h:103
WERD::bounding_box
TBOX bounding_box() const
Definition: werd.cpp:147
TBOX::print
void print() const
Definition: rect.h:277
word_comparator
int word_comparator(const void *word1p, const void *word2p)
Definition: werd.cpp:369
C_BLOB
Definition: stepblob.h:36
ROW::lmargin
int16_t lmargin() const
Definition: ocrrow.h:100
TBOX::height
int16_t height() const
Definition: rect.h:107
WERD::cblob_list
C_BLOB_LIST * cblob_list()
Definition: werd.h:94
ROW::x_height
float x_height() const
Definition: ocrrow.h:63
QSPLINE::plot
void plot(ScrollView *window, ScrollView::Color colour) const
Definition: quspline.cpp:335
ROW::space
int32_t space() const
Definition: ocrrow.h:78
WERD::set_flag
void set_flag(WERD_FLAGS mask, bool value)
Definition: werd.h:117
ROW::ascenders
float ascenders() const
Definition: ocrrow.h:81
W_EOL
end of line
Definition: werd.h:47
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
ELIST_LINK::operator=
void operator=(const ELIST_LINK &)
Definition: elst.h:134
ROW::kern
int32_t kern() const
Definition: ocrrow.h:69
QSPLINE::y
double y(double x) const
Definition: quspline.cpp:202
WERD
Definition: werd.h:55
TBOX::left
int16_t left() const
Definition: rect.h:71
TBOX::right
int16_t right() const
Definition: rect.h:78
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
QUAD_COEFFS::c
float c
Definition: quadratc.h:73
QUAD_COEFFS::b
float b
Definition: quadratc.h:72
ROW::word_list
WERD_LIST * word_list()
Definition: ocrrow.h:54
W_BOL
start of line
Definition: werd.h:46
TBOX
Definition: rect.h:33