tesseract 4.1.1
Loading...
Searching...
No Matches
BLOCK Class Reference

#include <ocrblock.h>

Inheritance diagram for BLOCK:
ELIST_LINK

Public Member Functions

 BLOCK ()
 
 BLOCK (const char *name, bool prop, int16_t kern, int16_t space, int16_t xmin, int16_t ymin, int16_t xmax, int16_t ymax)
 
 ~BLOCK ()=default
 
void set_stats (bool prop, int16_t kern, int16_t space, int16_t ch_pitch)
 
void set_xheight (int32_t height)
 set char size More...
 
void set_font_class (int16_t font)
 set font class More...
 
bool prop () const
 return proportional More...
 
bool right_to_left () const
 
void set_right_to_left (bool value)
 
int32_t fixed_pitch () const
 return pitch More...
 
int16_t kern () const
 return kerning More...
 
int16_t font () const
 return font class More...
 
int16_t space () const
 return spacing More...
 
const char * name () const
 return filename More...
 
int32_t x_height () const
 return xheight More...
 
float cell_over_xheight () const
 
void set_cell_over_xheight (float ratio)
 
ROW_LIST * row_list ()
 get rows More...
 
void compute_row_margins ()
 
PARA_LIST * para_list ()
 
C_BLOB_LIST * blob_list ()
 get blobs More...
 
C_BLOB_LIST * reject_blobs ()
 
FCOORD re_rotation () const
 
void set_re_rotation (const FCOORD &rotation)
 
FCOORD classify_rotation () const
 
void set_classify_rotation (const FCOORD &rotation)
 
FCOORD skew () const
 
void set_skew (const FCOORD &skew)
 
const ICOORDmedian_size () const
 
void set_median_size (int x, int y)
 
Pix * render_mask (TBOX *mask_box)
 
TBOX restricted_bounding_box (bool upper_dots, bool lower_dots) const
 
void reflect_polygon_in_y_axis ()
 
void rotate (const FCOORD &rotation)
 
void sort_rows ()
 decreasing y order More...
 
void compress ()
 shrink white space More...
 
void check_pitch ()
 check proportional More...
 
void compress (const ICOORD vec)
 shrink white space and move by vector More...
 
void print (FILE *fp, bool dump)
 dump whole table More...
 
BLOCKoperator= (const BLOCK &source)
 
- Public Member Functions inherited from ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Public Attributes

PDBLK pdblk
 Page Description Block. More...
 

Friends

class BLOCK_RECT_IT
 

Detailed Description

Definition at line 29 of file ocrblock.h.

Constructor & Destructor Documentation

◆ BLOCK() [1/2]

BLOCK::BLOCK ( )
inline

Definition at line 34 of file ocrblock.h.

35 : re_rotation_(1.0f, 0.0f),
36 classify_rotation_(1.0f, 0.0f),
37 skew_(1.0f, 0.0f) {
38 pdblk.hand_poly = nullptr;
39 }
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:190
POLY_BLOCK * hand_poly
weird as well
Definition: pdblock.h:95

◆ BLOCK() [2/2]

BLOCK::BLOCK ( const char *  name,
bool  prop,
int16_t  kern,
int16_t  space,
int16_t  xmin,
int16_t  ymin,
int16_t  xmax,
int16_t  ymax 
)

BLOCK::BLOCK

Constructor for a simple rectangular block.

Parameters
namefilename
propproportional
kernkerning
spacespacing
xminbottom left
xmaxtop right

Definition at line 31 of file ocrblock.cpp.

38 : pdblk(xmin, ymin, xmax, ymax),
39 filename(name),
40 re_rotation_(1.0f, 0.0f),
41 classify_rotation_(1.0f, 0.0f),
42 skew_(1.0f, 0.0f) {
43 ICOORDELT_IT left_it = &pdblk.leftside;
44 ICOORDELT_IT right_it = &pdblk.rightside;
45
46 proportional = prop;
47 kerning = kern;
48 spacing = space;
49 font_class = -1; //not assigned
50 cell_over_xheight_ = 2.0f;
51 pdblk.hand_poly = nullptr;
52 left_it.set_to_list (&pdblk.leftside);
53 right_it.set_to_list (&pdblk.rightside);
54 //make default box
55 left_it.add_to_end (new ICOORDELT (xmin, ymin));
56 left_it.add_to_end (new ICOORDELT (xmin, ymax));
57 right_it.add_to_end (new ICOORDELT (xmax, ymin));
58 right_it.add_to_end (new ICOORDELT (xmax, ymax));
59}
int16_t kern() const
return kerning
Definition: ocrblock.h:90
const char * name() const
return filename
Definition: ocrblock.h:102
int16_t space() const
return spacing
Definition: ocrblock.h:98
bool prop() const
return proportional
Definition: ocrblock.h:76
ICOORDELT_LIST rightside
right side vertices
Definition: pdblock.h:97
ICOORDELT_LIST leftside
left side vertices
Definition: pdblock.h:96

