tesseract 4.1.1
Loading...
Searching...
No Matches
ocrrow.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * File: ocrrow.cpp (Formerly row.c)
3 * Description: Code for the ROW class.
4 * Author: Ray Smith
5 *
6 * (C) Copyright 1991, Hewlett-Packard Ltd.
7 ** Licensed under the Apache License, Version 2.0 (the "License");
8 ** you may not use this file except in compliance with the License.
9 ** You may obtain a copy of the License at
10 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 *
17 **********************************************************************/
18
19#include "ocrrow.h"
20#include "blobbox.h"
21
22// Include automatically generated configuration file if running autoconf.
23#ifdef HAVE_CONFIG_H
24#include "config_auto.h"
25#endif
26
28/**********************************************************************
29 * ROW::ROW
30 *
31 * Constructor to build a ROW. Only the stats stuff are given here.
32 * The words are added directly.
33 **********************************************************************/
34ROW::ROW ( //constructor
35int32_t spline_size, //no of segments
36int32_t * xstarts, //segment boundaries
37double *coeffs, //coefficients
38float x_height, //line height
39float ascenders, //ascender size
40float descenders, //descender drop
41int16_t kern, //char gap
42int16_t space //word gap
43)
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}
56
57
58/**********************************************************************
59 * ROW::ROW
60 *
61 * Constructor to build a ROW. Only the stats stuff are given here.
62 * The words are added directly.
63 **********************************************************************/
64
65ROW::ROW( //constructor
66 TO_ROW *to_row, //source row
67 int16_t kern, //char gap
68 int16_t space //word gap
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}
81
82// Returns the bounding box including the desired combination of upper and
83// lower noise/diacritic elements.
84TBOX ROW::restricted_bounding_box(bool upper_dots, bool lower_dots) const {
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}
93
94/**********************************************************************
95 * ROW::recalc_bounding_box
96 *
97 * Set the bounding box correctly
98 **********************************************************************/
99
100void ROW::recalc_bounding_box() { //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}
139
140
141/**********************************************************************
142 * ROW::move
143 *
144 * Reposition row by vector
145 **********************************************************************/
146
147void ROW::move( // reposition row
148 const ICOORD vec // by vector
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}
158
159
160/**********************************************************************
161 * ROW::print
162 *
163 * Display members
164 **********************************************************************/
165
166void ROW::print( //print
167 FILE *fp //file to print on
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}
178
179
180/**********************************************************************
181 * ROW::plot
182 *
183 * Draw the ROW in the given colour.
184 **********************************************************************/
185
186#ifndef GRAPHICS_DISABLED
187void ROW::plot( //draw it
188 ScrollView* window, //window to draw in
189 ScrollView::Color colour //colour to draw in
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}
199
200/**********************************************************************
201 * ROW::plot
202 *
203 * Draw the ROW in rainbow colours.
204 **********************************************************************/
205
206void ROW::plot( //draw it
207 ScrollView* window //window to draw in
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}
217#endif // GRAPHICS_DISABLED
218
219/**********************************************************************
220 * ROW::operator=
221 *
222 * Assign rows by duplicating the row structure but NOT the WERDLIST
223 **********************************************************************/
224
225ROW & ROW::operator= (const ROW & source) {
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}
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
#define ELISTIZE(CLASSNAME)
Definition: elst.h:931
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
@ baseline
Definition: mfoutline.h:63
float body_size
Definition: blobbox.h:661
QSPLINE baseline
Definition: blobbox.h:670
float xheight
Definition: blobbox.h:657
float descdrop
Definition: blobbox.h:660
float ascrise
Definition: blobbox.h:659
Definition: ocrrow.h:37
void plot(ScrollView *window, ScrollView::Color colour)
Definition: ocrrow.cpp:187
int32_t space() const
Definition: ocrrow.h:79
ROW & operator=(const ROW &source)
Definition: ocrrow.cpp:225
void move(const ICOORD vec)
Definition: ocrrow.cpp:147
TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const
Definition: ocrrow.cpp:84
void recalc_bounding_box()
Definition: ocrrow.cpp:100
void print(FILE *fp)
Definition: ocrrow.cpp:166
ROW()=default
int32_t kern() const
Definition: ocrrow.h:70
integer coordinate
Definition: points.h:32
void move(ICOORD vec)
Definition: quspline.cpp:251
Definition: rect.h:34
void move(const ICOORD vec)
Definition: rect.h:157
void print() const
Definition: rect.h:278
int16_t left() const
Definition: rect.h:72
Definition: werd.h:56
void set_flag(WERD_FLAGS mask, bool value)
Definition: werd.h:118
TBOX bounding_box() const
Definition: werd.cpp:148
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:283
void operator=(const ELIST_LINK &)
Definition: elst.h:94