Glyph.h

00001 # ifndef Conjecture_Glyph_h
00002 # define Conjecture_Glyph_h Conjecture_Glyph_h
00003 
00004 // C Dependencies
00005 //  - FUTURE FIX: these headers are only needed while the C++ interface
00006 //    relies on the underlying C code.
00007 
00008 # include "pnm.h"
00009 # include "gocr.h"  // Box
00010 
00011 // C++ Dependencies
00012 # include <vector>
00013 # include "Element.h"
00014 # include "ImageArgs.h"
00015 # include "GlyphFeatures.h"  // LineType, has-a
00016 
00017 namespace Conjecture {
00018 
00026 # define GlyphLoopStart(self, glyph) \
00027 { \
00028     std::vector<Glyph*> __glyphs; \
00029     (self)->allGlyphs(__glyphs); \
00030     for (std::vector<Glyph*>::iterator __it = __glyphs.begin(); __it != __glyphs.end(); ++__it) { \
00031       Glyph* glyph = *__it;
00032 
00033 # define ConstGlyphLoopStart(self, glyph) \
00034 { \
00035     std::vector<const Glyph*> __glyphs; \
00036     (self)->allGlyphs(__glyphs); \
00037     for (std::vector<const Glyph*>::const_iterator __it = __glyphs.begin(); __it != __glyphs.end(); ++__it) { \
00038       const Glyph* glyph = *__it;
00039 
00040 # define GlyphLoopEnd \
00041     } \
00042 }
00043 
00064   class Glyph : public Element {
00065   public:
00066     // ********
00067     // Types
00068     class Char {
00069       public:
00070       Char(wchar_t c,int w) { this->c = c; this->weight = w; }
00071       wchar_t c;
00072       int weight;
00073     };
00074 
00075     // *******
00076     // Methods
00077 
00084     Glyph(Element* parent = NULL, void* internal = NULL);
00085 
00091     Glyph(Glyph* glyph);
00092 
00098     virtual Glyph* asGlyph()             { return this; }
00099     virtual const Glyph* asGlyph() const { return this; }
00100 
00109     inline void setUnicode(wchar_t unicode) { this->unicodeIs(unicode); }
00110 
00111     virtual void printSummary(std::ostream& os = std::cerr, const std::string& indent = "", int index = -1) const;
00112 
00113     void addChar(const Glyph::Char& chr);
00114 
00121     GlyphFeatures::LineType lineType() const;
00122 
00123     // ---------------------------------------------------------------
00124     // DEBUGGING METHODS
00125 
00131     virtual void writeText(std::ostream& os) const;
00132 
00142     static void test(int argc = 0, const char* argv[] = NULL);
00143 
00144     wchar_t unicode() const { return this->_unicode; }
00145     const std::vector<Char>& charset() const { return this->_charset; }
00146 
00147     // Accessors
00148     inline int  best() const { return this->_best; }
00149     virtual int type() const { return Type; }
00150     // we provide 'box' publically because it is temporary - need to
00151     // remove it anyway, and Page often needs the Box within Glyph.
00152     inline const Box* box() const { return this->_box; }
00153     inline void boxIs(Box* box)   { this->_box = box; }
00154     inline Box* & boxRef()        { return this->_box; }
00155 
00156   protected:
00157     // ********
00158     // Methods
00159 
00160     // ********
00161     // Accessors
00162     inline void bestIs(const int & best) { this->_best = best; }
00163     inline int & bestRef() { return this->_best; }
00164     wchar_t& unicodeRef() { return this->_unicode; }
00165     void unicodeIs(wchar_t unicode) { this->_unicode = unicode; }
00166     std::vector<Char>& charset() { return this->_charset; }
00167 
00168   private:
00169     // ********
00170     // Methods
00171 
00172     // ********
00173     // Accessors
00174 
00175     // ********
00176     // State
00177     wchar_t           _unicode;
00178 
00192     static const ElementType Type = ELEMENT_GLYPH;
00193 
00194     // Are any of these really necessary?
00195     Box*              _box;   // old gocr data-structure
00196     int               _best; // inex into _charset (best match)
00197     std::vector<Char> _charset;
00198   };
00199 };
00200 
00201 # endif // Conjecture_Glyph_h
00202 

Generated on Thu Jun 15 19:56:09 2006 for Conjecture by  doxygen 1.4.6