tesseract v5.3.3.20231005
tesseract::ROW Class Reference

#include <ocrrow.h>

Inheritance diagram for tesseract::ROW:
tesseract::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) const
 
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 tesseract::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 39 of file ocrrow.h.

Constructor & Destructor Documentation

◆ ROW() [1/3]

tesseract::ROW::ROW ( )
default

◆ ROW() [2/3]

tesseract::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), 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;
54 rmargin_ = 0;
55}
int32_t kern() const
Definition: ocrrow.h:72
float x_height() const
Definition: ocrrow.h:66
int32_t space() const
Definition: ocrrow.h:81
float ascenders() const
Definition: ocrrow.h:84
float descenders() const
Definition: ocrrow.h:87

◆ ROW() [3/3]

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

Definition at line 64 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;
78 lmargin_ = 0;
79 rmargin_ = 0;
80}

Member Function Documentation

◆ ascenders()

float tesseract::ROW::ascenders ( ) const
inline

Definition at line 84 of file ocrrow.h.

84 { // return size
85 return ascrise;
86 }

◆ base_line()

float tesseract::ROW::base_line ( float  xpos) const
inline

Definition at line 61 of file ocrrow.h.

62 { // at the position
63 // get spline value
64 return static_cast<float>(baseline.y(xpos));
65 }
double y(double x) const
Definition: quspline.cpp:203

◆ body_size()

float tesseract::ROW::body_size ( ) const
inline

Definition at line 75 of file ocrrow.h.

75 { // return body size
76 return bodysize;
77 }

◆ bounding_box()

TBOX tesseract::ROW::bounding_box ( ) const
inline

Definition at line 90 of file ocrrow.h.

90 { // return bounding box
91 return bound_box;
92 }

◆ descenders()

float tesseract::ROW::descenders ( ) const
inline

Definition at line 87 of file ocrrow.h.

87 { // return size
88 return descdrop;
89 }

◆ has_drop_cap()

bool tesseract::ROW::has_drop_cap ( ) const
inline

Definition at line 113 of file ocrrow.h.

113 {
114 return has_drop_cap_;
115 }

◆ kern()

int32_t tesseract::ROW::kern ( ) const
inline

Definition at line 72 of file ocrrow.h.

72 { // return kerning
73 return kerning;
74 }

◆ lmargin()

int16_t tesseract::ROW::lmargin ( ) const
inline

Definition at line 103 of file ocrrow.h.

103 {
104 return lmargin_;
105 }

◆ move()

void tesseract::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
157 bound_box.move(vec);
158 baseline.move(vec);
159}
void move(ICOORD vec)
Definition: quspline.cpp:244
void move(const ICOORD vec)
Definition: rect.h:170

◆ operator=()

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

Definition at line 225 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()) {
234 words.clear();
235 }
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:100

◆ para()

PARA * tesseract::ROW::para ( ) const
inline

Definition at line 120 of file ocrrow.h.

120 {
121 return para_;
122 }

◆ plot() [1/2]

void tesseract::ROW::plot ( ScrollView window)

Definition at line 206 of file ocrrow.cpp.

208 {
209 WERD *word; // current word
210 WERD_IT it = &words; // words of ROW
211
212 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
213 word = it.data();
214 word->plot(window); // in rainbow colours
215 }
216}

◆ plot() [2/2]

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

Definition at line 187 of file ocrrow.cpp.

190 {
191 WERD *word; // current word
192 WERD_IT it = &words; // words of ROW
193
194 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
195 word = it.data();
196 word->plot(window, colour); // all in one colour
197 }
198}

◆ plot_baseline()

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

Definition at line 139 of file ocrrow.h.

141 { // colour to draw
142 // draw it
143 baseline.plot(window, colour);
144 }
void plot(ScrollView *window, ScrollView::Color colour) const
Definition: quspline.cpp:340

◆ print()

void tesseract::ROW::print ( FILE *  fp) const

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 tprintf(const char *format,...)
Definition: tprintf.cpp:41
void print() const
Definition: rect.h:289

◆ recalc_bounding_box()

void tesseract::ROW::recalc_bounding_box ( )

Definition at line 100 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 }
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 }
137 // extend BB as reqd
138 bound_box += word->bounding_box();
139 }
140}
@ W_BOL
start of line
Definition: werd.h:34
@ W_EOL
end of line
Definition: werd.h:35
int word_comparator(const void *word1p, const void *word2p)
Definition: werd.cpp:377

◆ restricted_bounding_box()

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

Definition at line 84 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);
90 }
91 return box;
92}
@ TBOX

◆ rmargin()

int16_t tesseract::ROW::rmargin ( ) const
inline

Definition at line 106 of file ocrrow.h.

106 {
107 return rmargin_;
108 }

◆ set_body_size()

void tesseract::ROW::set_body_size ( float  new_size)
inline

Definition at line 78 of file ocrrow.h.

78 { // set body size
79 bodysize = new_size;
80 }

◆ set_has_drop_cap()

void tesseract::ROW::set_has_drop_cap ( bool  has)
inline

