tesseract  5.0.0-alpha-619-ge9db
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 28 of file ocrblock.h.

Constructor & Destructor Documentation

◆ BLOCK() [1/2]

BLOCK::BLOCK ( )
inline

Definition at line 33 of file ocrblock.h.

33  :
34  BLOCK()
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;

◆ 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 30 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));

◆ ~BLOCK()

BLOCK::~BLOCK ( )
default

Member Function Documentation

◆ blob_list()

C_BLOB_LIST* BLOCK::blob_list ( )
inline

get blobs

Definition at line 127 of file ocrblock.h.

128  {
129  return &c_blobs;

◆ cell_over_xheight()

float BLOCK::cell_over_xheight ( ) const
inline

Definition at line 108 of file ocrblock.h.

109  {
110  return cell_over_xheight_;

◆ 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 163 of file ocrblock.cpp.

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

◆ classify_rotation()

FCOORD BLOCK::classify_rotation ( ) const
inline

Definition at line 139 of file ocrblock.h.

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

◆ 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 125 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 ()));

◆ 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 175 of file ocrblock.cpp.

178  {
179  pdblk.box.move (vec);
180  compress();

◆ compute_row_margins()

void BLOCK::compute_row_margins ( )

Definition at line 326 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  }

◆ fixed_pitch()

int32_t BLOCK::fixed_pitch ( ) const
inline

return pitch

Definition at line 85 of file ocrblock.h.

