tesseract  4.00.00dev
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 "ocrrow.h"
21 #include "blobbox.h"
22 
23 // Include automatically generated configuration file if running autoconf.
24 #ifdef HAVE_CONFIG_H
25 #include "config_auto.h"
26 #endif
27 
28 ELISTIZE (ROW)
29 /**********************************************************************
30  * ROW::ROW
31  *
32  * Constructor to build a ROW. Only the stats stuff are given here.
33  * The words are added directly.
34  **********************************************************************/
35 ROW::ROW ( //constructor
36 inT32 spline_size, //no of segments
37 inT32 * xstarts, //segment boundaries
38 double *coeffs, //coefficients
39 float x_height, //line height
40 float ascenders, //ascender size
41 float descenders, //descender drop
42 inT16 kern, //char gap
43 inT16 space //word gap
44 )
45  : baseline(spline_size, xstarts, coeffs),
46  para_(NULL) {
47  kerning = kern; //just store stuff
48  spacing = space;
49  xheight = x_height;
50  ascrise = ascenders;
51  bodysize = 0.0f;
52  descdrop = descenders;
53  has_drop_cap_ = false;
54  lmargin_ = 0;
55  rmargin_ = 0;
56 }
57 
58 
59 /**********************************************************************
60  * ROW::ROW
61  *
62  * Constructor to build a ROW. Only the stats stuff are given here.
63  * The words are added directly.
64  **********************************************************************/
65 
66 ROW::ROW( //constructor
67  TO_ROW *to_row, //source row
68  inT16 kern, //char gap
69  inT16 space //word gap
70  ) : para_(NULL) {
71  kerning = kern; //just store stuff
72  spacing = space;
73  xheight = to_row->xheight;
74  bodysize = to_row->body_size;
75  ascrise = to_row->ascrise;
76  descdrop = to_row->descdrop;
77  baseline = to_row->baseline;
78  has_drop_cap_ = false;
79  lmargin_ = 0;
80  rmargin_ = 0;
81 }
82 
83 // Returns the bounding box including the desired combination of upper and
84 // lower noise/diacritic elements.
85 TBOX ROW::restricted_bounding_box(bool upper_dots, bool lower_dots) const {
86  TBOX box;
87  // This is a read-only iteration of the words in the row.
88  WERD_IT it(const_cast<WERD_LIST *>(&words));
89  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
90  box += it.data()->restricted_bounding_box(upper_dots, lower_dots);
91  }
92  return box;
93 }
94 
95 /**********************************************************************
96  * ROW::recalc_bounding_box
97  *
98  * Set the bounding box correctly
99  **********************************************************************/
100 
101 void ROW::recalc_bounding_box() { //recalculate BB
102  WERD *word; //current word
103  WERD_IT it = &words; //words of ROW
104  inT16 left; //of word
105  inT16 prev_left; //old left
106 
107  if (!it.empty ()) {
108  word = it.data ();
109  prev_left = word->bounding_box ().left ();
110  it.forward ();
111  while (!it.at_first ()) {
112  word = it.data ();
113  left = word->bounding_box ().left ();
114  if (left < prev_left) {
115  it.move_to_first ();
116  //words in BB order
117  it.sort (word_comparator);
118  break;
119  }
120  prev_left = left;
121  it.forward ();
122  }
123  }
124  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
125  word = it.data ();
126  if (it.at_first ())
127  word->set_flag (W_BOL, TRUE);
128  else
129  //not start of line
130  word->set_flag (W_BOL, FALSE);
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  //extend BB as reqd
137  bound_box += word->bounding_box ();
138  }
139 }
140 
141 
142 /**********************************************************************
143  * ROW::move
144  *
145  * Reposition row by vector
146  **********************************************************************/
147 
148 void ROW::move( // reposition row
149  const ICOORD vec // by vector
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  bound_box.move (vec);
157  baseline.move (vec);
158 }
159 
160 
161 /**********************************************************************
162  * ROW::print
163  *
164  * Display members
165  **********************************************************************/
166 
167 void ROW::print( //print
168  FILE *fp //file to print on
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 }
179 
180 
181 /**********************************************************************
182  * ROW::plot
183  *
184  * Draw the ROW in the given colour.
185  **********************************************************************/
186 
187 #ifndef GRAPHICS_DISABLED
188 void ROW::plot( //draw it
189  ScrollView* window, //window to draw in
190  ScrollView::Color colour //colour to draw in
191  ) {
192  WERD *word; //current word
193  WERD_IT it = &words; //words of ROW
194 
195  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
196  word = it.data ();
197  word->plot (window, colour); //all in one colour
198  }
199 }
200 
201 /**********************************************************************
202  * ROW::plot
203  *
204  * Draw the ROW in rainbow colours.
205  **********************************************************************/
206 
207 void ROW::plot( //draw it
208  ScrollView* window //window to draw in
209  ) {
210  WERD *word; //current word
211  WERD_IT it = &words; //words of ROW
212 
213  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
214  word = it.data ();
215  word->plot (window); //in rainbow colours
216  }
217 }
218 #endif // GRAPHICS_DISABLED
219 
220 /**********************************************************************
221  * ROW::operator=
222  *
223  * Assign rows by duplicating the row structure but NOT the WERDLIST
224  **********************************************************************/
225 
226 ROW & ROW::operator= (const ROW & source) {
227  this->ELIST_LINK::operator= (source);
228  kerning = source.kerning;
229  spacing = source.spacing;
230  xheight = source.xheight;
231  bodysize = source.bodysize;
232  ascrise = source.ascrise;
233  descdrop = source.descdrop;
234  if (!words.empty ())
235  words.clear ();
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 move(ICOORD vec)
Definition: quspline.cpp:259
#define TRUE
Definition: capi.h:45
int32_t inT32
Definition: host.h:38
float xheight
Definition: blobbox.h:653
ROW()
Definition: ocrrow.h:36
int word_comparator(const void *word1p, const void *word2p)
Definition: werd.cpp:394
float descdrop
Definition: blobbox.h:656
Definition: werd.h:36
void move(const ICOORD vec)
Definition: ocrrow.cpp:148
void set_flag(WERD_FLAGS mask, BOOL8 value)
Definition: werd.h:129
#define tprintf(...)
Definition: tprintf.h:31
ROW & operator=(const ROW &source)
Definition: ocrrow.cpp:226
float body_size
Definition: blobbox.h:657
void print(FILE *fp)
Definition: ocrrow.cpp:167
TBOX bounding_box() const
Definition: werd.cpp:160
int16_t inT16
Definition: host.h:36
TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const
Definition: ocrrow.cpp:85
inT16 left() const
Definition: rect.h:68
QSPLINE baseline
Definition: blobbox.h:666
#define FALSE
Definition: capi.h:46
inT32 kern() const
Definition: ocrrow.h:67
Definition: werd.h:35
Definition: rect.h:30
void print() const
Definition: rect.h:270
void operator=(const ELIST_LINK &)
Definition: elst.h:101
#define ELISTIZE(CLASSNAME)
Definition: elst.h:961
void plot(ScrollView *window, ScrollView::Color colour)
Definition: ocrrow.cpp:188
void move(const ICOORD vec)
Definition: rect.h:153
Definition: werd.h:60
void recalc_bounding_box()
Definition: ocrrow.cpp:101
Definition: ocrrow.h:32
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:297
float ascrise
Definition: blobbox.h:655
integer coordinate
Definition: points.h:30
inT32 space() const
Definition: ocrrow.h:76