13#ifndef ML_GL_2D_FONT_H
14#define ML_GL_2D_FONT_H
26ML_OPENGL_START_NAMESPACE
74 bool init(
const char* fontname);
82 bool init(
const char* fontname,
83 const int numFonts,
const int* sizes);
101 const float fontSize,
const float color[4],
102 const char*
string,
const size_t length = 0,
103 const bool overlay=
false,
const bool shadow=
true,
104 const float* shadowColor=
nullptr);
111 const char*
string,
const size_t length)
const;
191 const float fontSize,
const float color[4],
192 const bool shadow,
const char* asciiString,
const wchar_t* optionalUnicodeString,
193 const float* shadowColor);
210 const char*
copyAndConvertString(
const char*
string,
size_t length,
const wchar_t** optionalUnicodeString)
const;
225 std::string _fontfile;
228 std::string _fallback;
234 FTFont* _font[MAX_FONTS];
237 float _fontSize[MAX_FONTS];
243 bool _unicodeRendering;
246 static GL2DFont* _defaultSystemFont;
249ML_OPENGL_END_NAMESPACE
A bridge to the ftgl library that manages font rendering with texture fonts.
bool checkUTF8StringForUnicodeChars(const char *string, size_t length=0) const
Check if the string contains unicode chars.
bool isUnicodeRenderingPossible() const
Returns true if unicode rendering is possible, otherwise false.
bool init(const char *fontname, const int numFonts, const int *sizes)
Init the given font (either just a font name without .ttf or an absolute path) with the given number ...
int getFontIndex(const float fontSize) const
Get the font idx that should be used for the given size of the font.
void postFontDraw(const bool overlay)
Finalize the font rendering.
int getStringWidth(const float fontSize, const char *string, const size_t length) const
Get width of the given simple string.
static std::string getDefaultSystemFontName()
returns the default font name for proportional fonts (this can be overwritten via the "GL2DFont_Defau...
bool reloadFonts()
Free old fonts and reload them.
std::string findFontFile(const char *fontName)
Searches for the file name of the given font.
bool init(const char *fontname)
Init the given font (either just a font name without .ttf or an absolute path).
void contextDestroyed() override
forget the resource, the context was destroyed (called by the GLResourceManager)
static GL2DFont * getDefaultSystemFont()
get the default system font (already initialized, a valid GL context is only required for the draw me...
const char * copyAndConvertString(const char *string, size_t length, const wchar_t **optionalUnicodeString) const
Internal method that copies the string to the internal buffer and generates a unicode string if it is...
int getFontDescender(const float fontSize) const
Get the descender of the font in pixels (positive distance from the baseline).
void preFontDraw(const bool overlay)
Initialize font rendering.
bool debugFontRenderingEnabled()
check if debug font rendering is enabled
int getFontHeight(const float fontSize) const
Get the height of a font (ascender+descender) in pixels.
int getFontAscender(const float fontSize) const
Get the ascender of the font in pixels.
std::string findFontFileWithFontconfig(const char *fontName)
Searches the font by using fontconfig (Linux only)
bool init()
Init with the default system font.
void drawString(const float dx, const float dy, const float fontSize, const float color[4], const char *string, const size_t length=0, const bool overlay=false, const bool shadow=true, const float *shadowColor=nullptr)
This function draws a simple string with no linefeeds.
bool isInitialized() const
Returns true if font loaded, otherwise false.
void cleanup()
Cleanup the fonts.
void doFontDraw(const float dx, const float dy, const float fontSize, const float color[4], const bool shadow, const char *asciiString, const wchar_t *optionalUnicodeString, const float *shadowColor)
Render the fonts.
Abstract base class for GLResources.
#define MLOPENGL_EXPORT
Macro to put all following stuff into the namespace ML_NAMESPACE to avoid collisions with symbols of ...