tesseract  5.0.0-alpha-619-ge9db
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 <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 static_cast<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.
162  bool has_drop_cap_;
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
ScrollView
Definition: scrollview.h:97
elst.h
ROW::para
PARA * para() const
Definition: ocrrow.h:117
ROW::base_line
float base_line(float xpos) const
Definition: ocrrow.h:58
ROW::set_has_drop_cap
void set_has_drop_cap(bool has)
Definition: ocrrow.h:107
ROW::descenders
float descenders() const
Definition: ocrrow.h:84
ROW::set_rmargin
void set_rmargin(int16_t rmargin)
Definition: ocrrow.h:97
ROW::rmargin
int16_t rmargin() const
Definition: ocrrow.h:103
ROW::plot
void plot(ScrollView *window, ScrollView::Color colour)
Definition: ocrrow.cpp:180
ICOORD
integer coordinate
Definition: points.h:30
ROW::recalc_bounding_box
void recalc_bounding_box()
Definition: ocrrow.cpp:96
QSPLINE
Definition: quspline.h:31
ROW::print
void print(FILE *fp)
Definition: ocrrow.cpp:160
rect.h
ROW::tweak_row_baseline
friend void tweak_row_baseline(ROW *, double, double)
Definition: tordmain.cpp:893
ELISTIZEH
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:907
ROW::operator=
ROW & operator=(const ROW &source)
Definition: ocrrow.cpp:216
ROW::lmargin
int16_t lmargin() const
Definition: ocrrow.h:100
werd.h
ROW::x_height
float x_height() const
Definition: ocrrow.h:63
QSPLINE::plot
void plot(ScrollView *window, ScrollView::Color colour) const
Definition: quspline.cpp:335
ROW::restricted_bounding_box
TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const
Definition: ocrrow.cpp:81
ROW::space
int32_t space() const
Definition: ocrrow.h:78
ROW::plot_baseline
void plot_baseline(ScrollView *window, ScrollView::Color colour)
Definition: ocrrow.h:136
ROW::ascenders
float ascenders() const
Definition: ocrrow.h:81
ROW::bounding_box
TBOX bounding_box() const
Definition: ocrrow.h:87
ROW::has_drop_cap
bool has_drop_cap() const
Definition: ocrrow.h:110
ROW::move
void move(const ICOORD vec)
Definition: ocrrow.cpp:142
ROW::kern
int32_t kern() const
Definition: ocrrow.h:69
ROW::set_body_size
void set_body_size(float new_size)
Definition: ocrrow.h:75
ROW::set_para
void set_para(PARA *p)
Definition: ocrrow.h:114
ROW::set_lmargin
void set_lmargin(int16_t lmargin)
Definition: ocrrow.h:94
quspline.h
ROW::ROW
ROW()=default
QSPLINE::y
double y(double x) const
Definition: quspline.cpp:202
ROW
Definition: ocrrow.h:35
TO_ROW
Definition: blobbox.h:543
PARA
Definition: ocrpara.h:29
ELIST_LINK
Definition: elst.h:74
ScrollView::Color
Color
Definition: scrollview.h:100
ROW::word_list
WERD_LIST * word_list()
Definition: ocrrow.h:54
scrollview.h
ROW::body_size
float body_size() const
Definition: ocrrow.h:72
ROW::set_x_height
void set_x_height(float new_xheight)
Definition: ocrrow.h:66
TBOX
Definition: rect.h:33