All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BLOCK Class Reference

#include <ocrblock.h>

Inheritance diagram for BLOCK:
ELIST_LINK PDBLK

Public Member Functions

 BLOCK ()
 
 BLOCK (const char *name, BOOL8 prop, inT16 kern, inT16 space, inT16 xmin, inT16 ymin, inT16 xmax, inT16 ymax)
 
 ~BLOCK ()
 
void set_stats (BOOL8 prop, inT16 kern, inT16 space, inT16 ch_pitch)
 
void set_xheight (inT32 height)
 set char size More...
 
void set_font_class (inT16 font)
 set font class More...
 
BOOL8 prop () const
 return proportional More...
 
bool right_to_left () const
 
void set_right_to_left (bool value)
 
inT32 fixed_pitch () const
 return pitch More...
 
inT16 kern () const
 return kerning More...
 
inT16 font () const
 return font class More...
 
inT16 space () const
 return spacing More...
 
const char * name () const
 return filename More...
 
inT32 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, BOOL8 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 Member Functions inherited from PDBLK
 PDBLK ()
 empty constructor More...
 
 PDBLK (inT16 xmin, inT16 ymin, inT16 xmax, inT16 ymax)
 simple constructor More...
 
void set_sides (ICOORDELT_LIST *left, ICOORDELT_LIST *right)
 
 ~PDBLK ()
 destructor More...
 
POLY_BLOCKpoly_block () const
 
void set_poly_block (POLY_BLOCK *blk)
 set the poly block More...
 
void bounding_box (ICOORD &bottom_left, ICOORD &top_right) const
 get box More...
 
const TBOXbounding_box () const
 get real box More...
 
int index () const
 
void set_index (int value)
 
BOOL8 contains (ICOORD pt)
 is pt inside block More...
 
void move (const ICOORD vec)
 reposition block More...
 
Pix * render_mask (const FCOORD &rerotation, TBOX *mask_box)
 
void plot (ScrollView *window, inT32 serial, ScrollView::Color colour)
 
PDBLKoperator= (const PDBLK &source)
 

Friends

class BLOCK_RECT_IT
 

Additional Inherited Members

- Protected Attributes inherited from PDBLK
POLY_BLOCKhand_poly
 
ICOORDELT_LIST leftside
 
ICOORDELT_LIST rightside
 
TBOX box
 
int index_
 

Detailed Description

Definition at line 30 of file ocrblock.h.

Constructor & Destructor Documentation

BLOCK::BLOCK ( )
inline

Definition at line 36 of file ocrblock.h.

37  : re_rotation_(1.0f, 0.0f),
38  classify_rotation_(1.0f, 0.0f),
39  skew_(1.0f, 0.0f) {
40  right_to_left_ = false;
41  hand_poly = NULL;
42  }
POLY_BLOCK * hand_poly
Definition: pdblock.h:111
#define NULL
Definition: host.h:144
BLOCK::BLOCK ( const char *  name,
BOOL8  prop,
inT16  kern,
inT16  space,
inT16  xmin,
inT16  ymin,
inT16  xmax,
inT16  ymax 
)

BLOCK::BLOCK

Constructor for a simple rectangular block.

Definition at line 34 of file ocrblock.cpp.

41  : PDBLK (xmin, ymin, xmax, ymax),
42  filename(name),
43  re_rotation_(1.0f, 0.0f),
44  classify_rotation_(1.0f, 0.0f),
45  skew_(1.0f, 0.0f) {
46  ICOORDELT_IT left_it = &leftside;
47  ICOORDELT_IT right_it = &rightside;
48 
49  proportional = prop;
50  right_to_left_ = false;
51  kerning = kern;
52  spacing = space;
53  font_class = -1; //not assigned
54  cell_over_xheight_ = 2.0f;
55  hand_poly = NULL;
56  left_it.set_to_list (&leftside);
57  right_it.set_to_list (&rightside);
58  //make default box
59  left_it.add_to_end (new ICOORDELT (xmin, ymin));
60  left_it.add_to_end (new ICOORDELT (xmin, ymax));
61  right_it.add_to_end (new ICOORDELT (xmax, ymin));
62  right_it.add_to_end (new ICOORDELT (xmax, ymax));
63 }
POLY_BLOCK * hand_poly
Definition: pdblock.h:111
PDBLK()
empty constructor
Definition: pdblock.h:38
inT16 kern() const
return kerning
Definition: ocrblock.h:94
const char * name() const
return filename
Definition: ocrblock.h:106
ICOORDELT_LIST rightside
Definition: pdblock.h:113
ICOORDELT_LIST leftside
Definition: pdblock.h:112
#define NULL
Definition: host.h:144
inT16 space() const
return spacing
Definition: ocrblock.h:102
BOOL8 prop() const
return proportional
Definition: ocrblock.h:80
BLOCK::~BLOCK ( )
inline

