00001 # ifndef GlyphFeatures_h
00002 # define GlyphFeatures_h GlyphFeatures_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 # include "Root.h"
00022
00023
00024 # include <vector>
00025
00026 namespace Conjecture {
00027 class Glyph;
00028
00029
00095
00096
00097 class GlyphFeatures : public Root {
00098 public:
00099
00100
00117 typedef float Confidence;
00118
00132 typedef enum {
00133
00134
00135 LTUnknown = 0,
00136 Base = 1,
00137 Ascender = 2,
00138 Descender = 3,
00139 Total = 4,
00140
00141 __LTSIZE = 5,
00142 } LineType;
00143
00153 typedef enum {
00154
00155
00156 Center = 1,
00157 Top = 2,
00158 Bottom = 3,
00159 Left = 4,
00160 Right = 5,
00161 Dominant = 8,
00162 Recessive = 9,
00163 HalfLine = 10,
00164
00165 Undef = 11,
00166 } Variant;
00167
00168 private:
00169 static const char* _LineTypes[__LTSIZE+1];
00170 static std::string LineTypeStr(LineType v);
00171
00172 static const char* _Variants[Undef+1];
00173 static std::string VariantStr(Variant v);
00174
00181 typedef std::vector<Variant> VariantSet;
00182 typedef std::pair<Variant,Variant> Variant2;
00183 typedef std::vector<Variant2> Variant2Set;
00184
00185 public:
00186
00187 GlyphFeatures(LineType lineType = LTUnknown);
00188
00229 GlyphFeatures(wchar_t unicode, LineType lineType, const std::string& spec);
00230
00231 void init(wchar_t unicode, LineType lineType);
00232
00233
00234
00235 inline wchar_t unicode() const { return this->_unicode; }
00236 inline bool xdisconnect() const { return this->_xdisconnect; }
00237 inline bool ydisconnect() const { return this->_ydisconnect; }
00238 inline float MostOfLength() const { return this->_MostOfLength; }
00239 inline const LineType& lineType() const { return this->_lineType; }
00240
00241
00242
00243
00244
00245
00246 void addHorizontal(Variant position, Variant length);
00247 void addVertical(Variant position, Variant length);
00248 void addHole(Variant position);
00249 void addCup(Variant position);
00250
00255
00261 Variant hasHorizontal(Variant position) const;
00262 Variant hasVertical(Variant position) const;
00263 bool hasHole(Variant position) const;
00264 bool hasCup(Variant position) const;
00265
00266
00268 std::ostream& print(std::ostream& os = std::cout, const std::string& indent = "") const;
00269
00270 static void Test(int argc = 0, const char* argv[] = NULL);
00271
00332 Confidence matches(const GlyphFeatures& target) const;
00333
00334 protected:
00335
00336
00337 inline void unicodeIs(const wchar_t & unicode) { this->_unicode = unicode; }
00338 inline void xdisconnectIs(const bool & xdisconnect) { this->_xdisconnect = xdisconnect; }
00339 inline void ydisconnectIs(const bool & ydisconnect) { this->_ydisconnect = ydisconnect; }
00340 inline void lineTypeIs(const LineType & lineType) { this->_lineType = lineType; }
00341 inline void MostOfLengthIs(float MostOfLength) { this->_MostOfLength = MostOfLength; }
00342
00343
00344 inline const Variant2Set & horizontal() const { return this->_horizontal; }
00345 inline const Variant2Set & vertical() const { return this->_vertical; }
00346 inline const VariantSet & holes() const { return this->_holes; }
00347 inline const VariantSet & cups() const { return this->_cups; }
00348
00349 inline wchar_t & unicodeRef() { return this->_unicode; }
00350 inline bool & xdisconnectRef() { return this->_xdisconnect; }
00351 inline bool & ydisconnectRef() { return this->_ydisconnect; }
00352 inline LineType & lineTypeRef() { return this->_lineType; }
00353 inline Variant2Set & horizontalRef() { return this->_horizontal; }
00354 inline Variant2Set & verticalRef() { return this->_vertical; }
00355 inline VariantSet & holesRef() { return this->_holes; }
00356 inline VariantSet & cupsRef() { return this->_cups; }
00357
00358
00359
00360 Confidence lineMatch(Variant mine, Variant target) const;
00361
00362 private:
00363
00364
00365 inline float & MostOfLengthRef() { return this->_MostOfLength; }
00366
00367
00368
00369
00370
00371
00372 wchar_t _unicode;
00373 bool _xdisconnect;
00374 bool _ydisconnect;
00375
00382 LineType _lineType;
00383
00384 Variant2Set _horizontal;
00385 Variant2Set _vertical;
00386 VariantSet _holes;
00387 VariantSet _cups;
00388
00389 static float _MostOfLength;
00390 };
00391 }
00392
00393 # endif // GlyphFeatures_h
00394