tesseract
3.03
|
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 word is always a copy and needs to be deleted. 00027 **********************************************************************/ 00028 00029 WERD *make_pseudo_word(PAGE_RES* page_res, // Blocks to check. 00030 const TBOX &selection_box, 00031 BLOCK *&pseudo_block, 00032 ROW *&pseudo_row) { // Row of selection. 00033 PAGE_RES_IT pr_it(page_res); 00034 C_BLOB_LIST new_blobs; // list of gathered blobs 00035 C_BLOB_IT new_blob_it = &new_blobs; // iterator 00036 WERD *pseudo_word; // fabricated word 00037 00038 for (WERD_RES* word_res = pr_it.word(); word_res != NULL; 00039 word_res = pr_it.forward()) { 00040 WERD* word = word_res->word; 00041 if (word->bounding_box().overlap(selection_box)) { 00042 C_BLOB_IT blob_it(word->cblob_list()); 00043 for (blob_it.mark_cycle_pt(); 00044 !blob_it.cycled_list(); blob_it.forward()) { 00045 C_BLOB* blob = blob_it.data(); 00046 if (blob->bounding_box().overlap(selection_box)) { 00047 new_blob_it.add_after_then_move(C_BLOB::deep_copy(blob)); 00048 pseudo_row = pr_it.row()->row; 00049 pseudo_block = pr_it.block()->block; 00050 } 00051 } 00052 } 00053 } 00054 if (!new_blobs.empty()) 00055 pseudo_word = new WERD(&new_blobs, 1, NULL); 00056 else 00057 pseudo_word = NULL; 00058 return pseudo_word; 00059 }