Definition at line 52 of file ocrblock.h.

52  {
53  }

Member Function Documentation

C_BLOB_LIST* BLOCK::blob_list ( )
inline

get blobs

Definition at line 132 of file ocrblock.h.

132  {
133  return &c_blobs;
134  }
float BLOCK::cell_over_xheight ( ) const
inline

Definition at line 113 of file ocrblock.h.

113  {
114  return cell_over_xheight_;
115  }
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 170 of file ocrblock.cpp.

170  { // check prop
171  // tprintf("Missing FFT fixed pitch stuff!\n");
172  pitch = -1;
173 }
FCOORD BLOCK::classify_rotation ( ) const
inline

Definition at line 144 of file ocrblock.h.

144  {
145  return classify_rotation_; // Apply this before classifying.
146  }
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 132 of file ocrblock.cpp.

132  { // squash it up
133  #define ROW_SPACING 5
134 
135  ROW_IT row_it(&rows);
136  ROW *row;
137  ICOORD row_spacing (0, ROW_SPACING);
138 
139  ICOORDELT_IT icoordelt_it;
140 
141  sort_rows();
142 
143  box = TBOX (box.topleft (), box.topleft ());
145  for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
146  row = row_it.data ();
147  row->move (box.botleft () - row_spacing -
148  row->bounding_box ().topleft ());
149  box += row->bounding_box ();
150  }
151 
152  leftside.clear ();
153  icoordelt_it.set_to_list (&leftside);
154  icoordelt_it.add_to_end (new ICOORDELT (box.left (), box.bottom ()));
155  icoordelt_it.add_to_end (new ICOORDELT (box.left (), box.top ()));
156  rightside.clear ();
157  icoordelt_it.set_to_list (&rightside);
158  icoordelt_it.add_to_end (new ICOORDELT (box.right (), box.bottom ()));
159  icoordelt_it.add_to_end (new ICOORDELT (box.right (), box.top ()));
160 }
TBOX box
Definition: pdblock.h:114
void move(const ICOORD vec)
Definition: ocrrow.cpp:148
const ICOORD & botleft() const
Definition: rect.h:88
inT16 right() const
Definition: rect.h:75
Definition: ocrrow.h:32
ICOORD topleft() const
Definition: rect.h:96
ICOORDELT_LIST rightside
Definition: pdblock.h:113
ICOORDELT_LIST leftside
Definition: pdblock.h:112
inT16 left() const
Definition: rect.h:68
void move_bottom_edge(const inT16 y)
Definition: rect.h:133
TBOX bounding_box() const
Definition: ocrrow.h:85
#define ROW_SPACING
integer coordinate
Definition: points.h:30
inT16 bottom() const
Definition: rect.h:61
Definition: rect.h:30
void sort_rows()
decreasing y order
Definition: ocrblock.cpp:118
inT16 top() const
Definition: rect.h:54
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 182 of file ocrblock.cpp.

184  {
185  box.move (vec);
186  compress();
187 }
TBOX box
Definition: pdblock.h:114
void compress()
shrink white space
Definition: ocrblock.cpp:132
void move(const ICOORD vec)
Definition: rect.h:153
void BLOCK::compute_row_margins ( )

Definition at line 333 of file ocrblock.cpp.

