tesseract  5.0.0
ocrrow.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: ocrrow.h (Formerly row.h)
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 #ifndef OCRROW_H
21 #define OCRROW_H
22 
23 #include "elst.h" // for ELIST_ITERATOR, ELISTIZEH, ELIST_LINK
24 #include "quspline.h" // for QSPLINE
25 #include "rect.h" // for TBOX
26 #include "scrollview.h" // for ScrollView, ScrollView::Color
27 #include "werd.h" // for WERD_LIST
28 
29 #include <cstdint> // for int16_t, int32_t
30 #include <cstdio> // for FILE
31 
32 namespace tesseract {
33 
34 class ICOORD;
35 class TO_ROW;
36 
37 struct PARA;
38 
39 class ROW : public ELIST_LINK {
40  friend void tweak_row_baseline(ROW *, double, double);
41 
42 public:
43  ROW() = default;
44  ROW( // constructor
45  int32_t spline_size, // no of segments
46  int32_t *xstarts, // segment boundaries
47  double *coeffs, // coefficients //ascender size
48  float x_height, float ascenders,
49  float descenders, // descender size
50  int16_t kern, // char gap
51  int16_t space); // word gap
52  ROW( // constructor
53  TO_ROW *row, // textord row
54  int16_t kern, // char gap
55  int16_t space); // word gap
56 
57  WERD_LIST *word_list() { // get words
58  return &words;
59  }
60 
61  float base_line( // compute baseline
62  float xpos) const { // at the position
63  // get spline value
64  return static_cast<float>(baseline.y(xpos));
65  }
66  float x_height() const { // return x height
67  return xheight;
68  }
69  void set_x_height(float new_xheight) { // set x height
70  xheight = new_xheight;
71  }
72  int32_t kern() const { // return kerning
73  return kerning;
74  }
75  float body_size() const { // return body size
76  return bodysize;
77  }
78  void set_body_size(float new_size) { // set body size
79  bodysize = new_size;
80  }
81  int32_t space() const { // return spacing
82  return spacing;
83  }
84  float ascenders() const { // return size
85  return ascrise;
86  }
87  float descenders() const { // return size
88  return descdrop;
89  }
90  TBOX bounding_box() const { // return bounding box
91  return bound_box;
92  }
93  // Returns the bounding box including the desired combination of upper and
94  // lower noise/diacritic elements.
95  TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const;
96 
97  void set_lmargin(int16_t lmargin) {
98  lmargin_ = lmargin;
99  }
100  void set_rmargin(int16_t rmargin) {
101  rmargin_ = rmargin;
102  }
103  int16_t lmargin() const {
104  return lmargin_;
105  }
106  int16_t rmargin() const {
107  return rmargin_;
108  }
109 
110  void set_has_drop_cap(bool has) {
111  has_drop_cap_ = has;
112  }
113  bool has_drop_cap() const {
114  return has_drop_cap_;
115  }
116 
117  void set_para(PARA *p) {
118  para_ = p;
119  }
120  PARA *para() const {
121  return para_;
122  }
123 
124  void recalc_bounding_box(); // recalculate BB
125 
126  void move( // reposition row
127  const ICOORD vec); // by vector
128 
129  void print( // print
130  FILE *fp) const; // file to print on
131 
132 #ifndef GRAPHICS_DISABLED
133  void plot( // draw one
134  ScrollView *window, // window to draw in
135  ScrollView::Color colour); // uniform colour
136  void plot( // draw one
137  ScrollView *window); // in rainbow colours
138 
139  void plot_baseline( // draw the baseline
140  ScrollView *window, // window to draw in
141  ScrollView::Color colour) { // colour to draw
142  // draw it
143  baseline.plot(window, colour);
144  }
145 #endif // !GRAPHICS_DISABLED
146  ROW &operator=(const ROW &source);
147 
148 private:
149  // Copy constructor (currently unused, therefore private).
150  ROW(const ROW &source) = delete;
151 
152  int32_t kerning; // inter char gap
153  int32_t spacing; // inter word gap
154  TBOX bound_box; // bounding box
155  float xheight; // height of line
156  float ascrise; // size of ascenders
157  float descdrop; //-size of descenders
158  float bodysize; // CJK character size. (equals to
159  // xheight+ascrise by default)
160  WERD_LIST words; // words
161  QSPLINE baseline; // baseline spline
162 
163  // These get set after blocks have been determined.
164  bool has_drop_cap_;
165  int16_t lmargin_; // Distance to left polyblock margin.
166  int16_t rmargin_; // Distance to right polyblock margin.
167 
168  // This gets set during paragraph analysis.
169  PARA *para_; // Paragraph of which this row is part.
170 };
171 
172 ELISTIZEH(ROW)
173 
174 } // namespace tesseract
175 
176 #endif
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:803
TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const
Definition: ocrrow.cpp:84
void set_lmargin(int16_t lmargin)
Definition: ocrrow.h:97
float body_size() const
Definition: ocrrow.h:75
ROW & operator=(const ROW &source)
Definition: ocrrow.cpp:225
void move(const ICOORD vec)
Definition: ocrrow.cpp:148
WERD_LIST * word_list()
Definition: ocrrow.h:57
void plot_baseline(ScrollView *window, ScrollView::Color colour)
Definition: ocrrow.h:139
void set_body_size(float new_size)
Definition: ocrrow.h:78
void plot(ScrollView *window, ScrollView::Color colour)
Definition: ocrrow.cpp:187
bool has_drop_cap() const
Definition: ocrrow.h:113
void set_rmargin(int16_t rmargin)
Definition: ocrrow.h:100
int32_t kern() const
Definition: ocrrow.h:72
void recalc_bounding_box()
Definition: ocrrow.cpp:100
void print(FILE *fp) const
Definition: ocrrow.cpp:167
void set_has_drop_cap(bool has)
Definition: ocrrow.h:110
void set_para(PARA *p)
Definition: ocrrow.h:117
int16_t rmargin() const
Definition: ocrrow.h:106
float x_height() const
Definition: ocrrow.h:66
float base_line(float xpos) const
Definition: ocrrow.h:61
PARA * para() const
Definition: ocrrow.h:120
TBOX bounding_box() const
Definition: ocrrow.h:90
int16_t lmargin() const
Definition: ocrrow.h:103
void set_x_height(float new_xheight)
Definition: ocrrow.h:69
ROW()=default
int32_t space() const
Definition: ocrrow.h:81
float ascenders() const
Definition: ocrrow.h:84
float descenders() const
Definition: ocrrow.h:87
friend void tweak_row_baseline(ROW *, double, double)
Definition: tordmain.cpp:864
integer coordinate
Definition: points.h:36
double y(double x) const
Definition: quspline.cpp:203
void plot(ScrollView *window, ScrollView::Color colour) const
Definition: quspline.cpp:340