00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef BLOBS_H
00027 #define BLOBS_H
00028
00029
00030
00031
00032 #include "clst.h"
00033 #include "rect.h"
00034 #include "vecfuncs.h"
00035
00036 class BLOCK;
00037 class C_BLOB;
00038 class DENORM;
00039 class ROW;
00040 class WERD;
00041
00042
00043
00044
00045 #define EDGEPTFLAGS 4
00046
00047 typedef struct
00048 {
00049 int num_chars;
00050 int widths[1];
00051 } WIDTH_RECORD;
00052
00053 struct TPOINT {
00054 TPOINT(): x(0), y(0) {}
00055 TPOINT(inT16 vx, inT16 vy) : x(vx), y(vy) {}
00056 TPOINT(const ICOORD &ic) : x(ic.x()), y(ic.y()) {}
00057
00058 void operator+=(const TPOINT& other) {
00059 x += other.x;
00060 y += other.y;
00061 }
00062 void operator/=(int divisor) {
00063 x /= divisor;
00064 y /= divisor;
00065 }
00066
00067 inT16 x;
00068 inT16 y;
00069 };
00070 typedef TPOINT VECTOR;
00071
00072 struct EDGEPT {
00073 EDGEPT() : next(NULL), prev(NULL) {
00074 memset(flags, 0, EDGEPTFLAGS * sizeof(flags[0]));
00075 }
00076 EDGEPT(const EDGEPT& src) : next(NULL), prev(NULL) {
00077 CopyFrom(src);
00078 }
00079 EDGEPT& operator=(const EDGEPT& src) {
00080 CopyFrom(src);
00081 return *this;
00082 }
00083
00084 void CopyFrom(const EDGEPT& src) {
00085 pos = src.pos;
00086 vec = src.vec;
00087 memcpy(flags, src.flags, EDGEPTFLAGS * sizeof(flags[0]));
00088 }
00089
00090 void Hide() {
00091 flags[0] = true;
00092 }
00093 void Reveal() {
00094 flags[0] = false;
00095 }
00096 bool IsHidden() const {
00097 return flags[0] != 0;
00098 }
00099
00100 TPOINT pos;
00101 VECTOR vec;
00102
00103
00104
00105 char flags[EDGEPTFLAGS];
00106 EDGEPT* next;
00107 EDGEPT* prev;
00108 };
00109
00110
00111 CLISTIZEH(EDGEPT);
00112
00113 struct TESSLINE {
00114 TESSLINE() : is_hole(false), loop(NULL), next(NULL) {}
00115 TESSLINE(const TESSLINE& src) : loop(NULL), next(NULL) {
00116 CopyFrom(src);
00117 }
00118 ~TESSLINE() {
00119 Clear();
00120 }
00121 TESSLINE& operator=(const TESSLINE& src) {
00122 CopyFrom(src);
00123 return *this;
00124 }
00125
00126 static TESSLINE* BuildFromOutlineList(EDGEPT* outline);
00127
00128 void CopyFrom(const TESSLINE& src);
00129
00130 void Clear();
00131
00132 void Normalize(const DENORM& denorm);
00133
00134 void Rotate(const FCOORD rotation);
00135
00136 void Move(const ICOORD vec);
00137
00138 void Scale(float factor);
00139
00140 void SetupFromPos();
00141
00142 void ComputeBoundingBox();
00143
00144
00145
00146
00147
00148 void MinMaxCrossProduct(const TPOINT vec, int* min_xp, int* max_xp) const;
00149
00150 TBOX bounding_box() const;
00151
00152 bool Contains(const TPOINT& pt) {
00153 return topleft.x <= pt.x && pt.x <= botright.x &&
00154 botright.y <= pt.y && pt.y <= topleft.y;
00155 }
00156
00157 void plot(ScrollView* window, ScrollView::Color color,
00158 ScrollView::Color child_color);
00159
00160 int BBArea() const {
00161 return (botright.x - topleft.x) * (topleft.y - botright.y);
00162 }
00163
00164 TPOINT topleft;
00165 TPOINT botright;
00166 TPOINT start;
00167 bool is_hole;
00168 EDGEPT *loop;
00169 TESSLINE *next;
00170 };
00171
00172 struct TBLOB {
00173 TBLOB() : outlines(NULL), next(NULL) {}
00174 TBLOB(const TBLOB& src) : outlines(NULL), next(NULL) {
00175 CopyFrom(src);
00176 }
00177 ~TBLOB() {
00178 Clear();
00179 }
00180 TBLOB& operator=(const TBLOB& src) {
00181 CopyFrom(src);
00182 return *this;
00183 }
00184
00185
00186 static TBLOB* PolygonalCopy(C_BLOB* src);
00187
00188
00189
00190
00191
00192 TBLOB* ClassifyNormalizeIfNeeded(const DENORM** denorm) const;
00193
00194 void CopyFrom(const TBLOB& src);
00195
00196 void Clear();
00197
00198 void Normalize(const DENORM& denorm);
00199
00200 void Rotate(const FCOORD rotation);
00201
00202 void Move(const ICOORD vec);
00203
00204 void Scale(float factor);
00205
00206 void ComputeBoundingBoxes();
00207
00208
00209 int NumOutlines() const;
00210
00211 TBOX bounding_box() const;
00212
00213 void plot(ScrollView* window, ScrollView::Color color,
00214 ScrollView::Color child_color);
00215
00216 int BBArea() const {
00217 int total_area = 0;
00218 for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next)
00219 total_area += outline->BBArea();
00220 return total_area;
00221 }
00222
00223 TESSLINE *outlines;
00224 TBLOB *next;
00225 };
00226
00227 int count_blobs(TBLOB *blobs);
00228
00229 struct TWERD {
00230 TWERD() : blobs(NULL), latin_script(false), next(NULL) {}
00231 TWERD(const TWERD& src) : blobs(NULL), next(NULL) {
00232 CopyFrom(src);
00233 }
00234 ~TWERD() {
00235 Clear();
00236 }
00237 TWERD& operator=(const TWERD& src) {
00238 CopyFrom(src);
00239 return *this;
00240 }
00241
00242
00243 static TWERD* PolygonalCopy(WERD* src);
00244
00245
00246 void SetupBLNormalize(const BLOCK* block, const ROW* row,
00247 float x_height, bool numeric_mode,
00248 DENORM* denorm) const;
00249
00250 void Normalize(const DENORM& denorm);
00251
00252 void CopyFrom(const TWERD& src);
00253
00254 void Clear();
00255
00256 void ComputeBoundingBoxes();
00257
00258
00259 int NumBlobs() const {
00260 return count_blobs(blobs);
00261 }
00262 TBOX bounding_box() const;
00263
00264
00265
00266 void MergeBlobs(int start, int end);
00267
00268 void plot(ScrollView* window);
00269
00270 TBLOB* blobs;
00271 bool latin_script;
00272 TWERD* next;
00273 };
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 #define free_widths(w) \
00284 if (w) memfree (w)
00285
00286
00287
00288
00289
00290
00291
00292
00293 void blob_origin(TBLOB *blob, TPOINT *origin);
00294
00295
00296 WIDTH_RECORD *blobs_widths(TBLOB *blobs);
00297
00298 bool divisible_blob(TBLOB *blob, bool italic_blob, TPOINT* location);
00299
00300 void divide_blobs(TBLOB *blob, TBLOB *other_blob, bool italic_blob,
00301 const TPOINT& location);
00302
00303 #endif