00001
00002
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
00072
00073 };
00074
00076 typedef std::hash_map<char, glyph*, std::hash<char>, eqchar> glyph_hash;
00077
00078 private:
00079
00080 static FT_Library s_library;
00081 static unsigned int s_library_refs;
00082
00083
00084 texture m_texture;
00085 std::string m_name;
00086 glyph_hash m_glyphs;
00087 FT_Face m_face;
00088 GLfloat m_baseline;
00089
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
00137
00138
00139
00140
00141
00142 static ttf* load( const std::string& filename, unsigned int pt_size );
00143 };
00144
00145 #endif