Definition at line 110 of file ocrrow.h.

110 {
111 has_drop_cap_ = has;
112 }

◆ set_lmargin()

void tesseract::ROW::set_lmargin ( int16_t  lmargin)
inline

Definition at line 97 of file ocrrow.h.

97 {
98 lmargin_ = lmargin;
99 }
int16_t lmargin() const
Definition: ocrrow.h:103

◆ set_para()

void tesseract::ROW::set_para ( PARA p)
inline

Definition at line 117 of file ocrrow.h.

117 {
118 para_ = p;
119 }
const char * p

◆ set_rmargin()

void tesseract::ROW::set_rmargin ( int16_t  rmargin)
inline

Definition at line 100 of file ocrrow.h.

100 {
101 rmargin_ = rmargin;
102 }
int16_t rmargin() const
Definition: ocrrow.h:106

◆ set_x_height()

void tesseract::ROW::set_x_height ( float  new_xheight)
inline

Definition at line 69 of file ocrrow.h.

69 { // set x height
70 xheight = new_xheight;
71 }

◆ space()

int32_t tesseract::ROW::space ( ) const
inline

Definition at line 81 of file ocrrow.h.

81 { // return spacing
82 return spacing;
83 }

◆ word_list()

WERD_LIST * tesseract::ROW::word_list ( )
inline

Definition at line 57 of file ocrrow.h.

57 { // get words
58 return &words;
59 }

◆ x_height()

float tesseract::ROW::x_height ( ) const
inline

Definition at line 66 of file ocrrow.h.

66 { // return x height
67 return xheight;
68 }

Friends And Related Function Documentation

◆ tweak_row_baseline

void tweak_row_baseline ( ROW ,
double  ,
double   
)
friend

Definition at line 864 of file tordmain.cpp.

864 {
865 TBOX blob_box; // bounding box
866 C_BLOB *blob; // current blob
867 WERD *word; // current word
868 int32_t blob_count; // no of blobs
869 int32_t src_index; // source segment
870 int32_t dest_index; // destination segment
871 float ydiff; // baseline error
872 float x_centre; // centre of blob
873 // words of row
874 WERD_IT word_it = row->word_list();
875 C_BLOB_IT blob_it; // blob iterator
876
877 blob_count = 0;
878 for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) {
879 word = word_it.data(); // current word
880 // get total blobs
881 blob_count += word->cblob_list()->length();
882 }
883 if (blob_count == 0) {
884 return;
885 }
886 // spline segments
887 std::vector<int32_t> xstarts(blob_count + row->baseline.segments + 1);
888 // spline coeffs
889 std::vector<double> coeffs((blob_count + row->baseline.segments) * 3);
890
891 src_index = 0;
892 dest_index = 0;
893 xstarts[0] = row->baseline.xcoords[0];
894 for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) {
895 word = word_it.data(); // current word
896 // blobs in word
897 blob_it.set_to_list(word->cblob_list());
898 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
899 blob = blob_it.data();
900 blob_box = blob->bounding_box();
901 x_centre = (blob_box.left() + blob_box.right()) / 2.0;
902 ydiff = blob_box.bottom() - row->base_line(x_centre);
903 if (ydiff < 0) {
904 ydiff = -ydiff / row->x_height();
905 } else {
906 ydiff = ydiff / row->x_height();
907 }
908 if (ydiff < blshift_maxshift && blob_box.height() / row->x_height() > blshift_xfraction) {
909 if (xstarts[dest_index] >= x_centre) {
910 xstarts[dest_index] = blob_box.left();
911 }
912 coeffs[dest_index * 3] = 0;
913 coeffs[dest_index * 3 + 1] = 0;
914 coeffs[dest_index * 3 + 2] = blob_box.bottom();
915 // shift it
916 dest_index++;
917 xstarts[dest_index] = blob_box.right() + 1;
918 } else {
919 if (xstarts[dest_index] <= x_centre) {
920 while (row->baseline.xcoords[src_index + 1] <= x_centre &&
921 src_index < row->baseline.segments - 1) {
922 if (row->baseline.xcoords[src_index + 1] > xstarts[dest_index]) {
923 coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
924 coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
925 coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
926 dest_index++;
927 xstarts[dest_index] = row->baseline.xcoords[src_index + 1];
928 }
929 src_index++;
930 }
931 coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
932 coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
933 coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
934 dest_index++;
935 xstarts[dest_index] = row->baseline.xcoords[src_index + 1];
936 }
937 }
938 }
939 }
940 while (src_index < row->baseline.segments &&
941 row->baseline.xcoords[src_index + 1] <= xstarts[dest_index]) {
942 src_index++;
943 }
944 while (src_index < row->baseline.segments) {
945 coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
946 coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
947 coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
948 dest_index++;
949 src_index++;
950 xstarts[dest_index] = row->baseline.xcoords[src_index];
951 }
952 // turn to spline
953 row->baseline = QSPLINE(dest_index, &xstarts[0], &coeffs[0]);
954}

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