333  {
334  if (row_list()->empty() || row_list()->singleton()) {
335  return;
336  }
337 
338  // If Layout analysis was not called, default to this.
339  POLY_BLOCK rect_block(bounding_box(), PT_FLOWING_TEXT);
340  POLY_BLOCK *pblock = &rect_block;
341  if (poly_block() != NULL) {
342  pblock = poly_block();
343  }
344 
345  // Step One: Determine if there is a drop-cap.
346  // TODO(eger): Fix up drop cap code for RTL languages.
347  ROW_IT r_it(row_list());
348  ROW *first_row = r_it.data();
349  ROW *second_row = r_it.data_relative(1);
350 
351  // initialize the bottom of a fictitious drop cap far above the first line.
352  int drop_cap_bottom = first_row->bounding_box().top() +
353  first_row->bounding_box().height();
354  int drop_cap_right = first_row->bounding_box().left();
355  int mid_second_line = second_row->bounding_box().top() -
356  second_row->bounding_box().height() / 2;
357  WERD_IT werd_it(r_it.data()->word_list()); // words of line one
358  if (!werd_it.empty()) {
359  C_BLOB_IT cblob_it(werd_it.data()->cblob_list());
360  for (cblob_it.mark_cycle_pt(); !cblob_it.cycled_list();
361  cblob_it.forward()) {
362  TBOX bbox = cblob_it.data()->bounding_box();
363  if (bbox.bottom() <= mid_second_line) {
364  // we found a real drop cap
365  first_row->set_has_drop_cap(true);
366  if (drop_cap_bottom > bbox.bottom())
367  drop_cap_bottom = bbox.bottom();
368  if (drop_cap_right < bbox.right())
369  drop_cap_right = bbox.right();
370  }
371  }
372  }
373 
374  // Step Two: Calculate the margin from the text of each row to the block
375  // (or drop-cap) boundaries.
376  PB_LINE_IT lines(pblock);
377  r_it.set_to_list(row_list());
378  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
379  ROW *row = r_it.data();
380  TBOX row_box = row->bounding_box();
381  int left_y = row->base_line(row_box.left()) + row->x_height();
382  int left_margin;
383  ICOORDELT_LIST *segments = lines.get_line(left_y);
384  LeftMargin(segments, row_box.left(), &left_margin);
385  delete segments;
386 
387  if (row_box.top() >= drop_cap_bottom) {
388  int drop_cap_distance = row_box.left() - row->space() - drop_cap_right;
389  if (drop_cap_distance < 0)
390  drop_cap_distance = 0;
391  if (drop_cap_distance < left_margin)
392  left_margin = drop_cap_distance;
393  }
394 
395  int right_y = row->base_line(row_box.right()) + row->x_height();
396  int right_margin;
397  segments = lines.get_line(right_y);
398  RightMargin(segments, row_box.right(), &right_margin);
399  delete segments;
400  row->set_lmargin(left_margin);
401  row->set_rmargin(right_margin);
402  }
403 }
void set_rmargin(inT16 rmargin)
Definition: ocrrow.h:95
inT32 space() const
Definition: ocrrow.h:76
void set_lmargin(inT16 lmargin)
Definition: ocrrow.h:92
void set_has_drop_cap(bool has)
Definition: ocrrow.h:105
bool RightMargin(ICOORDELT_LIST *segments, int x, int *margin)
Definition: ocrblock.cpp:285
float x_height() const
Definition: ocrrow.h:61
inT16 right() const
Definition: rect.h:75
bool LeftMargin(ICOORDELT_LIST *segments, int x, int *margin)
Definition: ocrblock.cpp:255
Definition: ocrrow.h:32
float base_line(float xpos) const
Definition: ocrrow.h:56
inT16 left() const
Definition: rect.h:68
TBOX bounding_box() const
Definition: ocrrow.h:85
inT16 bottom() const
Definition: rect.h:61
inT16 height() const
Definition: rect.h:104
Definition: rect.h:30
#define NULL
Definition: host.h:144
const TBOX & bounding_box() const
get real box
Definition: pdblock.h:73
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:120
inT16 top() const
Definition: rect.h:54
POLY_BLOCK * poly_block() const
Definition: pdblock.h:59
inT32 BLOCK::fixed_pitch ( ) const
inline

return pitch

Definition at line 90 of file ocrblock.h.

90  {
91  return pitch;
92  }
inT16 BLOCK::font ( ) const
inline

return font class

Definition at line 98 of file ocrblock.h.

