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