00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef MMSFBFONT_H_
00034 #define MMSFBFONT_H_
00035
00036 #include "mmsgui/fb/mmsfbbase.h"
00037 #include "mmsgui/fb/mmsfbbuffer.h"
00038
00039 #ifdef __HAVE_GLU__
00040 #define MMSFBFONT_GLYPH_MAX_MESHES 512
00041 #endif
00042
00043
00044 typedef struct {
00045
00046 unsigned int character;
00047
00048 unsigned char *buffer;
00049
00050 int pitch;
00051
00052 int left;
00053
00054 int top;
00055
00056 int width;
00057
00058 int height;
00059
00060 int advanceX;
00061 #ifdef __HAVE_OPENGL__
00062 #ifndef __HAVE_GLU__
00063
00064
00065 GLuint texture;
00066 #else
00067
00068
00069 MMSFBBuffer *meshes;
00070 MMSFBBuffer *outline;
00071 #endif
00072 #endif
00073 } MMSFBFont_Glyph;
00074
00075
00076
00077
00078
00079 class MMSFBFont {
00080 private:
00081
00082 bool initialized;
00083
00084
00085 MMSMutex Lock;
00086
00087 #ifdef __HAVE_DIRECTFB__
00088
00089 void *dfbfont;
00090 #endif
00091
00092
00093 static void *ft_library;
00094
00095
00096 void *ft_face;
00097
00098
00099 string filename;
00100
00101
00102 typedef std::map<std::string, unsigned int> MMSFBFONT_MAP;
00103
00104
00105 static MMSFBFONT_MAP index;
00106
00107
00108 static unsigned int index_pos;
00109
00110
00111 unsigned int font_id;
00112
00113 #if (defined(__HAVE_OPENGL__) && defined(__HAVE_GLU__))
00114
00115 float scale_coeff;
00116 #endif
00117
00118
00119 int ascender;
00120
00121
00122 int descender;
00123
00124
00125 int height;
00126
00127
00128 std::map<unsigned int, MMSFBFont_Glyph> charmap;
00129
00130
00131 static unsigned int numReferences;
00132
00133 void lock();
00134 void unlock();
00135
00136 void *loadFTGlyph(unsigned int character);
00137 bool setupFTGlyph(unsigned int character, void *ftg, MMSFBFont_Glyph *glyph);
00138
00139 public:
00140 MMSFBFont(string filename, int w, int h);
00141 virtual ~MMSFBFont();
00142
00143 bool isInitialized();
00144
00145 bool getStringWidth(string text, int len, int *width);
00146 bool getHeight(int *height);
00147
00148 bool getAscender(int *ascender);
00149 bool getDescender(int *descender);
00150
00151 bool getScaleCoeff(float *scale_coeff);
00152
00153 bool getGlyph(unsigned int character, MMSFBFont_Glyph *glyph);
00154
00155 friend class MMSFBSurface;
00156 friend class MMSFBBackEndInterface;
00157 };
00158
00159 #define MMSFBFONT_GET_UNICODE_CHAR(text, len) \
00160 for (int cnt = 0; cnt < len; cnt++) { \
00161 unsigned char c = text[cnt]; \
00162 unsigned int character; \
00163 if(c >= 0xf0) { \
00164 if(len < (cnt + 3)) { DEBUGMSG("MMSFBFONT", "invalid unicode string"); break; } \
00165 character = (unsigned int)((c & 0x07 ) << 18); \
00166 character |= ((text[++cnt] & 0x3f ) << 12); \
00167 character |= ((text[++cnt] & 0x3f) << 6); \
00168 character |= (text[++cnt] & 0x3f); \
00169 } else if(c >= 0xe0) { \
00170 if(len < (cnt + 2)) { DEBUGMSG("MMSFBFONT", "invalid unicode string"); break; } \
00171 character = (unsigned int)((c & 0x0f ) << 12); \
00172 character |= ((text[++cnt] & 0x3f) << 6); \
00173 character |= (text[++cnt] & 0x3f); \
00174 } else if(c >= 0xc0) { \
00175 if(len < (cnt + 1)) { DEBUGMSG("MMSFBFONT", "invalid unicode string"); break; } \
00176 character = (unsigned int)(((c & 0x1f ) << 6) | (text[++cnt] & 0x3f)); \
00177 } else { \
00178 character = (unsigned int)c; \
00179 }
00180
00181 #endif