98  {
99  return font_class;
100  }
inT16 BLOCK::kern ( ) const
inline

return kerning

Definition at line 94 of file ocrblock.h.

94  {
95  return kerning;
96  }
const ICOORD& BLOCK::median_size ( ) const
inline

Definition at line 156 of file ocrblock.h.

156  {
157  return median_size_;
158  }
const char* BLOCK::name ( ) const
inline

return filename

Definition at line 106 of file ocrblock.h.

106  {
107  return filename.string ();
108  }
const char * string() const
Definition: strngs.cpp:193
BLOCK & BLOCK::operator= ( const BLOCK source)

BLOCK::operator=

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

Definition at line 228 of file ocrblock.cpp.

230  {
231  this->ELIST_LINK::operator= (source);
232  this->PDBLK::operator= (source);
233  proportional = source.proportional;
234  kerning = source.kerning;
235  spacing = source.spacing;
236  filename = source.filename; //STRINGs assign ok
237  if (!rows.empty ())
238  rows.clear ();
239  re_rotation_ = source.re_rotation_;
240  classify_rotation_ = source.classify_rotation_;
241  skew_ = source.skew_;
242  return *this;
243 }
void operator=(const ELIST_LINK &)
Definition: elst.h:101
PDBLK & operator=(const PDBLK &source)
Definition: pdblock.cpp:238
PARA_LIST* BLOCK::para_list ( )
inline

Definition at line 128 of file ocrblock.h.

128  {
129  return &paras_;
130  }
void BLOCK::print ( FILE *  fp,
BOOL8  dump 
)

dump whole table

BLOCK::print

Print the info on a block

Definition at line 196 of file ocrblock.cpp.

199  {
200  ICOORDELT_IT it = &leftside; //iterator
201 
202  box.print ();
203  tprintf ("Proportional= %s\n", proportional ? "TRUE" : "FALSE");
204  tprintf ("Kerning= %d\n", kerning);
205  tprintf ("Spacing= %d\n", spacing);
206  tprintf ("Fixed_pitch=%d\n", pitch);
207  tprintf ("Filename= %s\n", filename.string ());
208 
209  if (dump) {
210  tprintf ("Left side coords are:\n");
211  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
212  tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
213  tprintf ("\n");
214  tprintf ("Right side coords are:\n");
215  it.set_to_list (&rightside);
216  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
217  tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
218  tprintf ("\n");
219  }
220 }
TBOX box
Definition: pdblock.h:114
#define tprintf(...)
Definition: tprintf.h:31
void print() const
Definition: rect.h:270
ICOORDELT_LIST rightside
Definition: pdblock.h:113
ICOORDELT_LIST leftside
Definition: pdblock.h:112
const char * string() const
Definition: strngs.cpp:193
BOOL8 BLOCK::prop ( ) const
inline

return proportional

Definition at line 80 of file ocrblock.h.

80  {
81  return proportional;
82  }
FCOORD BLOCK::re_rotation ( ) const
inline

Definition at line 138 of file ocrblock.h.

138  {
139  return re_rotation_; // How to transform coords back to image.
140  }
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 107 of file ocrblock.cpp.

107  {
109  box = *poly_block()->bounding_box();
110 }
TBOX box
Definition: pdblock.h:114
void reflect_in_y_axis()
Definition: polyblk.cpp:209
TBOX * bounding_box()
Definition: polyblk.h:38
POLY_BLOCK * poly_block() const
Definition: pdblock.h:59
C_BLOB_LIST* BLOCK::reject_blobs ( )
inline

Definition at line 135 of file ocrblock.h.

135  {
136  return &rej_blobs;
137  }
Pix* BLOCK::render_mask ( TBOX mask_box)
inline

Definition at line 164 of file ocrblock.h.

164  {
165  return PDBLK::render_mask(re_rotation_, mask_box);
166  }
Pix * render_mask(const FCOORD &rerotation, TBOX *mask_box)
Definition: pdblock.cpp:128
TBOX BLOCK::restricted_bounding_box ( bool  upper_dots,
bool  lower_dots 
) const

Definition at line 91 of file ocrblock.cpp.

