00001 # ifndef Conjecture_GlyphFeatures_h
00002 # define Conjecture_GlyphFeatures_h Conjecture_GlyphFeatures_h
00003
00004
00005
00006
00007
00008 # include "Root.h"
00009
00010
00011 # include <vector>
00012
00013 namespace Conjecture {
00014 class Glyph;
00015
00085 class GlyphFeatures : public Root {
00086 public:
00087
00088
00108 typedef float Confidence;
00109
00126 typedef enum {
00127
00128
00129 LTUnknown = 0,
00130 Base = 1,
00131 Ascender = 2,
00132 Descender = 3,
00133 Total = 4,
00134
00135 __LTSIZE = 5,
00136 } LineType;
00137
00150 typedef enum {
00151
00152
00153 Center = 1,
00154 Top = 2,
00155 Bottom = 3,
00156 Left = 4,
00157 Right = 5,
00158 Dominant = 8,
00159 Recessive = 9,
00160 HalfLine = 10,
00161
00162 Undef = 11,
00163 } Variant;
00164
00165 private:
00166 static const char* _LineTypes[__LTSIZE+1];
00167 static std::string LineTypeStr(LineType v);
00168
00169 static const char* _Variants[Undef+1];
00170 static std::string VariantStr(Variant v);
00171
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
00232 GlyphFeatures(wchar_t unicode, LineType lineType, const std::string& spec);
00233
00234 void init(wchar_t unicode, LineType lineType);
00235
00236
00237 inline wchar_t unicode() const { return this->_unicode; }
00238 inline bool xdisconnect() const { return this->_xdisconnect; }
00239 inline bool ydisconnect() const { return this->_ydisconnect; }
00240 inline float MostOfLength() const { return this->_MostOfLength; }
00241 inline const LineType& lineType() const { return this->_lineType; }
00242
00243
00244 void addHorizontal(Variant position, Variant length);
00245 void addVertical(Variant position, Variant length);
00246 void addHole(Variant position);
00247 void addCup(Variant position);
00248
00262 Variant hasHorizontal(Variant position) const;
00263 Variant hasVertical(Variant position) const;
00264 bool hasHole(Variant position) const;
00265 bool hasCup(Variant position) const;
00266
00271 std::ostream& print(std::ostream& os = std::cout, const std::string& indent = "") const;
00272
00273 static void Test(int argc = 0, const char* argv[] = NULL);
00274
00338 Confidence matches(const GlyphFeatures& target) const;
00339
00340 protected:
00341
00342 inline void unicodeIs(const wchar_t & unicode) { this->_unicode = unicode; }
00343 inline void xdisconnectIs(const bool & xdisconnect) { this->_xdisconnect = xdisconnect; }
00344 inline void ydisconnectIs(const bool & ydisconnect) { this->_ydisconnect = ydisconnect; }
00345 inline void lineTypeIs(const LineType & lineType) { this->_lineType = lineType; }
00346 inline void MostOfLengthIs(float MostOfLength) { this->_MostOfLength = MostOfLength; }
00347
00348
00349 inline const Variant2Set & horizontal() const { return this->_horizontal; }
00350 inline const Variant2Set & vertical() const { return this->_vertical; }
00351 inline const VariantSet & holes() const { return this->_holes; }
00352 inline const VariantSet & cups() const { return this->_cups; }
00353
00354 inline wchar_t & unicodeRef() { return this->_unicode; }
00355 inline bool & xdisconnectRef() { return this->_xdisconnect; }
00356 inline bool & ydisconnectRef() { return this->_ydisconnect; }
00357 inline LineType & lineTypeRef() { return this->_lineType; }
00358 inline Variant2Set & horizontalRef() { return this->_horizontal; }
00359 inline Variant2Set & verticalRef() { return this->_vertical; }
00360 inline VariantSet & holesRef() { return this->_holes; }
00361 inline VariantSet & cupsRef() { return this->_cups; }
00362
00363
00364 Confidence lineMatch(Variant mine, Variant target) const;
00365
00366 private:
00367
00368 inline float & MostOfLengthRef() { return this->_MostOfLength; }
00369
00370
00371
00372
00373 wchar_t _unicode;
00374 bool _xdisconnect;
00375 bool _ydisconnect;
00376
00386 LineType _lineType;
00387
00388 Variant2Set _horizontal;
00389 Variant2Set _vertical;
00390 VariantSet _holes;
00391 VariantSet _cups;
00392
00393 static float _MostOfLength;
00394 };
00395 }
00396
00397 # endif // Conjecture_GlyphFeatures_h
00398