• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**********************************************************************
2  * File:			word.c
3  * Description: Code for the WERD class.
4  * Author:		Ray Smith
5  * Created:		Tue Oct 08 14:32:12 BST 1991
6  *
7  * (C) Copyright 1991, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #ifndef           WERD_H
21 #define           WERD_H
22 
23 #include          "varable.h"
24 #include          "bits16.h"
25 #include          "strngs.h"
26 #include          "blckerr.h"
27 #include          "stepblob.h"
28 #include          "polyblob.h"
29 //#include                                                      "larcblob.h"
30 
31 enum WERD_FLAGS
32 {
33   W_SEGMENTED,                   //correctly segmented
34   W_ITALIC,                      //italic text
35   W_BOLD,                        //bold text
36   W_BOL,                         //start of line
37   W_EOL,                         //end of line
38   W_NORMALIZED,                  //flags
39   W_POLYGON,                     //approximation
40   W_LINEARC,                     //linearc approx
41   W_DONT_CHOP,                   //fixed pitch chopped
42   W_REP_CHAR,                    //repeated character
43   W_FUZZY_SP,                    //fuzzy space
44   W_FUZZY_NON,                   //fuzzy nonspace
45   W_INVERSE                      //white on black
46 };
47 
48 enum DISPLAY_FLAGS
49 {
50   /* Display flags bit number allocations */
51   DF_BOX,                        //Bounding box
52   DF_TEXT,                       //Correct ascii
53   DF_POLYGONAL,                  //Polyg approx
54   DF_EDGE_STEP,                  //Edge steps
55   DF_BN_POLYGONAL                //BL normalisd polyapx
56 };
57 
58 class ROW;                       //forward decl
59 
60 class WERD:public ELIST_LINK
61 {
62   public:
WERD()63     WERD() {
64     }                            //empty constructor
65     WERD(                         //constructor
66          C_BLOB_LIST *blob_list,  //blobs in word
67          uinT8 blanks,            //blanks in front
68          const char *text);       //correct text
69     WERD(                        //constructor
70          PBLOB_LIST *blob_list,  //blobs in word
71          uinT8 blanks,           //blanks in front
72          const char *text);      //correct text
73     WERD(                        //constructor
74          PBLOB_LIST *blob_list,  //blobs in word
75          WERD *clone);           //use these flags etc.
76     WERD(                         //constructor
77          C_BLOB_LIST *blob_list,  //blobs in word
78          WERD *clone);            //use these flags etc.
~WERD()79     ~WERD () {                   //destructor
80       if (flags.bit (W_POLYGON)) {
81                                  //use right     destructor
82         ((PBLOB_LIST *) & cblobs)->clear ();
83                                  //use right     destructor
84         ((PBLOB_LIST *) & rej_cblobs)->clear ();
85       }
86       //              else if (flags.bit(W_LINEARC))
87       //                      ((LARC_BLOB_LIST*)&cblobs)->clear();                            //use right     destructor
88     }
89 
90     WERD *poly_copy(                 //make copy as poly
91                     float xheight);  //row xheight
92     WERD *larc_copy(                 //make copy as larc
93                     float xheight);  //row xheight
94 
95                                  //get DUFF compact blobs
rej_cblob_list()96     C_BLOB_LIST *rej_cblob_list() {
97       if (flags.bit (W_POLYGON))
98         WRONG_WORD.error ("WERD::rej_cblob_list", ABORT, NULL);
99       return &rej_cblobs;
100     }
101 
102                                  //get DUFF poly blobs
rej_blob_list()103     PBLOB_LIST *rej_blob_list() {
104       if (!flags.bit (W_POLYGON))
105         WRONG_WORD.error ("WERD::rej_blob_list", ABORT, NULL);
106       return (PBLOB_LIST *) (&rej_cblobs);
107     }
108 
cblob_list()109     C_BLOB_LIST *cblob_list() {  //get compact blobs
110       if (flags.bit (W_POLYGON) || flags.bit (W_LINEARC))
111         WRONG_WORD.error ("WERD::cblob_list", ABORT, NULL);
112       return &cblobs;
113     }
blob_list()114     PBLOB_LIST *blob_list() {  //get poly blobs
115       if (!flags.bit (W_POLYGON))
116         WRONG_WORD.error ("WERD::blob_list", ABORT, NULL);
117                                  //make it right type
118       return (PBLOB_LIST *) (&cblobs);
119     }
120     //      LARC_BLOB_LIST                          *larc_blob_list()                                       //get poly blobs
121     //      {
122     //              if (!flags.bit(W_LINEARC))
123     //                      WRONG_WORD.error("WERD::larc_blob_list",ABORT,NULL);
124     //              return (LARC_BLOB_LIST*)(&cblobs);                                              //make it right type
125     //      }
gblob_list()126     PBLOB_LIST *gblob_list() {  //get generic blobs
127                                  //make it right type
128       return (PBLOB_LIST *) (&cblobs);
129     }
130 
text()131     const char *text() const {  //correct text
132       return correct.string ();
133     }
space()134     uinT8 space() {  //access function
135       return blanks;
136     }
set_blanks(uinT8 new_blanks)137     void set_blanks(  //set blanks
138                     uinT8 new_blanks) {
139       blanks = new_blanks;
140     }
141 
set_text(const char * new_text)142     void set_text(                         //replace correct text
143                   const char *new_text) {  //with this
144       correct = new_text;
145     }
146 
147     TBOX bounding_box();  //compute bounding box
148 
flag(WERD_FLAGS mask)149     BOOL8 flag(                          //test flag
150                WERD_FLAGS mask) const {  //flag to test
151       return flags.bit (mask);
152     }
set_flag(WERD_FLAGS mask,BOOL8 value)153     void set_flag(                  //set flag value
154                   WERD_FLAGS mask,  //flag to test
155                   BOOL8 value) {    //value to set
156       flags.set_bit (mask, value);
157     }
158 
display_flag(uinT8 flag)159     BOOL8 display_flag(                     //test display flag
160                        uinT8 flag) const {  //flag to test
161       return disp_flags.bit (flag);
162     }
163 
set_display_flag(uinT8 flag,BOOL8 value)164     void set_display_flag(                //set display flag
165                           uinT8 flag,     //flag to set
166                           BOOL8 value) {  //value to set
167       disp_flags.set_bit (flag, value);
168     }
169 
170     WERD *shallow_copy();  //shallow copy word
171 
172     void move(                    // reposition word
173               const ICOORD vec);  // by vector
174 
175     void scale(                   // scale word
176                const float vec);  // by multiplier
177 
178     void join_on(                //append word
179                  WERD *&other);  //Deleting other
180 
181     void copy_on(                //copy blobs
182                  WERD *&other);  //from other
183 
184     void baseline_normalise (    // Tess style BL Norm
185                                  //optional antidote
186       ROW * row, DENORM * denorm = NULL);
187 
188     void baseline_normalise_x (  //Use non standard xht
189       ROW * row, float x_height, //Weird value to use
190       DENORM * denorm = NULL);   //optional antidote
191 
192     void baseline_denormalise(  //un-normalise
193                               const DENORM *denorm);
194 
195     void print(            //print
196                FILE *fp);  //file to print on
197 
198     void plot (                  //draw one
199       ScrollView* window,             //window to draw in
200                                  //uniform colour
201       ScrollView::Color colour, BOOL8 solid = FALSE);
202 
203     void plot (                  //draw one
204                                  //in rainbow colours
205       ScrollView* window, BOOL8 solid = FALSE);
206 
207     void plot_rej_blobs (        //draw one
208                                  //in rainbow colours
209       ScrollView* window, BOOL8 solid = FALSE);
210 
211     WERD & operator= (           //assign words
212       const WERD & source);      //from this
213 
prep_serialise()214     void prep_serialise() {  //set ptrs to counts
215       correct.prep_serialise ();
216       if (flags.bit (W_POLYGON))
217         ((PBLOB_LIST *) (&cblobs))->prep_serialise ();
218       //              else if (flags.bit(W_LINEARC))
219       //                      ((LARC_BLOB_LIST*)(&cblobs))->prep_serialise();
220       else
221         cblobs.prep_serialise ();
222       rej_cblobs.prep_serialise ();
223     }
224 
dump(FILE * f)225     void dump(  //write external bits
226               FILE *f) {
227       correct.dump (f);
228       if (flags.bit (W_POLYGON))
229         ((PBLOB_LIST *) (&cblobs))->dump (f);
230       //              else if (flags.bit(W_LINEARC))
231       //                      ((LARC_BLOB_LIST*)(&cblobs))->dump( f );
232       else
233         cblobs.dump (f);
234       rej_cblobs.dump (f);
235     }
236 
de_dump(FILE * f)237     void de_dump(  //read external bits
238                  FILE *f) {
239       correct.de_dump (f);
240       if (flags.bit (W_POLYGON))
241         ((PBLOB_LIST *) (&cblobs))->de_dump (f);
242       //              else if (flags.bit(W_LINEARC))
243       //                      ((LARC_BLOB_LIST*)(&cblobs))->de_dump( f );
244       else
245         cblobs.de_dump (f);
246       rej_cblobs.de_dump (f);
247     }
248 
249     make_serialise (WERD) private:
250     uinT8 blanks;                //no of blanks
251     uinT8 dummy;                 //padding
252     BITS16 flags;                //flags about word
253     BITS16 disp_flags;           //display flags
254     inT16 dummy2;                //padding
255     STRING correct;              //correct text
256     C_BLOB_LIST cblobs;          //compacted blobs
257     C_BLOB_LIST rej_cblobs;      //DUFF blobs
258 };
259 
260 ELISTIZEH_S (WERD)
261 #include          "ocrrow.h"     //placed here due to
262 extern BOOL_VAR_H (bln_numericmode, 0, "Optimize for numbers");
263 extern INT_VAR_H (bln_x_height, 128, "Baseline Normalisation X-height");
264 extern INT_VAR_H (bln_baseline_offset, 64,
265 "Baseline Norm. offset of baseline");
266 //void                                                          poly_linearc_outlines(                  //do list of outlines
267 //LARC_OUTLINE_LIST                             *srclist,                                                       //list to convert
268 //OUTLINE_LIST                                  *destlist                                                       //desstination list
269 //);
270 //OUTLINE                                                       *poly_larcline(                                 //draw it
271 //LARC_OUTLINE                                  *srcline                                                                //one to approximate
272 //);
273 int word_comparator(                     //sort blobs
274                     const void *word1p,  //ptr to ptr to word1
275                     const void *word2p   //ptr to ptr to word2
276                    );
277 #endif
278