◆ ~BLOCK()

BLOCK::~BLOCK ( )
default

Member Function Documentation

◆ blob_list()

C_BLOB_LIST * BLOCK::blob_list ( )
inline

get blobs

Definition at line 128 of file ocrblock.h.

128 {
129 return &c_blobs;
130 }

◆ cell_over_xheight()

float BLOCK::cell_over_xheight ( ) const
inline

Definition at line 109 of file ocrblock.h.

109 {
110 return cell_over_xheight_;
111 }

◆ check_pitch()

void BLOCK::check_pitch ( )

check proportional

BLOCK::check_pitch

Check whether the block is fixed or prop, set the flag, and set the pitch if it is fixed.

Definition at line 164 of file ocrblock.cpp.

164 { // check prop
165 // tprintf("Missing FFT fixed pitch stuff!\n");
166 pitch = -1;
167}

◆ classify_rotation()

FCOORD BLOCK::classify_rotation ( ) const
inline

Definition at line 140 of file ocrblock.h.

140 {
141 return classify_rotation_; // Apply this before classifying.
142 }

◆ compress() [1/2]

void BLOCK::compress ( )

shrink white space

BLOCK::compress

Delete space between the rows. (And maybe one day, compress the rows) Fill space of block from top down, left aligning rows.

Definition at line 126 of file ocrblock.cpp.

126 { // squash it up
127 #define ROW_SPACING 5
128
129 ROW_IT row_it(&rows);
130 ROW *row;
131 ICOORD row_spacing (0, ROW_SPACING);
132
133 ICOORDELT_IT icoordelt_it;
134
135 sort_rows();
136
139 for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
140 row = row_it.data ();
141 row->move (pdblk.box.botleft () - row_spacing -
142 row->bounding_box ().topleft ());
143 pdblk.box += row->bounding_box ();
144 }
145
146 pdblk.leftside.clear ();
147 icoordelt_it.set_to_list (&pdblk.leftside);
148 icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.left (), pdblk.box.bottom ()));
149 icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.left (), pdblk.box.top ()));
150 pdblk.rightside.clear ();
151 icoordelt_it.set_to_list (&pdblk.rightside);
152 icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.right (), pdblk.box.bottom ()));
153 icoordelt_it.add_to_end (new ICOORDELT (pdblk.box.right (), pdblk.box.top ()));
154}
#define ROW_SPACING
void sort_rows()
decreasing y order
Definition: ocrblock.cpp:112
Definition: ocrrow.h:37
void move(const ICOORD vec)
Definition: ocrrow.cpp:147
TBOX bounding_box() const
Definition: ocrrow.h:88
TBOX box
bounding box
Definition: pdblock.h:98
integer coordinate
Definition: points.h:32
Definition: rect.h:34
const ICOORD & botleft() const
Definition: rect.h:92
int16_t top() const
Definition: rect.h:58
ICOORD topleft() const
Definition: rect.h:100
int16_t left() const
Definition: rect.h:72
int16_t bottom() const
Definition: rect.h:65
void move_bottom_edge(const int16_t y)
Definition: rect.h:137
int16_t right() const
Definition: rect.h:79

◆ compress() [2/2]

void BLOCK::compress ( const ICOORD  vec)

shrink white space and move by vector

BLOCK::compress

Compress and move in a single operation.

Definition at line 176 of file ocrblock.cpp.

178 {
179 pdblk.box.move (vec);
180 compress();
181}
void compress()
shrink white space
Definition: ocrblock.cpp:126
void move(const ICOORD vec)
Definition: rect.h:157

