Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

ttf.h

00001 //FILE:         ttf.h
00002 //AUTHOR:       Nathan Cournia <nathan@cournia.com>
00003 
00004 #ifndef COURNIA_TTF_H
00005 #define COURNIA_TTF_H 1
00006 
00007 #include "config.h"
00008 #ifdef HAVE_GNU_EXT_HASH_MAP
00009 #include <ext/hash_map>
00010 namespace std { using namespace __gnu_cxx; }
00011 #else
00012 #ifdef HAVE_EXT_HASH_MAP
00013 #include <ext/hash_map>
00014 #else
00015 #ifdef HAVE_STL
00016 #include <hash_map>
00017 #endif
00018 #endif
00019 #endif
00020 
00021 #include <ft2build.h>
00022 #include FT_FREETYPE_H
00023 
00024 #include "texture.h"
00025 
00026 namespace gl {
00027         class ttf;
00028 }
00029 
00031 
00056 class gl::ttf
00057 {
00058 public:
00060         struct eqchar {
00061                 bool operator()( char c1, char c2 ) const {
00062                         return (c1 == c2);
00063                 }
00064         };
00065 
00067         struct glyph {
00068                 GLfloat bx, by; 
00069                 GLfloat tx, ty; 
00070                 GLfloat aspect; 
00071                 //unsigned int base;
00072                 //unsigned int width;
00073         };
00074 
00076         typedef std::hash_map<char, glyph*, std::hash<char>, eqchar> glyph_hash;
00077 
00078 private:
00079         //static data shared between all instances of this class
00080         static FT_Library s_library;
00081         static unsigned int s_library_refs;
00082 
00083         //instance specific data
00084         texture m_texture;
00085         std::string m_name;
00086         glyph_hash m_glyphs;
00087         FT_Face m_face;
00088         GLfloat m_baseline;
00089         //real_t m_size;
00090 
00091 public:
00093         ttf( void );
00094 
00096         ttf( const ttf& cpy );
00097         
00099         ~ttf( void );
00100 
00102         ttf& operator= ( const ttf& cpy );
00103 
00105 
00116         void render_string( real_t &x, real_t &y, real_t size, 
00117                 const std::string& text ) const;
00118 
00120         inline std::string get_name( void ) const {
00121                 return m_name;
00122         }
00123 
00125         inline operator bool ( void ) const {
00126                 return m_texture;
00127         }
00128 
00130         inline texture get_texture( void ) const {
00131                 return m_texture;
00132         }
00133 
00135         /*
00136          * All fonts are rendered on a 512x512 texture.  Setting \a pt_size
00137          * to high may cause the font to fail to load because there is not
00138          * enough texture space.
00139          * \param filename The file to load.  Must be a true type font (ttf).
00140          * \param pt_size Height (in pixels) of the largest glyph to render.
00141          */
00142         static ttf* load( const std::string& filename, unsigned int pt_size );
00143 };
00144 
00145 #endif

Generated on Tue Feb 11 18:49:42 2003 for uber by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002