MeVisLab Resolution Independence API
Loading...
Searching...
No Matches
mlGL2DFont.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_GL_2D_FONT_H
14#define ML_GL_2D_FONT_H
15
16
18
19#include "mlOpenGLSystem.h"
20
21#include "mlGLResources.h"
22#include <string>
23
24class FTFont;
25
26ML_OPENGL_START_NAMESPACE
27
28//-----------------------------------------------------------------------------
51//-----------------------------------------------------------------------------
53{
54
55public:
57 ~GL2DFont() override;
58
59 // Currently, the maximum internal font number is hardwired.
60 enum {
62 };
63
64 //---------------------------------------------------------------------------
67 //---------------------------------------------------------------------------
68 bool init();
69
70 //---------------------------------------------------------------------------
74 //---------------------------------------------------------------------------
75 bool init(const char* fontname);
76
77 //---------------------------------------------------------------------------
82 //---------------------------------------------------------------------------
83 bool init(const char* fontname, int numFonts, const int* sizes);
84
85 //---------------------------------------------------------------------------
103 //---------------------------------------------------------------------------
104 void drawString(float dx, float dy, float fontSize, const float color[4], const char* string, size_t length = 0,
105 bool overlay = false, bool shadow = true, const float* shadowColor = nullptr);
106
107 //---------------------------------------------------------------------------
110 //---------------------------------------------------------------------------
111 int getStringWidth(float fontSize, const char* string, int length = -1) const;
112
113 //---------------------------------------------------------------------------
116 //---------------------------------------------------------------------------
117 int getFontHeight(float fontSize) const;
118
119 //---------------------------------------------------------------------------
122 //---------------------------------------------------------------------------
123 int getFontAscender(float fontSize) const;
124
125 //---------------------------------------------------------------------------
128 //---------------------------------------------------------------------------
129 int getFontDescender(float fontSize) const;
130
131 //---------------------------------------------------------------------------
133 //---------------------------------------------------------------------------
134 bool isInitialized() const
135 {
136 return _init;
137 };
138
139 //---------------------------------------------------------------------------
141 //---------------------------------------------------------------------------
143 {
144 return _unicodeRendering;
145 };
146
147 //---------------------------------------------------------------------------
151 //---------------------------------------------------------------------------
153
154 //---------------------------------------------------------------------------
156 //---------------------------------------------------------------------------
157 void contextDestroyed() override;
158
159 //---------------------------------------------------------------------------
161 //---------------------------------------------------------------------------
163
164 //---------------------------------------------------------------------------
169 //---------------------------------------------------------------------------
170 static std::string getDefaultSystemFontName();
171
172protected:
173 //---------------------------------------------------------------------------
175 //---------------------------------------------------------------------------
176 int getFontIndex(float fontSize) const;
177
178 //---------------------------------------------------------------------------
180 //---------------------------------------------------------------------------
181 void cleanup();
182
183 //---------------------------------------------------------------------------
185 //---------------------------------------------------------------------------
187
188 //---------------------------------------------------------------------------
190 //---------------------------------------------------------------------------
191 void preFontDraw(bool overlay);
192
193 //---------------------------------------------------------------------------
195 //---------------------------------------------------------------------------
196 void doFontDraw(float dx, float dy, float fontSize, const float color[4], bool shadow, const char* asciiString,
197 const wchar_t* optionalUnicodeString, const float* shadowColor);
198
199 //---------------------------------------------------------------------------
201 //---------------------------------------------------------------------------
202 void postFontDraw(const bool overlay);
203
204 //---------------------------------------------------------------------------
206 //---------------------------------------------------------------------------
207 bool checkUTF8StringForUnicodeChars(const char* string, size_t length = 0) const;
208
209 //---------------------------------------------------------------------------
213 //---------------------------------------------------------------------------
214 const char* copyAndConvertString(const char* string, size_t length, const wchar_t** optionalUnicodeString) const;
215
216 //---------------------------------------------------------------------------
219 //---------------------------------------------------------------------------
220 std::string findFontFile(const char* fontName);
221
222 //---------------------------------------------------------------------------
224 //---------------------------------------------------------------------------
225 std::string findFontFileWithFontconfig(const char* fontName);
226
227private:
229 std::string _fontfile;
230
232 std::string _fallback;
233
235 int _numFonts;
236
238 FTFont* _font[MAX_FONTS];
239
241 float _fontSize[MAX_FONTS];
242
244 bool _init;
245
247 bool _unicodeRendering;
248
250 static GL2DFont* _defaultSystemFont;
251};
252
253ML_OPENGL_END_NAMESPACE
254#endif
bool checkUTF8StringForUnicodeChars(const char *string, size_t length=0) const
Checks whether the string contains unicode chars.
bool isUnicodeRenderingPossible() const
Returns true if Unicode rendering is possible; otherwise, it returns false.
Definition mlGL2DFont.h:142
void drawString(float dx, float dy, float fontSize, const float color[4], const char *string, size_t length=0, bool overlay=false, bool shadow=true, const float *shadowColor=nullptr)
void doFontDraw(float dx, float dy, float fontSize, const float color[4], bool shadow, const char *asciiString, const wchar_t *optionalUnicodeString, const float *shadowColor)
Renders the fonts.
int getFontAscender(float fontSize) const
void postFontDraw(const bool overlay)
Finalizes the font rendering.
static std::string getDefaultSystemFontName()
bool reloadFonts()
Frees old fonts and reloads them.
std::string findFontFile(const char *fontName)
bool init(const char *fontname)
void contextDestroyed() override
Forgets the resource, the context was destroyed (called by the GLResourceManager).
static GL2DFont * getDefaultSystemFont()
const char * copyAndConvertString(const char *string, size_t length, const wchar_t **optionalUnicodeString) const
bool debugFontRenderingEnabled()
Checks whether debug font rendering is enabled.
std::string findFontFileWithFontconfig(const char *fontName)
Searches the font by using fontconfig (Linux only).
bool init(const char *fontname, int numFonts, const int *sizes)
int getStringWidth(float fontSize, const char *string, int length=-1) const
int getFontDescender(float fontSize) const
int getFontHeight(float fontSize) const
void preFontDraw(bool overlay)
Initializes font rendering.
bool isInitialized() const
Returns true if font loaded; otherwise, it returns false.
Definition mlGL2DFont.h:134
void cleanup()
Cleans up the fonts.
~GL2DFont() override
int getFontIndex(float fontSize) const
Returns the font index that should be used for the given size of the font.
#define MLOPENGL_EXPORT
Closes the namespace for all ML code after the usage of ML_UTILS_START_NAMESPACE.