◆ compute_row_margins()

void BLOCK::compute_row_margins ( )

Definition at line 327 of file ocrblock.cpp.

327 {
328 if (row_list()->empty() || row_list()->singleton()) {
329 return;
330 }
331
332 // If Layout analysis was not called, default to this.
334 POLY_BLOCK *pblock = &rect_block;
335 if (pdblk.poly_block() != nullptr) {
336 pblock = pdblk.poly_block();
337 }
338
339 // Step One: Determine if there is a drop-cap.
340 // TODO(eger): Fix up drop cap code for RTL languages.
341 ROW_IT r_it(row_list());
342 ROW *first_row = r_it.data();
343 ROW *second_row = r_it.data_relative(1);
344
345 // initialize the bottom of a fictitious drop cap far above the first line.
346 int drop_cap_bottom = first_row->bounding_box().top() +
347 first_row->bounding_box().height();
348 int drop_cap_right = first_row->bounding_box().left();
349 int mid_second_line = second_row->bounding_box().top() -
350 second_row->bounding_box().height() / 2;
351 WERD_IT werd_it(r_it.data()->word_list()); // words of line one
352 if (!werd_it.empty()) {
353 C_BLOB_IT cblob_it(werd_it.data()->cblob_list());
354 for (cblob_it.mark_cycle_pt(); !cblob_it.cycled_list();
355 cblob_it.forward()) {
356 TBOX bbox = cblob_it.data()->bounding_box();
357 if (bbox.bottom() <= mid_second_line) {
358 // we found a real drop cap
359 first_row->set_has_drop_cap(true);
360 if (drop_cap_bottom > bbox.bottom())
361 drop_cap_bottom = bbox.bottom();
362 if (drop_cap_right < bbox.right())
363 drop_cap_right = bbox.right();
364 }
365 }
366 }
367
368 // Step Two: Calculate the margin from the text of each row to the block
369 // (or drop-cap) boundaries.
370 PB_LINE_IT lines(pblock);
371 r_it.set_to_list(row_list());
372 for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
373 ROW *row = r_it.data();
374 TBOX row_box = row->bounding_box();
375 int left_y = row->base_line(row_box.left()) + row->x_height();
376 int left_margin;
377 const std::unique_ptr</*non-const*/ ICOORDELT_LIST> segments_left(
378 lines.get_line(left_y));
379 LeftMargin(segments_left.get(), row_box.left(), &left_margin);
380
381 if (row_box.top() >= drop_cap_bottom) {
382 int drop_cap_distance = row_box.left() - row->space() - drop_cap_right;
383 if (drop_cap_distance < 0)
384 drop_cap_distance = 0;
385 if (drop_cap_distance < left_margin)
386 left_margin = drop_cap_distance;
387 }
388
389 int right_y = row->base_line(row_box.right()) + row->x_height();
390 int right_margin;
391 const std::unique_ptr</*non-const*/ ICOORDELT_LIST> segments_right(
392 lines.get_line(right_y));
393 RightMargin(segments_right.get(), row_box.right(), &right_margin);
394 row->set_lmargin(left_margin);
395 row->set_rmargin(right_margin);
396 }
397}
@ PT_FLOWING_TEXT
Definition: capi.h:130
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:116
void set_has_drop_cap(bool has)
Definition: ocrrow.h:108
int32_t space() const
Definition: ocrrow.h:79
float base_line(float xpos) const
Definition: ocrrow.h:59
void set_lmargin(int16_t lmargin)
Definition: ocrrow.h:95
void set_rmargin(int16_t rmargin)
Definition: ocrrow.h:98
float x_height() const
Definition: ocrrow.h:64
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:59
POLY_BLOCK * poly_block() const
Definition: pdblock.h:55
int16_t height() const
Definition: rect.h:108

◆ fixed_pitch()

int32_t BLOCK::fixed_pitch ( ) const
inline

return pitch

Definition at line 86 of file ocrblock.h.

86 {
87 return pitch;
88 }

◆ font()

int16_t BLOCK::font ( ) const
inline

return font class

Definition at line 94 of file ocrblock.h.

94 {
95 return font_class;
96 }

◆ kern()

int16_t BLOCK::kern ( ) const
inline

return kerning

Definition at line 90 of file ocrblock.h.

90 {
91 return kerning;
92 }