86  {
87  return pitch;

◆ font()

int16_t BLOCK::font ( ) const
inline

return font class

Definition at line 93 of file ocrblock.h.

94  {
95  return font_class;

◆ kern()

int16_t BLOCK::kern ( ) const
inline

return kerning

Definition at line 89 of file ocrblock.h.

90  {
91  return kerning;

◆ median_size()

const ICOORD& BLOCK::median_size ( ) const
inline

Definition at line 151 of file ocrblock.h.

152  {
153  return median_size_;

◆ name()

const char* BLOCK::name ( ) const
inline

return filename

Definition at line 101 of file ocrblock.h.

102  {
103  return filename.c_str ();

◆ operator=()

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

BLOCK::operator=

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

Definition at line 221 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;

◆ para_list()

PARA_LIST* BLOCK::para_list ( )
inline

Definition at line 123 of file ocrblock.h.

124  {
125  return &paras_;

◆ 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 189 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.c_str ());
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  }

◆ prop()

bool BLOCK::prop ( ) const
inline

return proportional

Definition at line 75 of file ocrblock.h.

76  {
77  return proportional;

◆ re_rotation()

FCOORD BLOCK::re_rotation ( ) const
inline

Definition at line 133 of file ocrblock.h.

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

◆ 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 100 of file ocrblock.cpp.

◆ reject_blobs()

C_BLOB_LIST* BLOCK::reject_blobs ( )
inline

Definition at line 130 of file ocrblock.h.

131  {
132  return &rej_blobs;

◆ render_mask()

Pix* BLOCK::render_mask ( TBOX mask_box)
inline

Definition at line 159 of file ocrblock.h.

160  {
161  return pdblk.render_mask(re_rotation_, mask_box);

◆ restricted_bounding_box()

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

Definition at line 84 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;

◆ right_to_left()

bool BLOCK::right_to_left ( ) const
inline

Definition at line 78 of file ocrblock.h.

79  {
80  return right_to_left_;

◆ rotate()

void BLOCK::rotate ( const FCOORD rotation)

BLOCK::rotate

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

Definition at line 77 of file ocrblock.cpp.

78  {
79  pdblk.poly_block()->rotate(rotation);

◆ row_list()

ROW_LIST* BLOCK::row_list ( )
inline

get rows

Definition at line 115 of file ocrblock.h.

116  {
117  return &rows;

◆ set_cell_over_xheight()

void BLOCK::set_cell_over_xheight ( float  ratio)
inline

Definition at line 111 of file ocrblock.h.

112  {
113  cell_over_xheight_ = ratio;

◆ set_classify_rotation()

void BLOCK::set_classify_rotation ( const FCOORD rotation)
inline

Definition at line 142 of file ocrblock.h.

143  {
144  classify_rotation_ = rotation;

◆ set_font_class()

void BLOCK::set_font_class ( int16_t  font)
inline

set font class

Definition at line 71 of file ocrblock.h.

72  {
73  font_class = font;

◆ set_median_size()

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

Definition at line 154 of file ocrblock.h.

155  {
156  median_size_.set_x(x);
157  median_size_.set_y(y);

◆ set_re_rotation()

void BLOCK::set_re_rotation ( const FCOORD rotation)
inline

Definition at line 136 of file ocrblock.h.

137  {
138  re_rotation_ = rotation;

◆ set_right_to_left()

void BLOCK::set_right_to_left ( bool  value)
inline

Definition at line 81 of file ocrblock.h.

82  {
83  right_to_left_ = value;

◆ set_skew()

void BLOCK::set_skew ( const FCOORD skew)
inline

Definition at line 148 of file ocrblock.h.

149  {
150  skew_ = skew;

◆ 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 57 of file ocrblock.h.

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

◆ set_xheight()

void BLOCK::set_xheight ( int32_t  height)
inline

set char size

Definition at line 67 of file ocrblock.h.

68  {
69  xheight = height;

◆ skew()

FCOORD BLOCK::skew ( ) const
inline

Definition at line 145 of file ocrblock.h.

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

◆ 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 111 of file ocrblock.cpp.

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

◆ space()

int16_t BLOCK::space ( ) const
inline

return spacing

Definition at line 97 of file ocrblock.h.

98  {
99  return spacing;

◆ x_height()

int32_t BLOCK::x_height ( ) const
inline

return xheight

Definition at line 105 of file ocrblock.h.

106  {
107  return xheight;

Friends And Related Function Documentation

◆ BLOCK_RECT_IT

friend class BLOCK_RECT_IT
friend

Definition at line 31 of file ocrblock.h.

Member Data Documentation

◆ pdblk

PDBLK BLOCK::pdblk

Page Description Block.

Definition at line 189 of file ocrblock.h.


The documentation for this class was generated from the following files:
TBOX
Definition: cleanapi_test.cc:19
ICOORD::set_x
void set_x(int16_t xin)
rewrite function
Definition: points.h:60
TBOX::move
void move(const ICOORD vec)
Definition: rect.h:156
BLOCK::skew
FCOORD skew() const
Definition: ocrblock.h:145
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
PDBLK::bounding_box
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:58
ROW::set_rmargin
void set_rmargin(int16_t rmargin)
Definition: ocrrow.h:97
BLOCK::row_list
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:115
ICOORD
integer coordinate
Definition: points.h:30
BLOCK::sort_rows
void sort_rows()
decreasing y order
Definition: ocrblock.cpp:111
TBOX::print
void print() const
Definition: rect.h:277
BLOCK::name
const char * name() const
return filename
Definition: ocrblock.h:101
TBOX::top
int16_t top() const
Definition: rect.h:57
PB_LINE_IT
Definition: polyblk.h:90
BLOCK::font
int16_t font() const
return font class
Definition: ocrblock.h:93
BLOCK::compress
void compress()
shrink white space
Definition: ocrblock.cpp:125
PDBLK::rightside
ICOORDELT_LIST rightside
right side vertices
Definition: pdblock.h:96
TBOX::topleft
ICOORD topleft() const
Definition: rect.h:99
PDBLK::leftside
ICOORDELT_LIST leftside
left side vertices
Definition: pdblock.h:95
ICOORD::set_y
void set_y(int16_t yin)
rewrite function
Definition: points.h:64
ROW_SPACING
#define ROW_SPACING
BLOCK::space
int16_t space() const
return spacing
Definition: ocrblock.h:97
TBOX::height
int16_t height() const
Definition: rect.h:107
POLY_BLOCK::rotate
void rotate(FCOORD rotation)
Definition: polyblk.cpp:183
BLOCK::pdblk
PDBLK pdblk
Page Description Block.
Definition: ocrblock.h:189
ROW::x_height
float x_height() const
Definition: ocrrow.h:63
ROW::space
int32_t space() const
Definition: ocrrow.h:78
STRING::c_str
const char * c_str() const
Definition: strngs.cpp:192
PDBLK::poly_block
POLY_BLOCK * poly_block() const
Definition: pdblock.h:54
BLOCK::BLOCK
BLOCK()
Definition: ocrblock.h:33
TBOX::move_bottom_edge
void move_bottom_edge(const int16_t y)
Definition: rect.h:136
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
ROW::bounding_box
TBOX bounding_box() const
Definition: ocrrow.h:87
BLOCK::prop
bool prop() const
return proportional
Definition: ocrblock.h:75
ELIST_LINK::operator=
void operator=(const ELIST_LINK &)
Definition: elst.h:134
TBOX::botleft
const ICOORD & botleft() const
Definition: rect.h:91
BLOCK::kern
int16_t kern() const
return kerning
Definition: ocrblock.h:89
ROW::move
void move(const ICOORD vec)
Definition: ocrrow.cpp:142
ROW::set_lmargin
void set_lmargin(int16_t lmargin)
Definition: ocrrow.h:94
POLY_BLOCK::bounding_box
TBOX * bounding_box()
Definition: polyblk.h:48
PDBLK::box
TBOX box
bounding box
Definition: pdblock.h:97
TBOX::left
int16_t left() const
Definition: rect.h:71
ROW
Definition: ocrrow.h:35
PT_FLOWING_TEXT
Definition: capi.h:109
TBOX::right
int16_t right() const
Definition: rect.h:78
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
POLY_BLOCK
Definition: polyblk.h:26
PDBLK::hand_poly
POLY_BLOCK * hand_poly
weird as well
Definition: pdblock.h:94
ICOORDELT
Definition: points.h:160
POLY_BLOCK::reflect_in_y_axis
void reflect_in_y_axis()
Definition: polyblk.cpp:207
TBOX
Definition: rect.h:33
PDBLK::render_mask
Pix * render_mask(const FCOORD &rerotation, TBOX *mask_box)
Definition: pdblock.cpp:126