|
tesseract 3.04.01
|
00001 /********************************************************************** 00002 * File: werdit.cpp (Formerly wordit.c) 00003 * Description: An iterator for passing over all the words in a document. 00004 * Author: Ray Smith 00005 * Created: Mon Apr 27 08:51:22 BST 1992 00006 * 00007 * (C) Copyright 1992, Hewlett-Packard Ltd. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #include "werdit.h" 00021 00022 /********************************************************************** 00023 * make_pseudo_word 00024 * 00025 * Make all the blobs inside a selection into a single word. 00026 * The returned PAGE_RES_IT* it points to the new word. After use, call 00027 * it->DeleteCurrentWord() to delete the fake word, and then 00028 * delete it to get rid of the iterator itself. 00029 **********************************************************************/ 00030 00031 PAGE_RES_IT* make_pseudo_word(PAGE_RES* page_res, const TBOX& selection_box) { 00032 PAGE_RES_IT pr_it(page_res); 00033 C_BLOB_LIST new_blobs; // list of gathered blobs 00034 C_BLOB_IT new_blob_it = &new_blobs; // iterator 00035 00036 for (WERD_RES* word_res = pr_it.word(); word_res != NULL; 00037 word_res = pr_it.forward()) { 00038 WERD* word = word_res->word; 00039 if (word->bounding_box().overlap(selection_box)) { 00040 C_BLOB_IT blob_it(word->cblob_list()); 00041 for (blob_it.mark_cycle_pt(); 00042 !blob_it.cycled_list(); blob_it.forward()) { 00043 C_BLOB* blob = blob_it.data(); 00044 if (blob->bounding_box().overlap(selection_box)) { 00045 new_blob_it.add_after_then_move(C_BLOB::deep_copy(blob)); 00046 } 00047 } 00048 if (!new_blobs.empty()) { 00049 WERD* pseudo_word = new WERD(&new_blobs, 1, NULL); 00050 word_res = pr_it.InsertSimpleCloneWord(*word_res, pseudo_word); 00051 PAGE_RES_IT* it = new PAGE_RES_IT(page_res); 00052 while (it->word() != word_res && it->word() != NULL) it->forward(); 00053 ASSERT_HOST(it->word() == word_res); 00054 return it; 00055 } 00056 } 00057 } 00058 return NULL; 00059 }