91  {
92  TBOX box;
93  // This is a read-only iteration of the rows in the block.
94  ROW_IT it(const_cast<ROW_LIST*>(&rows));
95  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
96  box += it.data()->restricted_bounding_box(upper_dots, lower_dots);
97  }
98  return box;
99 }
TBOX box
Definition: pdblock.h:114
Definition: rect.h:30
bool BLOCK::right_to_left ( ) const
inline

Definition at line 83 of file ocrblock.h.

83  {
84  return right_to_left_;
85  }
void BLOCK::rotate ( const FCOORD rotation)

BLOCK::rotate

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

Definition at line 84 of file ocrblock.cpp.

84  {
85  poly_block()->rotate(rotation);
86  box = *poly_block()->bounding_box();
87 }
TBOX box
Definition: pdblock.h:114
void rotate(FCOORD rotation)
Definition: polyblk.cpp:185
TBOX * bounding_box()
Definition: polyblk.h:38
POLY_BLOCK * poly_block() const
Definition: pdblock.h:59
ROW_LIST* BLOCK::row_list ( )
inline

get rows

Definition at line 120 of file ocrblock.h.

120  {
121  return &rows;
122  }
void BLOCK::set_cell_over_xheight ( float  ratio)
inline

Definition at line 116 of file ocrblock.h.

116  {
117  cell_over_xheight_ = ratio;
118  }
void BLOCK::set_classify_rotation ( const FCOORD rotation)
inline

Definition at line 147 of file ocrblock.h.

147  {
148  classify_rotation_ = rotation;
149  }
void BLOCK::set_font_class ( inT16  font)
inline

set font class

Definition at line 76 of file ocrblock.h.

76  {
77  font_class = font;
78  }
inT16 font() const
return font class
Definition: ocrblock.h:98
void BLOCK::set_median_size ( int  x,
int  y 
)
inline

Definition at line 159 of file ocrblock.h.

159  {
160  median_size_.set_x(x);
161  median_size_.set_y(y);
162  }
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void BLOCK::set_re_rotation ( const FCOORD rotation)
inline

Definition at line 141 of file ocrblock.h.

141  {
142  re_rotation_ = rotation;
143  }
void BLOCK::set_right_to_left ( bool  value)
inline

Definition at line 86 of file ocrblock.h.

86  {
87  right_to_left_ = value;
88  }
void BLOCK::set_skew ( const FCOORD skew)
inline

Definition at line 153 of file ocrblock.h.

153  {
154  skew_ = skew;
155  }
FCOORD skew() const
Definition: ocrblock.h:150
void BLOCK::set_stats ( BOOL8  prop,
inT16  kern,
inT16  space,
inT16  ch_pitch 
)
inline

set space size etc.

Parameters
propproportional
kerninter char size
spaceinter word size
ch_pitchpitch if fixed

Definition at line 62 of file ocrblock.h.

65  {
66  proportional = prop;
67  kerning = (inT8) kern;
68  spacing = space;
69  pitch = ch_pitch;
70  }
inT16 kern() const
return kerning
Definition: ocrblock.h:94
SIGNED char inT8
Definition: host.h:98
inT16 space() const
return spacing
Definition: ocrblock.h:102
BOOL8 prop() const
return proportional
Definition: ocrblock.h:80
void BLOCK::set_xheight ( inT32  height)
inline

set char size

Definition at line 72 of file ocrblock.h.

72  {
73  xheight = height;
74  }
FCOORD BLOCK::skew ( ) const
inline

Definition at line 150 of file ocrblock.h.

150  {
151  return skew_; // Direction of true horizontal.
152  }
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 118 of file ocrblock.cpp.

118  { // order on "top"
119  ROW_IT row_it(&rows);
120 
121  row_it.sort (decreasing_top_order);
122 }
int decreasing_top_order(const void *row1, const void *row2)
Definition: ocrblock.cpp:71
inT16 BLOCK::space ( ) const
inline

return spacing

Definition at line 102 of file ocrblock.h.

102  {
103  return spacing;
104  }
inT32 BLOCK::x_height ( ) const
inline

return xheight

Definition at line 110 of file ocrblock.h.

110  {
111  return xheight;
112  }

Friends And Related Function Documentation

friend class BLOCK_RECT_IT
friend

Definition at line 33 of file ocrblock.h.


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