/src/tesseract/src/ccstruct/ocrrow.h
Line | Count | Source (jump to first uncovered line) |
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<ROW>::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 | 1.75M | WERD_LIST *word_list() { // get words |
58 | 1.75M | return &words; |
59 | 1.75M | } |
60 | | |
61 | | float base_line( // compute baseline |
62 | 3.93M | float xpos) const { // at the position |
63 | | // get spline value |
64 | 3.93M | return static_cast<float>(baseline.y(xpos)); |
65 | 3.93M | } |
66 | 9.39M | float x_height() const { // return x height |
67 | 9.39M | return xheight; |
68 | 9.39M | } |
69 | 0 | void set_x_height(float new_xheight) { // set x height |
70 | 0 | xheight = new_xheight; |
71 | 0 | } |
72 | 0 | int32_t kern() const { // return kerning |
73 | 0 | return kerning; |
74 | 0 | } |
75 | 0 | float body_size() const { // return body size |
76 | 0 | return bodysize; |
77 | 0 | } |
78 | 0 | void set_body_size(float new_size) { // set body size |
79 | 0 | bodysize = new_size; |
80 | 0 | } |
81 | 331k | int32_t space() const { // return spacing |
82 | 331k | return spacing; |
83 | 331k | } |
84 | 449k | float ascenders() const { // return size |
85 | 449k | return ascrise; |
86 | 449k | } |
87 | 458k | float descenders() const { // return size |
88 | 458k | return descdrop; |
89 | 458k | } |
90 | 231k | TBOX bounding_box() const { // return bounding box |
91 | 231k | return bound_box; |
92 | 231k | } |
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 | 157k | void set_lmargin(int16_t lmargin) { |
98 | 157k | lmargin_ = lmargin; |
99 | 157k | } |
100 | 157k | void set_rmargin(int16_t rmargin) { |
101 | 157k | rmargin_ = rmargin; |
102 | 157k | } |
103 | 160k | int16_t lmargin() const { |
104 | 160k | return lmargin_; |
105 | 160k | } |
106 | 160k | int16_t rmargin() const { |
107 | 160k | return rmargin_; |
108 | 160k | } |
109 | | |
110 | 4.41k | void set_has_drop_cap(bool has) { |
111 | 4.41k | has_drop_cap_ = has; |
112 | 4.41k | } |
113 | 160k | bool has_drop_cap() const { |
114 | 160k | return has_drop_cap_; |
115 | 160k | } |
116 | | |
117 | 320k | void set_para(PARA *p) { |
118 | 320k | para_ = p; |
119 | 320k | } |
120 | 42.9M | PARA *para() const { |
121 | 42.9M | return para_; |
122 | 42.9M | } |
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 |