2007-03-08 04:03:40 +08:00
|
|
|
/**********************************************************************
|
|
|
|
* File: werdit.cpp (Formerly wordit.c)
|
|
|
|
* Description: An iterator for passing over all the words in a document.
|
|
|
|
* Author: Ray Smith
|
|
|
|
* Created: Mon Apr 27 08:51:22 BST 1992
|
|
|
|
*
|
|
|
|
* (C) Copyright 1992, Hewlett-Packard Ltd.
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
#include "werdit.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* make_pseudo_word
|
|
|
|
*
|
|
|
|
* Make all the blobs inside a selection into a single word.
|
|
|
|
* The word is always a copy and needs to be deleted.
|
|
|
|
**********************************************************************/
|
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
WERD *make_pseudo_word(PAGE_RES* page_res, // Blocks to check.
|
2013-09-23 23:26:50 +08:00
|
|
|
const TBOX &selection_box,
|
2007-03-08 04:03:40 +08:00
|
|
|
BLOCK *&pseudo_block,
|
2010-11-24 02:34:14 +08:00
|
|
|
ROW *&pseudo_row) { // Row of selection.
|
|
|
|
PAGE_RES_IT pr_it(page_res);
|
|
|
|
C_BLOB_LIST new_blobs; // list of gathered blobs
|
|
|
|
C_BLOB_IT new_blob_it = &new_blobs; // iterator
|
|
|
|
WERD *pseudo_word; // fabricated word
|
|
|
|
|
|
|
|
for (WERD_RES* word_res = pr_it.word(); word_res != NULL;
|
|
|
|
word_res = pr_it.forward()) {
|
|
|
|
WERD* word = word_res->word;
|
|
|
|
if (word->bounding_box().overlap(selection_box)) {
|
|
|
|
C_BLOB_IT blob_it(word->cblob_list());
|
|
|
|
for (blob_it.mark_cycle_pt();
|
|
|
|
!blob_it.cycled_list(); blob_it.forward()) {
|
|
|
|
C_BLOB* blob = blob_it.data();
|
|
|
|
if (blob->bounding_box().overlap(selection_box)) {
|
|
|
|
new_blob_it.add_after_then_move(C_BLOB::deep_copy(blob));
|
|
|
|
pseudo_row = pr_it.row()->row;
|
|
|
|
pseudo_block = pr_it.block()->block;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-24 02:34:14 +08:00
|
|
|
if (!new_blobs.empty())
|
|
|
|
pseudo_word = new WERD(&new_blobs, 1, NULL);
|
2007-03-08 04:03:40 +08:00
|
|
|
else
|
|
|
|
pseudo_word = NULL;
|
|
|
|
return pseudo_word;
|
|
|
|
}
|