tesseract 4.1.1
Loading...
Searching...
No Matches
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 34 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;
54 rmargin_ = 0;
55}
int32_t space() const
Definition: ocrrow.h:79
float descenders() const
Definition: ocrrow.h:85
float ascenders() const
Definition: ocrrow.h:82
float x_height() const
Definition: ocrrow.h:64
int32_t kern() const
Definition: ocrrow.h:70

◆ ROW() [3/3]

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

Definition at line 65 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 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 static_cast<float>(baseline.y (xpos));
63 }
double y(double x) const
Definition: quspline.cpp:209

◆ 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 147 of file ocrrow.cpp.

149 {
150 WERD_IT it(&words); // word iterator
151
152 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
153 it.data ()->move (vec);
154
155 bound_box.move (vec);
156 baseline.move (vec);
157}
void move(ICOORD vec)
Definition: quspline.cpp:251
void move(const ICOORD vec)
Definition: rect.h:157

◆ operator=()

ROW & 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 baseline = source.baseline; //QSPLINES must do =
236 bound_box = source.bound_box;
237 has_drop_cap_ = source.has_drop_cap_;
238 lmargin_ = source.lmargin_;
239 rmargin_ = source.rmargin_;
240 para_ = source.para_;
241 return *this;
242}
void operator=(const ELIST_LINK &)
Definition: elst.h:94

◆ 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)

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

◆ plot() [2/2]

void 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 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 }
void plot(ScrollView *window, ScrollView::Color colour) const
Definition: quspline.cpp:347

◆ print()

void ROW::print ( FILE *  fp)

Definition at line 166 of file ocrrow.cpp.

168 {
169 tprintf("Kerning= %d\n", kerning);
170 tprintf("Spacing= %d\n", spacing);
171 bound_box.print();
172 tprintf("Xheight= %f\n", xheight);
173 tprintf("Ascrise= %f\n", ascrise);
174 tprintf("Descdrop= %f\n", descdrop);
175 tprintf("has_drop_cap= %d\n", has_drop_cap_);
176 tprintf("lmargin= %d, rmargin= %d\n", lmargin_, rmargin_);
177}
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
void print() const
Definition: rect.h:278

◆ recalc_bounding_box()

void 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 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);
135 //extend BB as reqd
136 bound_box += word->bounding_box ();
137 }
138}
int word_comparator(const void *word1p, const void *word2p)
Definition: werd.cpp:370
@ W_EOL
end of line
Definition: werd.h:33
@ W_BOL
start of line
Definition: werd.h:32
int16_t left() const
Definition: rect.h:72
void set_flag(WERD_FLAGS mask, bool value)
Definition: werd.h:118
TBOX bounding_box() const
Definition: werd.cpp:148

◆ restricted_bounding_box()

TBOX 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}
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}
WERD_LIST * word_list()
Definition: ocrrow.h:55
float base_line(float xpos) const
Definition: ocrrow.h:59
float b
Definition: quadratc.h:58
float c
Definition: quadratc.h:59
double a
Definition: quadratc.h:57
int16_t height() const
Definition: rect.h:108
int16_t bottom() const
Definition: rect.h:65
int16_t right() const
Definition: rect.h:79
TBOX bounding_box() const
Definition: stepblob.cpp:253
C_BLOB_LIST * cblob_list()
Definition: werd.h:95

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