Example #1
0
WERD *make_real_word(BLOBNBOX_IT *box_it,  //iterator
                     inT32 blobcount,      //no of blobs to use
                     BOOL8 bol,            //start of line
                     uinT8 blanks          //no of blanks
                    ) {
  OUTLINE_IT out_it;             // outlines
  C_OUTLINE_IT cout_it;
  PBLOB_LIST blobs;              // blobs in word
  C_BLOB_LIST cblobs;
  PBLOB_IT blob_it = &blobs;     // iterator
  C_BLOB_IT cblob_it = &cblobs;
  WERD *word;                    // new word
  BLOBNBOX *bblob;               // current blob
  inT32 blobindex;               // in row

  for (blobindex = 0; blobindex < blobcount; blobindex++) {
    bblob = box_it->extract();
    if (bblob->joined_to_prev()) {
      if (bblob->blob() != NULL) {
        out_it.set_to_list(blob_it.data()->out_list());
        out_it.move_to_last();
        out_it.add_list_after(bblob->blob()->out_list());
        delete bblob->blob();
      }
      else if (bblob->cblob() != NULL) {
        cout_it.set_to_list(cblob_it.data()->out_list());
        cout_it.move_to_last();
        cout_it.add_list_after(bblob->cblob()->out_list());
        delete bblob->cblob();
      }
    }
    else {
      if (bblob->blob() != NULL)
        blob_it.add_after_then_move(bblob->blob());
      else if (bblob->cblob() != NULL)
        cblob_it.add_after_then_move(bblob->cblob());
    }
    delete bblob;
    box_it->forward();          // next one
  }

  if (blanks < 1)
    blanks = 1;

  if (blob_it.empty())
    word = new WERD(&cblobs, blanks, NULL);
  else
    word = new WERD(&blobs, blanks, NULL);

  if (bol)
    word->set_flag(W_BOL, TRUE);
  if (box_it->at_first())
    word->set_flag(W_EOL, TRUE);  // at end of line

  return word;
}
Example #2
0
static void clear_blobnboxes(BLOBNBOX_LIST* boxes) {
  BLOBNBOX_IT it = boxes;
  // A BLOBNBOX generally doesn't own its blobs, so if they do, you
  // have to delete them explicitly.
  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
    BLOBNBOX* box = it.data();
    if (box->blob() != NULL)
      delete box->blob();
    if (box->cblob() != NULL)
      delete box->cblob();
  }
}
Example #3
0
BOX box_next(                 //get bounding box
             BLOBNBOX_IT *it  //iterator to blobds
            ) {
  BLOBNBOX *blob;                //current blob
  BOX result;                    //total box

  blob = it->data ();
  result = blob->bounding_box ();
  do {
    it->forward ();
    blob = it->data ();
    if (blob->blob () == NULL && blob->cblob () == NULL)
                                 //was pre-chopped
      result += blob->bounding_box ();
  }
                                 //until next real blob
  while (blob->blob () == NULL && blob->cblob () == NULL || blob->joined_to_prev ());
  return result;
}
Example #4
0
void TO_ROW::compute_vertical_projection() {  //project whole row
  BOX row_box;                   //bound of row
  BLOBNBOX *blob;                //current blob
  BOX blob_box;                  //bounding box
  BLOBNBOX_IT blob_it = blob_list ();

  if (blob_it.empty ())
    return;
  row_box = blob_it.data ()->bounding_box ();
  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ())
    row_box += blob_it.data ()->bounding_box ();

  projection.set_range (row_box.left () - PROJECTION_MARGIN,
    row_box.right () + PROJECTION_MARGIN);
  projection_left = row_box.left () - PROJECTION_MARGIN;
  projection_right = row_box.right () + PROJECTION_MARGIN;
  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
    blob = blob_it.data ();
    if (blob->blob () != NULL)
      vertical_blob_projection (blob->blob (), &projection);
    else if (blob->cblob () != NULL)
      vertical_cblob_projection (blob->cblob (), &projection);
  }
}