Tesseract 3.01
|
00001 /********************************************************************** 00002 * File: word.c 00003 * Description: Code for the WERD class. 00004 * Author: Ray Smith 00005 * Created: Tue Oct 08 14:32:12 BST 1991 00006 * 00007 * (C) Copyright 1991, 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 #ifndef WERD_H 00021 #define WERD_H 00022 00023 #include "params.h" 00024 #include "bits16.h" 00025 #include "elst2.h" 00026 #include "strngs.h" 00027 #include "blckerr.h" 00028 #include "stepblob.h" 00029 00030 enum WERD_FLAGS 00031 { 00032 W_SEGMENTED, //< correctly segmented 00033 W_ITALIC, //< italic text 00034 W_BOLD, //< bold text 00035 W_BOL, //< start of line 00036 W_EOL, //< end of line 00037 W_NORMALIZED, //< flags 00038 W_SCRIPT_HAS_XHEIGHT, //< x-height concept makes sense. 00039 W_SCRIPT_IS_LATIN, //< Special case latin for y. splitting. 00040 W_DONT_CHOP, //< fixed pitch chopped 00041 W_REP_CHAR, //< repeated character 00042 W_FUZZY_SP, //< fuzzy space 00043 W_FUZZY_NON, //< fuzzy nonspace 00044 W_INVERSE //< white on black 00045 }; 00046 00047 enum DISPLAY_FLAGS 00048 { 00049 /* Display flags bit number allocations */ 00050 DF_BOX, //< Bounding box 00051 DF_TEXT, //< Correct ascii 00052 DF_POLYGONAL, //< Polyg approx 00053 DF_EDGE_STEP, //< Edge steps 00054 DF_BN_POLYGONAL //< BL normalisd polyapx 00055 }; 00056 00057 class ROW; //forward decl 00058 00059 class WERD : public ELIST2_LINK { 00060 public: 00061 WERD() {} 00062 // WERD constructed with: 00063 // blob_list - blobs of the word (we take this list's contents) 00064 // blanks - number of blanks before the word 00065 // text - correct text (outlives WERD) 00066 WERD(C_BLOB_LIST *blob_list, uinT8 blanks, const char *text); 00067 00068 // WERD constructed from: 00069 // blob_list - blobs in the word 00070 // clone - werd to clone flags, etc from. 00071 WERD(C_BLOB_LIST *blob_list, WERD *clone); 00072 00073 // Construct a WERD from a single_blob and clone the flags from this. 00074 // W_BOL and W_EOL flags are set according to the given values. 00075 WERD* ConstructFromSingleBlob(bool bol, bool eol, C_BLOB* blob); 00076 00077 ~WERD() { 00078 } 00079 00080 // assignment 00081 WERD & operator= (const WERD &source); 00082 00083 // This method returns a new werd constructed using the blobs in the input 00084 // all_blobs list, which correspond to the blobs in this werd object. The 00085 // blobs used to construct the new word are consumed and removed from the 00086 // input all_blobs list. 00087 // Returns NULL if the word couldn't be constructed. 00088 // Returns original blobs for which no matches were found in the output list 00089 // orphan_blobs (appends). 00090 WERD *ConstructWerdWithNewBlobs(C_BLOB_LIST *all_blobs, 00091 C_BLOB_LIST *orphan_blobs); 00092 00093 // Accessors for reject / DUFF blobs in various formats 00094 C_BLOB_LIST *rej_cblob_list() { // compact format 00095 return &rej_cblobs; 00096 } 00097 00098 // Accessors for good blobs in various formats. 00099 C_BLOB_LIST *cblob_list() { // get compact blobs 00100 return &cblobs; 00101 } 00102 00103 uinT8 space() { // access function 00104 return blanks; 00105 } 00106 void set_blanks(uinT8 new_blanks) { 00107 blanks = new_blanks; 00108 } 00109 int script_id() const { 00110 return script_id_; 00111 } 00112 void set_script_id(int id) { 00113 script_id_ = id; 00114 } 00115 00116 TBOX bounding_box(); // compute bounding box 00117 00118 const char *text() const { return correct.string(); } 00119 void set_text(const char *new_text) { correct = new_text; } 00120 00121 BOOL8 flag(WERD_FLAGS mask) const { return flags.bit(mask); } 00122 void set_flag(WERD_FLAGS mask, BOOL8 value) { flags.set_bit(mask, value); } 00123 00124 BOOL8 display_flag(uinT8 flag) const { return disp_flags.bit(flag); } 00125 void set_display_flag(uinT8 flag, BOOL8 value) { 00126 disp_flags.set_bit(flag, value); 00127 } 00128 00129 WERD *shallow_copy(); // shallow copy word 00130 00131 // reposition word by vector 00132 void move(const ICOORD vec); 00133 00134 // join other's blobs onto this werd, emptying out other. 00135 void join_on(WERD* other); 00136 00137 // copy other's blobs onto this word, leaving other intact. 00138 void copy_on(WERD* other); 00139 00140 // tprintf word metadata (but not blob innards) 00141 void print(); 00142 00143 // plot word on window in a uniform colour 00144 void plot(ScrollView *window, ScrollView::Color colour); 00145 00146 // Get the next color in the (looping) rainbow. 00147 static ScrollView::Color NextColor(ScrollView::Color colour); 00148 00149 // plot word on window in a rainbow of colours 00150 void plot(ScrollView *window); 00151 00152 // plot rejected blobs in a rainbow of colours 00153 void plot_rej_blobs(ScrollView *window); 00154 00155 private: 00156 uinT8 blanks; // no of blanks 00157 uinT8 dummy; // padding 00158 BITS16 flags; // flags about word 00159 BITS16 disp_flags; // display flags 00160 inT16 script_id_; // From unicharset. 00161 STRING correct; // correct text 00162 C_BLOB_LIST cblobs; // compacted blobs 00163 C_BLOB_LIST rej_cblobs; // DUFF blobs 00164 }; 00165 00166 ELIST2IZEH (WERD) 00167 #include "ocrrow.h" // placed here due to 00168 // compare words by increasing order of left edge, suitable for qsort(3) 00169 int word_comparator(const void *word1p, const void *word2p); 00170 #endif