2
2
* File: werd.cpp (Formerly word.c)
3
3
* Description: Code for the WERD class.
4
4
* Author: Ray Smith
5
- * Created: Tue Oct 08 14:32:12 BST 1991
6
5
*
7
6
* (C) Copyright 1991, Hewlett-Packard Ltd.
8
7
** Licensed under the Apache License, Version 2.0 (the "License");
17
16
*
18
17
**********************************************************************/
19
18
19
+ #include " werd.h"
20
20
#include " helpers.h"
21
21
#include " linlsq.h"
22
- #include " werd.h"
23
22
24
23
// Include automatically generated configuration file if running autoconf.
25
24
#ifdef HAVE_CONFIG_H
26
- #include " config_auto.h"
25
+ # include " config_auto.h"
27
26
#endif
28
27
29
- #define FIRST_COLOUR ScrollView::RED // /< first rainbow colour
30
- #define LAST_COLOUR ScrollView::AQUAMARINE // /< last rainbow colour
31
- #define CHILD_COLOUR ScrollView::BROWN // /< colour of children
28
+ #define FIRST_COLOUR ScrollView::RED // /< first rainbow colour
29
+ #define LAST_COLOUR ScrollView::AQUAMARINE // /< last rainbow colour
30
+ #define CHILD_COLOUR ScrollView::BROWN // /< colour of children
32
31
33
32
const ERRCODE CANT_SCALE_EDGESTEPS =
34
33
" Attempted to scale an edgestep format word" ;
@@ -44,11 +43,8 @@ ELIST2IZE(WERD)
44
43
* blank_count blanks in front of the word
45
44
* text correct text, outlives this WERD
46
45
*/
47
- WERD::WERD(C_BLOB_LIST *blob_list, uint8_t blank_count, const char *text)
48
- : blanks(blank_count),
49
- flags(0 ),
50
- script_id_(0 ),
51
- correct(text) {
46
+ WERD::WERD(C_BLOB_LIST* blob_list, uint8_t blank_count, const char * text)
47
+ : blanks(blank_count), flags(0 ), script_id_(0 ), correct(text) {
52
48
C_BLOB_IT start_it = &cblobs;
53
49
C_BLOB_IT rej_cblob_it = &rej_cblobs;
54
50
C_OUTLINE_IT c_outline_it;
@@ -72,17 +68,15 @@ WERD::WERD(C_BLOB_LIST *blob_list, uint8_t blank_count, const char *text)
72
68
with the concencus onto the reject list.
73
69
*/
74
70
start_it.set_to_list (&cblobs);
75
- if (start_it.empty ())
76
- return ;
71
+ if (start_it.empty ()) return ;
77
72
for (start_it.mark_cycle_pt (); !start_it.cycled_list (); start_it.forward ()) {
78
73
bool reject_blob = false ;
79
74
bool blob_inverted;
80
75
81
76
c_outline_it.set_to_list (start_it.data ()->out_list ());
82
77
blob_inverted = c_outline_it.data ()->flag (COUT_INVERSE);
83
78
for (c_outline_it.mark_cycle_pt ();
84
- !c_outline_it.cycled_list () && !reject_blob;
85
- c_outline_it.forward ()) {
79
+ !c_outline_it.cycled_list () && !reject_blob; c_outline_it.forward ()) {
86
80
reject_blob = c_outline_it.data ()->flag (COUT_INVERSE) != blob_inverted;
87
81
}
88
82
if (reject_blob) {
@@ -98,35 +92,33 @@ WERD::WERD(C_BLOB_LIST *blob_list, uint8_t blank_count, const char *text)
98
92
flags.set_bit (W_INVERSE, (inverted_vote > non_inverted_vote));
99
93
100
94
start_it.set_to_list (&cblobs);
101
- if (start_it.empty ())
102
- return ;
95
+ if (start_it.empty ()) return ;
103
96
for (start_it.mark_cycle_pt (); !start_it.cycled_list (); start_it.forward ()) {
104
97
c_outline_it.set_to_list (start_it.data ()->out_list ());
105
98
if (c_outline_it.data ()->flag (COUT_INVERSE) != flags.bit (W_INVERSE))
106
99
rej_cblob_it.add_after_then_move (start_it.extract ());
107
100
}
108
101
}
109
102
110
-
111
103
/* *
112
104
* WERD::WERD
113
105
*
114
106
* Constructor to build a WERD from a list of C_BLOBs.
115
107
* The C_BLOBs are not copied so the source list is emptied.
116
108
*/
117
109
118
- WERD::WERD (C_BLOB_LIST * blob_list, // /< In word order
119
- WERD * clone) // /< Source of flags
120
- : flags(clone->flags),
121
- script_id_(clone->script_id_),
122
- correct(clone->correct) {
110
+ WERD::WERD (C_BLOB_LIST* blob_list, // /< In word order
111
+ WERD* clone) // /< Source of flags
112
+ : flags(clone->flags),
113
+ script_id_(clone->script_id_),
114
+ correct(clone->correct) {
123
115
C_BLOB_IT start_it = blob_list; // iterator
124
116
C_BLOB_IT end_it = blob_list; // another
125
117
126
- while (!end_it.at_last ())
127
- end_it. forward (); // move to last
128
- ( reinterpret_cast <C_BLOB_LIST*>(&cblobs)) ->assign_to_sublist (&start_it, &end_it);
129
- // move to our list
118
+ while (!end_it.at_last ()) end_it. forward (); // move to last
119
+ ( reinterpret_cast <C_BLOB_LIST*>(&cblobs))
120
+ ->assign_to_sublist (&start_it, &end_it);
121
+ // move to our list
130
122
blanks = clone->blanks ;
131
123
// fprintf(stderr,"Wrong constructor!!!!\n");
132
124
}
@@ -223,7 +215,6 @@ void WERD::join_on(WERD* other) {
223
215
}
224
216
}
225
217
226
-
227
218
/* *
228
219
* WERD::copy_on
229
220
*
@@ -285,15 +276,14 @@ void WERD::print() {
285
276
tprintf (" Script = %d\n " , script_id_);
286
277
}
287
278
288
-
289
279
/* *
290
280
* WERD::plot
291
281
*
292
282
* Draw the WERD in the given colour.
293
283
*/
294
284
295
285
#ifndef GRAPHICS_DISABLED
296
- void WERD::plot (ScrollView * window, ScrollView::Color colour) {
286
+ void WERD::plot (ScrollView* window, ScrollView::Color colour) {
297
287
C_BLOB_IT it = &cblobs;
298
288
for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
299
289
it.data ()->plot (window, colour, colour);
@@ -304,8 +294,7 @@ void WERD::plot(ScrollView *window, ScrollView::Color colour) {
304
294
// Get the next color in the (looping) rainbow.
305
295
ScrollView::Color WERD::NextColor (ScrollView::Color colour) {
306
296
ScrollView::Color next = static_cast <ScrollView::Color>(colour + 1 );
307
- if (next >= LAST_COLOUR || next < FIRST_COLOUR)
308
- next = FIRST_COLOUR;
297
+ if (next >= LAST_COLOUR || next < FIRST_COLOUR) next = FIRST_COLOUR;
309
298
return next;
310
299
}
311
300
@@ -325,31 +314,28 @@ void WERD::plot(ScrollView* window) {
325
314
plot_rej_blobs (window);
326
315
}
327
316
328
-
329
317
/* *
330
318
* WERD::plot_rej_blobs
331
319
*
332
320
* Draw the WERD rejected blobs in window - ALWAYS GREY
333
321
*/
334
322
335
-
336
- void WERD::plot_rej_blobs (ScrollView *window) {
323
+ void WERD::plot_rej_blobs (ScrollView* window) {
337
324
C_BLOB_IT it = &rej_cblobs;
338
325
for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
339
326
it.data ()->plot (window, ScrollView::GREY, ScrollView::GREY);
340
327
}
341
328
}
342
329
#endif // GRAPHICS_DISABLED
343
330
344
-
345
331
/* *
346
332
* WERD::shallow_copy()
347
333
*
348
334
* Make a shallow copy of a word
349
335
*/
350
336
351
- WERD * WERD::shallow_copy () {
352
- WERD * new_word = new WERD;
337
+ WERD* WERD::shallow_copy () {
338
+ WERD* new_word = new WERD;
353
339
354
340
new_word->blanks = blanks;
355
341
new_word->flags = flags;
@@ -358,41 +344,37 @@ WERD *WERD::shallow_copy() {
358
344
return new_word;
359
345
}
360
346
361
-
362
347
/* *
363
348
* WERD::operator=
364
349
*
365
350
* Assign a word, DEEP copying the blob list
366
351
*/
367
352
368
- WERD & WERD::operator = (const WERD & source) {
369
- this ->ELIST2_LINK ::operator = (source);
353
+ WERD& WERD::operator =(const WERD& source) {
354
+ this ->ELIST2_LINK ::operator =(source);
370
355
blanks = source.blanks ;
371
356
flags = source.flags ;
372
357
script_id_ = source.script_id_ ;
373
358
dummy = source.dummy ;
374
359
correct = source.correct ;
375
- if (!cblobs.empty ())
376
- cblobs.clear ();
360
+ if (!cblobs.empty ()) cblobs.clear ();
377
361
cblobs.deep_copy (&source.cblobs , &C_BLOB::deep_copy);
378
362
379
- if (!rej_cblobs.empty ())
380
- rej_cblobs.clear ();
363
+ if (!rej_cblobs.empty ()) rej_cblobs.clear ();
381
364
rej_cblobs.deep_copy (&source.rej_cblobs , &C_BLOB::deep_copy);
382
365
return *this ;
383
366
}
384
367
385
-
386
368
/* *
387
369
* word_comparator()
388
370
*
389
371
* word comparator used to sort a word list so that words are in increasing
390
372
* order of left edge.
391
373
*/
392
374
393
- int word_comparator (const void * word1p, const void * word2p) {
394
- const WERD * word1 = *reinterpret_cast <const WERD* const *>(word1p);
395
- const WERD * word2 = *reinterpret_cast <const WERD* const *>(word2p);
375
+ int word_comparator (const void * word1p, const void * word2p) {
376
+ const WERD* word1 = *reinterpret_cast <const WERD* const *>(word1p);
377
+ const WERD* word2 = *reinterpret_cast <const WERD* const *>(word2p);
396
378
return word1->bounding_box ().left () - word2->bounding_box ().left ();
397
379
}
398
380
@@ -475,7 +457,7 @@ WERD* WERD::ConstructWerdWithNewBlobs(C_BLOB_LIST* all_blobs,
475
457
TBOX a_blob_box = a_blob->bounding_box ();
476
458
if ((not_found_box.major_overlap (a_blob_box) ||
477
459
a_blob_box.major_overlap (not_found_box)) &&
478
- not_found_box.y_overlap_fraction (a_blob_box) > 0.8 ) {
460
+ not_found_box.y_overlap_fraction (a_blob_box) > 0.8 ) {
479
461
// Already taken care of.
480
462
delete not_found_it.extract ();
481
463
break ;
0 commit comments