◆ median_size()

const ICOORD & BLOCK::median_size ( ) const
inline

Definition at line 152 of file ocrblock.h.

152 {
153 return median_size_;
154 }

◆ name()

const char * BLOCK::name ( ) const
inline

return filename

Definition at line 102 of file ocrblock.h.

102 {
103 return filename.string ();
104 }
const char * string() const
Definition: strngs.cpp:194

◆ operator=()

BLOCK & BLOCK::operator= ( const BLOCK source)

BLOCK::operator=

Assignment - duplicate the block structure, but with an EMPTY row list.

Definition at line 222 of file ocrblock.cpp.

224 {
225 this->ELIST_LINK::operator= (source);
226 pdblk = source.pdblk;
227 proportional = source.proportional;
228 kerning = source.kerning;
229 spacing = source.spacing;
230 filename = source.filename; //STRINGs assign ok
231 if (!rows.empty ())
232 rows.clear ();
233 re_rotation_ = source.re_rotation_;
234 classify_rotation_ = source.classify_rotation_;
235 skew_ = source.skew_;
236 return *this;
237}
void operator=(const ELIST_LINK &)
Definition: elst.h:94

◆ para_list()

PARA_LIST * BLOCK::para_list ( )
inline

Definition at line 124 of file ocrblock.h.

124 {
125 return &paras_;
126 }

◆ print()

void BLOCK::print ( FILE *  fp,
bool  dump 
)

dump whole table

BLOCK::print

Print the info on a block

Parameters
fpfile to print on
dumpprint full detail

Definition at line 190 of file ocrblock.cpp.

193 {
194 ICOORDELT_IT it = &pdblk.leftside; //iterator
195
196 pdblk.box.print ();
197 tprintf ("Proportional= %s\n", proportional ? "TRUE" : "FALSE");
198 tprintf ("Kerning= %d\n", kerning);
199 tprintf ("Spacing= %d\n", spacing);
200 tprintf ("Fixed_pitch=%d\n", pitch);
201 tprintf ("Filename= %s\n", filename.string ());
202
203 if (dump) {
204 tprintf ("Left side coords are:\n");
205 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
206 tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
207 tprintf ("\n");
208 tprintf ("Right side coords are:\n");
209 it.set_to_list (&pdblk.rightside);
210 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
211 tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
212 tprintf ("\n");
213 }
214}
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
void print() const
Definition: rect.h:278

◆ prop()

bool BLOCK::prop ( ) const
inline

return proportional

Definition at line 76 of file ocrblock.h.

76 {
77 return proportional;
78 }

◆ re_rotation()

FCOORD BLOCK::re_rotation ( ) const
inline

Definition at line 134 of file ocrblock.h.

134 {
135 return re_rotation_; // How to transform coords back to image.
136 }

◆ reflect_polygon_in_y_axis()

void BLOCK::reflect_polygon_in_y_axis ( )

BLOCK::reflect_polygon_in_y_axis

Reflects the polygon in the y-axis and recompute the bounding_box. Does nothing to any contained rows/words/blobs etc.

Definition at line 101 of file ocrblock.cpp.

101 {
104}
void reflect_in_y_axis()
Definition: polyblk.cpp:208
TBOX * bounding_box()
Definition: polyblk.h:35

◆ reject_blobs()

C_BLOB_LIST * BLOCK::reject_blobs ( )
inline

Definition at line 131 of file ocrblock.h.

131 {
132 return &rej_blobs;
133 }

◆ render_mask()

Pix * BLOCK::render_mask ( TBOX mask_box)
inline

Definition at line 160 of file ocrblock.h.

160 {
161 return pdblk.render_mask(re_rotation_, mask_box);
162 }
Pix * render_mask(const FCOORD &rerotation, TBOX *mask_box)
Definition: pdblock.cpp:131

◆ restricted_bounding_box()

TBOX BLOCK::restricted_bounding_box ( bool  upper_dots,
bool  lower_dots 
) const

Definition at line 85 of file ocrblock.cpp.

85 {
86 TBOX box;
87 // This is a read-only iteration of the rows in the block.
88 ROW_IT it(const_cast<ROW_LIST*>(&rows));
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}

◆ right_to_left()

bool BLOCK::right_to_left ( ) const
inline

