26 #define BLOCK_LABEL_HEIGHT 150 //char height of block id 39 int16_t ymin, int16_t xmax,
41 : pdblk(xmin, ymin, xmax, ymax),
43 re_rotation_(1.0f, 0.0f),
44 classify_rotation_(1.0f, 0.0f),
46 ICOORDELT_IT left_it = &pdblk.leftside;
47 ICOORDELT_IT right_it = &pdblk.rightside;
50 right_to_left_ =
false;
54 cell_over_xheight_ = 2.0f;
55 pdblk.hand_poly =
nullptr;
56 left_it.set_to_list (&pdblk.leftside);
57 right_it.set_to_list (&pdblk.rightside);
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));
71 static int decreasing_top_order(
const void *row1,
const void *row2) {
72 return (*reinterpret_cast<ROW* const*>(row2))->bounding_box().top() -
73 (*
reinterpret_cast<ROW* const*
>(row1))->bounding_box().top();
92 ROW_IT it(const_cast<ROW_LIST*>(&rows));
93 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
94 box += it.data()->restricted_bounding_box(upper_dots, lower_dots);
117 ROW_IT row_it(&rows);
119 row_it.sort (decreasing_top_order);
131 #define ROW_SPACING 5 133 ROW_IT row_it(&rows);
137 ICOORDELT_IT icoordelt_it;
143 for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
144 row = row_it.data ();
201 tprintf (
"Proportional= %s\n", proportional ?
"TRUE" :
"FALSE");
202 tprintf (
"Kerning= %d\n", kerning);
203 tprintf (
"Spacing= %d\n", spacing);
204 tprintf (
"Fixed_pitch=%d\n", pitch);
208 tprintf (
"Left side coords are:\n");
209 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
210 tprintf (
"(%d,%d) ", it.data ()->x (), it.data ()->y ());
212 tprintf (
"Right side coords are:\n");
214 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
215 tprintf (
"(%d,%d) ", it.data ()->x (), it.data ()->y ());
231 proportional = source.proportional;
232 kerning = source.kerning;
233 spacing = source.spacing;
234 filename = source.filename;
237 re_rotation_ = source.re_rotation_;
238 classify_rotation_ = source.classify_rotation_;
239 skew_ = source.skew_;
253 static bool LeftMargin(ICOORDELT_LIST *segments,
int x,
int *margin) {
256 if (segments->empty())
258 ICOORDELT_IT seg_it(segments);
259 for (seg_it.mark_cycle_pt(); !seg_it.cycled_list(); seg_it.forward()) {
260 int cur_margin = x - seg_it.data()->x();
261 if (cur_margin >= 0) {
263 *margin = cur_margin;
264 }
else if (cur_margin < *margin) {
265 *margin = cur_margin;
283 static bool RightMargin(ICOORDELT_LIST *segments,
int x,
int *margin) {
286 if (segments->empty())
288 ICOORDELT_IT seg_it(segments);
289 for (seg_it.mark_cycle_pt(); !seg_it.cycled_list(); seg_it.forward()) {
290 int cur_margin = seg_it.data()->x() + seg_it.data()->y() - x;
291 if (cur_margin >= 0) {
293 *margin = cur_margin;
294 }
else if (cur_margin < *margin) {
295 *margin = cur_margin;
346 ROW *first_row = r_it.data();
347 ROW *second_row = r_it.data_relative(1);
355 WERD_IT werd_it(r_it.data()->word_list());
356 if (!werd_it.empty()) {
357 C_BLOB_IT cblob_it(werd_it.data()->cblob_list());
358 for (cblob_it.mark_cycle_pt(); !cblob_it.cycled_list();
359 cblob_it.forward()) {
360 TBOX bbox = cblob_it.data()->bounding_box();
361 if (bbox.
bottom() <= mid_second_line) {
364 if (drop_cap_bottom > bbox.
bottom())
365 drop_cap_bottom = bbox.
bottom();
366 if (drop_cap_right < bbox.
right())
367 drop_cap_right = bbox.
right();
376 for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
377 ROW *row = r_it.data();
381 const std::unique_ptr< ICOORDELT_LIST> segments_left(
383 LeftMargin(segments_left.get(), row_box.
left(), &left_margin);
385 if (row_box.
top() >= drop_cap_bottom) {
386 int drop_cap_distance = row_box.
left() - row->
space() - drop_cap_right;
387 if (drop_cap_distance < 0)
388 drop_cap_distance = 0;
389 if (drop_cap_distance < left_margin)
390 left_margin = drop_cap_distance;
395 const std::unique_ptr< ICOORDELT_LIST> segments_right(
397 RightMargin(segments_right.get(), row_box.
right(), &right_margin);
414 BLOCK_IT block_it(block_list);
415 for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
416 BLOCK* block = block_it.data();
419 for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
421 ROW* row = row_it.data();
424 for (werd_it.mark_cycle_pt(); !werd_it.cycled_list(); werd_it.forward()) {
425 WERD* werd = werd_it.data();
431 tprintf(
"Block list stats:\nBlocks = %d\nRows = %d\nWords = %d\nBlobs = %d\n",
432 num_blocks, num_rows, num_words, num_blobs);
443 C_BLOB_LIST* output_blob_list) {
444 C_BLOB_IT return_list_it(output_blob_list);
445 BLOCK_IT block_it(blocks);
446 for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
447 BLOCK* block = block_it.data();
449 for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
450 ROW* row = row_it.data();
453 for (werd_it.mark_cycle_pt(); !werd_it.cycled_list(); werd_it.forward()) {
454 WERD* werd = werd_it.data();
455 return_list_it.move_to_last();
456 return_list_it.add_list_after(werd->
cblob_list());
457 return_list_it.move_to_last();
478 C_BLOB_LIST* new_blobs,
479 C_BLOB_LIST* not_found_blobs) {
482 BLOCK_IT block_it(block_list);
483 for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
484 BLOCK* block = block_it.data();
489 for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
490 ROW* row = row_it.data();
494 WERD_IT new_words_it(&new_words);
495 for (werd_it.mark_cycle_pt(); !werd_it.cycled_list(); werd_it.forward()) {
496 WERD* werd = werd_it.extract();
502 new_words_it.add_after_then_move(new_werd);
508 new_words_it.add_after_then_move(werd);
513 werd_it.move_to_first();
514 werd_it.add_list_after(&new_words);
void compute_row_margins()
void set_has_drop_cap(bool has)
void reflect_polygon_in_y_axis()
void move(const ICOORD vec)
void RefreshWordBlobsFromNewBlobs(BLOCK_LIST *block_list, C_BLOB_LIST *new_blobs, C_BLOB_LIST *not_found_blobs)
const char * string() const
float base_line(float xpos) const
ROW_LIST * row_list()
get rows
void rotate(FCOORD rotation)
void move(const ICOORD vec)
C_BLOB_LIST * rej_cblob_list()
void move_bottom_edge(const int16_t y)
void set_rmargin(int16_t rmargin)
void set_lmargin(int16_t lmargin)
void print(FILE *fp, bool dump)
dump whole table
TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const
ICOORDELT_LIST * get_line(int16_t y)
void operator=(const ELIST_LINK &)
BLOCK & operator=(const BLOCK &source)
void ExtractBlobsFromSegmentation(BLOCK_LIST *blocks, C_BLOB_LIST *output_blob_list)
POLY_BLOCK * poly_block() const
#define ELISTIZE(CLASSNAME)
TBOX bounding_box() const
DLLSYM void tprintf(const char *format,...)
C_BLOB_LIST * cblob_list()
void PrintSegmentationStats(BLOCK_LIST *block_list)
const ICOORD & botleft() const
void sort_rows()
decreasing y order
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
void check_pitch()
check proportional
WERD * ConstructWerdWithNewBlobs(C_BLOB_LIST *all_blobs, C_BLOB_LIST *orphan_blobs)
void compress()
shrink white space
void rotate(const FCOORD &rotation)