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
ELISTIZE_S(ROW)24 ELISTIZE_S (ROW)
25 /**********************************************************************
26 * ROW::ROW
27 *
28 * Constructor to build a ROW. Only the stats stuff are given here.
29 * The words are added directly.
30 **********************************************************************/
31 ROW::ROW ( //constructor
32 inT32 spline_size, //no of segments
33 inT32 * xstarts, //segment boundaries
34 double *coeffs, //coefficients
35 float x_height, //line height
36 float ascenders, //ascender size
37 float descenders, //descender drop
38 inT16 kern, //char gap
39 inT16 space //word gap
40 ):
41 baseline(spline_size, xstarts, coeffs) {
42 kerning = kern; //just store stuff
43 spacing = space;
44 xheight = x_height;
45 ascrise = ascenders;
46 descdrop = descenders;
47 }
48
49
50 /**********************************************************************
51 * ROW::ROW
52 *
53 * Constructor to build a ROW. Only the stats stuff are given here.
54 * The words are added directly.
55 **********************************************************************/
56
ROW(TO_ROW * to_row,inT16 kern,inT16 space)57 ROW::ROW( //constructor
58 TO_ROW *to_row, //source row
59 inT16 kern, //char gap
60 inT16 space //word gap
61 ) {
62 kerning = kern; //just store stuff
63 spacing = space;
64 xheight = to_row->xheight;
65 ascrise = to_row->ascrise;
66 descdrop = to_row->descdrop;
67 baseline = to_row->baseline;
68 }
69
70
71 /**********************************************************************
72 * ROW::recalc_bounding_box
73 *
74 * Set the bounding box correctly
75 **********************************************************************/
76
recalc_bounding_box()77 void ROW::recalc_bounding_box() { //recalculate BB
78 WERD *word; //current word
79 WERD_IT it = &words; //words of ROW
80 inT16 left; //of word
81 inT16 prev_left; //old left
82
83 if (!it.empty ()) {
84 word = it.data ();
85 prev_left = word->bounding_box ().left ();
86 it.forward ();
87 while (!it.at_first ()) {
88 word = it.data ();
89 left = word->bounding_box ().left ();
90 if (left < prev_left) {
91 it.move_to_first ();
92 //words in BB order
93 it.sort (word_comparator);
94 break;
95 }
96 prev_left = left;
97 it.forward ();
98 }
99 }
100 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
101 word = it.data ();
102 if (it.at_first ())
103 word->set_flag (W_BOL, TRUE);
104 else
105 //not start of line
106 word->set_flag (W_BOL, FALSE);
107 if (it.at_last ())
108 word->set_flag (W_EOL, TRUE);
109 else
110 //not end of line
111 word->set_flag (W_EOL, FALSE);
112 //extend BB as reqd
113 bound_box += word->bounding_box ();
114 }
115 }
116
117
118 /**********************************************************************
119 * ROW::move
120 *
121 * Reposition row by vector
122 **********************************************************************/
123
move(const ICOORD vec)124 void ROW::move( // reposition row
125 const ICOORD vec // by vector
126 ) {
127 WERD_IT it(&words); // word iterator
128
129 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
130 it.data ()->move (vec);
131
132 bound_box.move (vec);
133 baseline.move (vec);
134 }
135
136
137 /**********************************************************************
138 * ROW::print
139 *
140 * Display members
141 **********************************************************************/
142
print(FILE * fp)143 void ROW::print( //print
144 FILE *fp //file to print on
145 ) {
146 tprintf ("Kerning= %d\n", kerning);
147 tprintf ("Spacing= %d\n", spacing);
148 bound_box.print ();
149 tprintf ("Xheight= %f\n", xheight);
150 tprintf ("Ascrise= %f\n", ascrise);
151 tprintf ("Descdrop= %f\n", descdrop);
152 }
153
154
155 /**********************************************************************
156 * ROW::plot
157 *
158 * Draw the ROW in the given colour.
159 **********************************************************************/
160
161 #ifndef GRAPHICS_DISABLED
plot(ScrollView * window,ScrollView::Color colour)162 void ROW::plot( //draw it
163 ScrollView* window, //window to draw in
164 ScrollView::Color colour //colour to draw in
165 ) {
166 WERD *word; //current word
167 WERD_IT it = &words; //words of ROW
168
169 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
170 word = it.data ();
171 word->plot (window, colour); //all in one colour
172 }
173 }
174 #endif
175
176 /**********************************************************************
177 * ROW::plot
178 *
179 * Draw the ROW in rainbow colours.
180 **********************************************************************/
181
182 #ifndef GRAPHICS_DISABLED
plot(ScrollView * window)183 void ROW::plot( //draw it
184 ScrollView* window //window to draw in
185 ) {
186 WERD *word; //current word
187 WERD_IT it = &words; //words of ROW
188
189 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
190 word = it.data ();
191 word->plot (window); //in rainbow colours
192 }
193 }
194 #endif
195
196 /**********************************************************************
197 * ROW::operator=
198 *
199 * Assign rows by duplicating the row structure but NOT the WERDLIST
200 **********************************************************************/
201
operator =(const ROW & source)202 ROW & ROW::operator= ( //assignment
203 const ROW & source //from this
204 ) {
205 this->ELIST_LINK::operator= (source);
206 kerning = source.kerning;
207 spacing = source.spacing;
208 xheight = source.xheight;
209 ascrise = source.ascrise;
210 descdrop = source.descdrop;
211 if (!words.empty ())
212 words.clear ();
213 baseline = source.baseline; //QSPLINES must do =
214 bound_box = source.bound_box;
215 return *this;
216 }
217