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