MeVisLabToolboxReference
|
00001 //---------------------------------------------------------------------------------- 00002 // **InsertLicense** code 00003 //---------------------------------------------------------------------------------- 00005 00011 //---------------------------------------------------------------------------------- 00012 #ifndef __mlGL2DFont_H 00013 #define __mlGL2DFont_H 00014 00015 #ifndef __mlOpenGLSystem_H 00016 #include "mlOpenGLSystem.h" 00017 #endif 00018 00019 #include "mlGLResources.h" 00020 #include <string> 00021 00022 class FTFont; 00023 00024 ML_OPENGL_START_NAMESPACE 00025 00026 //----------------------------------------------------------------------------- 00049 //----------------------------------------------------------------------------- 00050 class MLOPENGL_EXPORT GL2DFont : public GLResource { 00051 00052 public: 00053 GL2DFont(); 00054 ~GL2DFont(); 00055 00056 // currently the maximum internal font number is hardwired 00057 enum { 00058 MAX_FONTS = 32 00059 }; 00060 00061 //--------------------------------------------------------------------------- 00064 //--------------------------------------------------------------------------- 00065 bool init(); 00066 00067 //--------------------------------------------------------------------------- 00071 //--------------------------------------------------------------------------- 00072 bool init(const char* fontname); 00073 00074 //--------------------------------------------------------------------------- 00079 //--------------------------------------------------------------------------- 00080 bool init(const char* fontname, 00081 const int numFonts, const int* sizes); 00082 00083 //--------------------------------------------------------------------------- 00096 //--------------------------------------------------------------------------- 00097 void drawString(const float dx, const float dy, 00098 const float fontSize, const float color[4], 00099 const char* string, const size_t length = 0, 00100 const bool overlay=false, const bool shadow=true); 00101 00102 //--------------------------------------------------------------------------- 00105 //--------------------------------------------------------------------------- 00106 int getStringWidth(const float fontSize, 00107 const char* string, const size_t length) const; 00108 00109 //--------------------------------------------------------------------------- 00112 //--------------------------------------------------------------------------- 00113 int getFontHeight(const float fontSize) const; 00114 00115 //--------------------------------------------------------------------------- 00118 //--------------------------------------------------------------------------- 00119 int getFontAscender(const float fontSize) const; 00120 00121 //--------------------------------------------------------------------------- 00124 //--------------------------------------------------------------------------- 00125 int getFontDescender(const float fontSize) const; 00126 00127 //--------------------------------------------------------------------------- 00129 //--------------------------------------------------------------------------- 00130 bool isInitialized() const { return _init; }; 00131 00132 //--------------------------------------------------------------------------- 00134 //--------------------------------------------------------------------------- 00135 bool isUnicodeRenderingPossible() const { return _unicodeRendering; }; 00136 00137 //--------------------------------------------------------------------------- 00141 //--------------------------------------------------------------------------- 00142 static GL2DFont* getDefaultSystemFont(); 00143 00144 //--------------------------------------------------------------------------- 00146 //--------------------------------------------------------------------------- 00147 virtual void contextDestroyed(); 00148 00149 //--------------------------------------------------------------------------- 00151 //--------------------------------------------------------------------------- 00152 bool debugFontRenderingEnabled(); 00153 00154 //--------------------------------------------------------------------------- 00159 //--------------------------------------------------------------------------- 00160 static std::string getDefaultSystemFontName(); 00161 00162 protected: 00163 //--------------------------------------------------------------------------- 00165 //--------------------------------------------------------------------------- 00166 int getFontIndex(const float fontSize) const; 00167 00168 //--------------------------------------------------------------------------- 00170 //--------------------------------------------------------------------------- 00171 void cleanup(); 00172 00173 //--------------------------------------------------------------------------- 00175 //--------------------------------------------------------------------------- 00176 bool reloadFonts(); 00177 00178 //--------------------------------------------------------------------------- 00180 //--------------------------------------------------------------------------- 00181 void preFontDraw(const bool overlay); 00182 00183 //--------------------------------------------------------------------------- 00185 //--------------------------------------------------------------------------- 00186 void doFontDraw(const float dx, const float dy, 00187 const float fontSize, const float color[4], 00188 const bool shadow, const char* asciiString, const wchar_t* optionalUnicodeString); 00189 00190 //--------------------------------------------------------------------------- 00192 //--------------------------------------------------------------------------- 00193 void postFontDraw(const bool overlay); 00194 00195 //--------------------------------------------------------------------------- 00197 //--------------------------------------------------------------------------- 00198 bool checkUTF8StringForUnicodeChars(const char* string, size_t length = 0) const; 00199 00200 //--------------------------------------------------------------------------- 00204 //--------------------------------------------------------------------------- 00205 const char* copyAndConvertString(const char* string, size_t length, const wchar_t** optionalUnicodeString) const; 00206 00207 private: 00209 std::string _fontfile; 00210 00212 std::string _fallback; 00213 00215 int _numFonts; 00216 00218 FTFont* _font[MAX_FONTS]; 00219 00221 float _fontSize[MAX_FONTS]; 00222 00224 bool _init; 00225 00227 bool _unicodeRendering; 00228 00230 static GL2DFont* _defaultSystemFont; 00231 }; 00232 00233 ML_OPENGL_END_NAMESPACE 00234 #endif