Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 * Created: Tue Oct 08 15:58:04 BST 1991
6 *
7 * (C) Copyright 1991, Hewlett-Packard Ltd.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 **********************************************************************/
19
20 #include "mfcpch.h"
21 #include "ocrrow.h"
22 #include "blobbox.h"
23
24 // Include automatically generated configuration file if running autoconf.
25 #ifdef HAVE_CONFIG_H
26 #include "config_auto.h"
27 #endif
28
29 ELISTIZE (ROW)
30 /**********************************************************************
31 * ROW::ROW
32 *
33 * Constructor to build a ROW. Only the stats stuff are given here.
34 * The words are added directly.
35 **********************************************************************/
36 ROW::ROW ( //constructor
37 inT32 spline_size, //no of segments
38 inT32 * xstarts, //segment boundaries
39 double *coeffs, //coefficients
40 float x_height, //line height
41 float ascenders, //ascender size
42 float descenders, //descender drop
43 inT16 kern, //char gap
44 inT16 space //word gap
45 )
46 : baseline(spline_size, xstarts, coeffs),
47 para_(NULL) {
48 kerning = kern; //just store stuff
49 spacing = space;
50 xheight = x_height;
51 ascrise = ascenders;
52 bodysize = 0.0f;
53 descdrop = descenders;
54 has_drop_cap_ = false;
55 lmargin_ = 0;
56 rmargin_ = 0;
57 }
58
59
60 /**********************************************************************
61 * ROW::ROW
62 *
63 * Constructor to build a ROW. Only the stats stuff are given here.
64 * The words are added directly.
65 **********************************************************************/
66
67 ROW::ROW( //constructor
68 TO_ROW *to_row, //source row
69 inT16 kern, //char gap
70 inT16 space //word gap
71 ) : para_(NULL) {
72 kerning = kern; //just store stuff
73 spacing = space;
74 xheight = to_row->xheight;
75 bodysize = to_row->body_size;
76 ascrise = to_row->ascrise;
77 descdrop = to_row->descdrop;
78 baseline = to_row->baseline;
79 has_drop_cap_ = false;
80 lmargin_ = 0;
81 rmargin_ = 0;
82 }
83
84
85 /**********************************************************************
86 * ROW::recalc_bounding_box
87 *
88 * Set the bounding box correctly
89 **********************************************************************/
90
91 void ROW::recalc_bounding_box() { //recalculate BB
92 WERD *word; //current word
93 WERD_IT it = &words; //words of ROW
94 inT16 left; //of word
95 inT16 prev_left; //old left
96
97 if (!it.empty ()) {
98 word = it.data ();
99 prev_left = word->bounding_box ().left ();
100 it.forward ();
101 while (!it.at_first ()) {
102 word = it.data ();
103 left = word->bounding_box ().left ();
104 if (left < prev_left) {
105 it.move_to_first ();
106 //words in BB order
107 it.sort (word_comparator);
108 break;
109 }
110 prev_left = left;
111 it.forward ();
112 }
113 }
114 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
115 word = it.data ();
116 if (it.at_first ())
117 word->set_flag (W_BOL, TRUE);
118 else
119 //not start of line
120 word->set_flag (W_BOL, FALSE);
121 if (it.at_last ())
122 word->set_flag (W_EOL, TRUE);
123 else
124 //not end of line
125 word->set_flag (W_EOL, FALSE);
126 //extend BB as reqd
127 bound_box += word->bounding_box ();
128 }
129 }
130
131
132 /**********************************************************************
133 * ROW::move
134 *
135 * Reposition row by vector
136 **********************************************************************/
137
138 void ROW::move( // reposition row
139 const ICOORD vec // by vector
140 ) {
141 WERD_IT it(&words); // word iterator
142
143 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
144 it.data ()->move (vec);
145
146 bound_box.move (vec);
147 baseline.move (vec);
148 }
149
150
151 /**********************************************************************
152 * ROW::print
153 *
154 * Display members
155 **********************************************************************/
156
157 void ROW::print( //print
158 FILE *fp //file to print on
159 ) {
160 tprintf("Kerning= %d\n", kerning);
161 tprintf("Spacing= %d\n", spacing);
162 bound_box.print();
163 tprintf("Xheight= %f\n", xheight);
164 tprintf("Ascrise= %f\n", ascrise);
165 tprintf("Descdrop= %f\n", descdrop);
166 tprintf("has_drop_cap= %d\n", has_drop_cap_);
167 tprintf("lmargin= %d, rmargin= %d\n", lmargin_, rmargin_);
168 }
169
170
171 /**********************************************************************
172 * ROW::plot
173 *
174 * Draw the ROW in the given colour.
175 **********************************************************************/
176
177 #ifndef GRAPHICS_DISABLED
178 void ROW::plot( //draw it
179 ScrollView* window, //window to draw in
180 ScrollView::Color colour //colour to draw in
181 ) {
182 WERD *word; //current word
183 WERD_IT it = &words; //words of ROW
184
185 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
186 word = it.data ();
187 word->plot (window, colour); //all in one colour
188 }
189 }
190
191 /**********************************************************************
192 * ROW::plot
193 *
194 * Draw the ROW in rainbow colours.
195 **********************************************************************/
196
197 void ROW::plot( //draw it
198 ScrollView* window //window to draw in
199 ) {
200 WERD *word; //current word
201 WERD_IT it = &words; //words of ROW
202
203 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
204 word = it.data ();
205 word->plot (window); //in rainbow colours
206 }
207 }
208 #endif // GRAPHICS_DISABLED
209
210 /**********************************************************************
211 * ROW::operator=
212 *
213 * Assign rows by duplicating the row structure but NOT the WERDLIST
214 **********************************************************************/
215
216 ROW & ROW::operator= (const ROW & source) {
217 this->ELIST_LINK::operator= (source);
218 kerning = source.kerning;
219 spacing = source.spacing;
220 xheight = source.xheight;
221 bodysize = source.bodysize;
222 ascrise = source.ascrise;
223 descdrop = source.descdrop;
224 if (!words.empty ())
225 words.clear ();
226 baseline = source.baseline; //QSPLINES must do =
227 bound_box = source.bound_box;
228 has_drop_cap_ = source.has_drop_cap_;
229 lmargin_ = source.lmargin_;
230 rmargin_ = source.rmargin_;
231 para_ = source.para_;
232 return *this;
233 }