00001
00020 #include "mfcpch.h"
00021 #include <stdlib.h>
00022 #include "blckerr.h"
00023 #include "ocrblock.h"
00024 #include "tprintf.h"
00025
00026 #define BLOCK_LABEL_HEIGHT 150 //char height of block id
00027
00031 ELISTIZE_S (BLOCK)
00032 BLOCK::BLOCK (
00033 const char *name,
00034 BOOL8 prop,
00035 INT16 kern,
00036 INT16 space,
00037 INT16 xmin,
00038 INT16 ymin, INT16 xmax,
00039 INT16 ymax):
00040 PDBLK (xmin, ymin, xmax, ymax),
00041 filename(name) {
00042
00043 ICOORDELT_IT left_it = &leftside;
00044 ICOORDELT_IT right_it = &rightside;
00045
00046 proportional = prop;
00047 kerning = kern;
00048 spacing = space;
00049 font_class = -1;
00050 hand_block = NULL;
00051 hand_poly = NULL;
00052 left_it.set_to_list (&leftside);
00053 right_it.set_to_list (&rightside);
00054
00055 left_it.add_to_end (new ICOORDELT (xmin, ymin));
00056 left_it.add_to_end (new ICOORDELT (xmin, ymax));
00057 right_it.add_to_end (new ICOORDELT (xmax, ymin));
00058 right_it.add_to_end (new ICOORDELT (xmax, ymax));
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00137 int decreasing_top_order(
00138 const void *row1,
00139 const void *row2) {
00140 return (*(ROW **) row2)->bounding_box ().top () -
00141 (*(ROW **) row1)->bounding_box ().top ();
00142 }
00143
00144
00150 void BLOCK::sort_rows() {
00151 ROW_IT row_it(&rows);
00152
00153 row_it.sort (decreasing_top_order);
00154 }
00155
00156
00163 void BLOCK::compress() {
00164 #define ROW_SPACING 5
00165
00166 ROW_IT row_it(&rows);
00167 ROW *row;
00168 ICOORD row_spacing (0, ROW_SPACING);
00169
00170 ICOORDELT_IT icoordelt_it;
00171
00172 sort_rows();
00173
00174 box = BOX (box.topleft (), box.topleft ());
00175 box.move_bottom_edge (ROW_SPACING);
00176 for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
00177 row = row_it.data ();
00178 row->move (box.botleft () - row_spacing -
00179 row->bounding_box ().topleft ());
00180 box += row->bounding_box ();
00181 }
00182
00183 leftside.clear ();
00184 icoordelt_it.set_to_list (&leftside);
00185 icoordelt_it.add_to_end (new ICOORDELT (box.left (), box.bottom ()));
00186 icoordelt_it.add_to_end (new ICOORDELT (box.left (), box.top ()));
00187 rightside.clear ();
00188 icoordelt_it.set_to_list (&rightside);
00189 icoordelt_it.add_to_end (new ICOORDELT (box.right (), box.bottom ()));
00190 icoordelt_it.add_to_end (new ICOORDELT (box.right (), box.top ()));
00191 }
00192
00193
00200 void BLOCK::check_pitch() {
00201
00202 pitch = -1;
00203 }
00204
00205
00211 void BLOCK::compress(
00212 const ICOORD vec
00213 ) {
00214 box.move (vec);
00215 compress();
00216 }
00217
00218
00222 void BLOCK::print(
00223 FILE *,
00224 BOOL8 dump
00225 ) {
00226 ICOORDELT_IT it = &leftside;
00227
00228 box.print ();
00229 tprintf ("Proportional= %s\n", proportional ? "TRUE" : "FALSE");
00230 tprintf ("Kerning= %d\n", kerning);
00231 tprintf ("Spacing= %d\n", spacing);
00232 tprintf ("Fixed_pitch=%d\n", pitch);
00233 tprintf ("Filename= %s\n", filename.string ());
00234
00235 if (dump) {
00236 tprintf ("Left side coords are:\n");
00237 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
00238 tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
00239 tprintf ("\n");
00240 tprintf ("Right side coords are:\n");
00241 it.set_to_list (&rightside);
00242 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
00243 tprintf ("(%d,%d) ", it.data ()->x (), it.data ()->y ());
00244 tprintf ("\n");
00245 }
00246 }
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00325
00326
00327
00328
00329
00330
00336 BLOCK & BLOCK::operator= (
00337 const BLOCK & source
00338 ) {
00339 this->ELIST_LINK::operator= (source);
00340 this->PDBLK::operator= (source);
00341 proportional = source.proportional;
00342 kerning = source.kerning;
00343 spacing = source.spacing;
00344 filename = source.filename;
00345 if (!rows.empty ())
00346 rows.clear ();
00347
00348
00349
00350
00351
00352
00353
00354 return *this;
00355 }