Definition at line 79 of file ocrblock.h.

79 {
80 return right_to_left_;
81 }

◆ rotate()

void BLOCK::rotate ( const FCOORD rotation)

BLOCK::rotate

Rotate the polygon by the given rotation and recompute the bounding_box.

Definition at line 78 of file ocrblock.cpp.

78 {
79 pdblk.poly_block()->rotate(rotation);
81}
void rotate(FCOORD rotation)
Definition: polyblk.cpp:184

◆ row_list()

ROW_LIST * BLOCK::row_list ( )
inline

get rows

Definition at line 116 of file ocrblock.h.

116 {
117 return &rows;
118 }

◆ set_cell_over_xheight()

void BLOCK::set_cell_over_xheight ( float  ratio)
inline

Definition at line 112 of file ocrblock.h.

112 {
113 cell_over_xheight_ = ratio;
114 }

◆ set_classify_rotation()

void BLOCK::set_classify_rotation ( const FCOORD rotation)
inline

Definition at line 143 of file ocrblock.h.

143 {
144 classify_rotation_ = rotation;
145 }

◆ set_font_class()

void BLOCK::set_font_class ( int16_t  font)
inline

set font class

Definition at line 72 of file ocrblock.h.

72 {
73 font_class = font;
74 }
int16_t font() const
return font class
Definition: ocrblock.h:94

◆ set_median_size()

void BLOCK::set_median_size ( int  x,
int  y 
)
inline

Definition at line 155 of file ocrblock.h.

155 {
156 median_size_.set_x(x);
157 median_size_.set_y(y);
158 }
void set_x(int16_t xin)
rewrite function
Definition: points.h:61
void set_y(int16_t yin)
rewrite function
Definition: points.h:65

◆ set_re_rotation()

void BLOCK::set_re_rotation ( const FCOORD rotation)
inline

Definition at line 137 of file ocrblock.h.

137 {
138 re_rotation_ = rotation;
139 }

◆ set_right_to_left()

void BLOCK::set_right_to_left ( bool  value)
inline

Definition at line 82 of file ocrblock.h.

82 {
83 right_to_left_ = value;
84 }

◆ set_skew()

void BLOCK::set_skew ( const FCOORD skew)
inline

Definition at line 149 of file ocrblock.h.

149 {
150 skew_ = skew;
151 }
FCOORD skew() const
Definition: ocrblock.h:146

◆ set_stats()

void BLOCK::set_stats ( bool  prop,
int16_t  kern,
int16_t  space,
int16_t  ch_pitch 
)
inline

set space size etc.

Parameters
propproportional
kerninter char size
spaceinter word size
ch_pitchpitch if fixed

Definition at line 58 of file ocrblock.h.

61 {
62 proportional = prop;
63 kerning = static_cast<int8_t>(kern);
64 spacing = space;
65 pitch = ch_pitch;
66 }

◆ set_xheight()

void BLOCK::set_xheight ( int32_t  height)
inline

set char size

Definition at line 68 of file ocrblock.h.

68 {
69 xheight = height;
70 }

◆ skew()

FCOORD BLOCK::skew ( ) const
inline

Definition at line 146 of file ocrblock.h.

146 {
147 return skew_; // Direction of true horizontal.
148 }

◆ sort_rows()

void BLOCK::sort_rows ( )

decreasing y order

BLOCK::sort_rows

Order rows so that they are in order of decreasing Y coordinate

Definition at line 112 of file ocrblock.cpp.

112 { // order on "top"
113 ROW_IT row_it(&rows);
114
115 row_it.sort (decreasing_top_order);
116}

◆ space()

int16_t BLOCK::space ( ) const
inline

return spacing

Definition at line 98 of file ocrblock.h.

98 {
99 return spacing;
100 }

◆ x_height()

int32_t BLOCK::x_height ( ) const
inline

return xheight

Definition at line 106 of file ocrblock.h.

106 {
107 return xheight;
108 }

Friends And Related Function Documentation

◆ BLOCK_RECT_IT

friend class BLOCK_RECT_IT
friend

Definition at line 32 of file ocrblock.h.

Member Data Documentation

◆ pdblk

PDBLK BLOCK::pdblk

Page Description Block.

Definition at line 190 of file ocrblock.h.


The documentation for this class was generated from the following files: