37#include <freetype/freetype.h>
40#include "IGUIEnvironment.h"
42#include "IVideoDriver.h"
94 void preload(u32 char_index, FT_Face face,
CGUITTFont *parent, u32 font_size,
const FT_Int32 loadFlags);
100 video::IImage*
createGlyphImage(
const FT_Bitmap &bits, video::IVideoDriver *driver)
const;
130 other.surface =
nullptr;
158 if (!glyph || !surface)
197 bool preload =
true, u32 shadow = 0, u32
shadow_alpha = 255);
228 void setFontHinting(
const bool enable,
const bool enable_auto_hinting =
true);
231 virtual void draw(
const core::stringw& utext,
const core::rect<s32>& position,
232 video::SColor color,
bool hcenter=
false,
bool vcenter=
false,
233 const core::rect<s32>* clip=0)
override;
236 bool hcenter=
false,
bool vcenter=
false,
237 const core::rect<s32>* clip=0);
240 virtual core::dimension2du
getDimension(
const wchar_t* text)
const override;
252 virtual core::vector2di
getKerning(
const wchar_t thisLetter,
const wchar_t previousLetter)
const override;
284 core::dimension2d<u32>
getDimension(
const std::u32string& text)
const;
292 const bool transparency,
const bool preload);
299 load_flags = FT_LOAD_DEFAULT | FT_LOAD_RENDER;
305 load_flags |= FT_LOAD_MONOCHROME | FT_LOAD_TARGET_MONO;
317 core::vector2di
getKerning(
const char32_t thisLetter,
const char32_t previousLetter)
const;
#define DISABLE_CLASS_COPY(C)
Definition basic_macros.h:26
Definition enriched_string.h:28
Class representing a TrueType font.
Definition CGUITTFont.h:187
static CGUITTFont * createTTFont(IGUIEnvironment *env, SGUITTFace *face, u32 size, bool antialias=true, bool preload=true, u32 shadow=0, u32 shadow_alpha=255)
Creates a new TrueType font and returns a pointer to it.
Definition CGUITTFont.cpp:283
video::IVideoDriver * Driver
Definition CGUITTFont.h:319
bool use_hinting
Definition CGUITTFont.h:276
u32 size
Definition CGUITTFont.h:278
virtual ~CGUITTFont()
Destructor.
Definition CGUITTFont.cpp:357
void setBatchLoadSize(u32 batch_size)
Sets the amount of glyphs to batch load.
Definition CGUITTFont.h:203
void setMonochrome(const bool flag)
Tells the font to use monochrome rendering.
Definition CGUITTFont.cpp:453
void setFontHinting(const bool enable, const bool enable_auto_hinting=true)
Enables or disables font hinting.
Definition CGUITTFont.cpp:459
virtual void draw(const core::stringw &utext, const core::rect< s32 > &position, video::SColor color, bool hcenter=false, bool vcenter=false, const core::rect< s32 > *clip=0) override
Draws some text and clips it to the specified rectangle if wanted.
Definition CGUITTFont.cpp:466
virtual void setInvisibleCharacters(const wchar_t *s) override
Define which characters should not be drawn by the font.
Definition CGUITTFont.cpp:879
bool use_auto_hinting
Definition CGUITTFont.h:277
FT_Face tt_face
Definition CGUITTFont.h:320
CGUITTGlyphPage * getLastGlyphPage() const
Get the last glyph page if there's still available slots.
Definition CGUITTFont.cpp:392
CGUITTGlyphPage * createGlyphPage(const u8 pixel_mode)
Create a new glyph page texture.
Definition CGUITTFont.cpp:402
bool useMonochrome() const
Check if the font is being loaded as a monochrome font.
Definition CGUITTFont.h:217
virtual core::dimension2du getDimension(const wchar_t *text) const override
Returns the dimension of a text string.
Definition CGUITTFont.cpp:642
void setFallback(gui::IGUIFont *font)
Set font that should be used for glyphs not present in ours.
Definition CGUITTFont.cpp:447
CGUITTFont(IGUIEnvironment *env)
Constructor.
Definition CGUITTFont.cpp:303
u32 getFontSize() const
Get the font size.
Definition CGUITTFont.h:206
u32 shadow_offset
Definition CGUITTFont.h:330
virtual void setKerningHeight(s32 kerning) override
Sets global kerning height for the font.
Definition CGUITTFont.cpp:824
bool use_monochrome
Definition CGUITTFont.h:275
u32 getLastGlyphPageIndex() const
Get the last glyph page's index.
Definition CGUITTFont.h:267
void update_load_flags()
Definition CGUITTFont.h:296
std::u32string InvisibleChars
Definition CGUITTFont.h:329
virtual core::vector2di getKerning(const wchar_t thisLetter, const wchar_t previousLetter) const override
Returns the distance between letters.
Definition CGUITTFont.cpp:829
u32 getWidthFromCharacter(char32_t c) const
Definition CGUITTFont.cpp:703
FT_Size_Metrics font_metrics
Definition CGUITTFont.h:321
u32 getGlyphIndexByChar(char32_t c) const
Returns (index + 1) of this->Glyphs Returns 0 if no such glyph is provided by the font.
Definition CGUITTFont.cpp:742
FT_Int32 load_flags
Definition CGUITTFont.h:322
s32 GlobalKerningWidth
Definition CGUITTFont.h:327
u32 getHeightFromCharacter(char32_t c) const
Definition CGUITTFont.cpp:722
virtual s32 getCharacterFromPos(const wchar_t *text, s32 pixel_x) const override
Calculates the index of the character in the text which is on a specific position.
Definition CGUITTFont.cpp:787
core::array< CGUITTGlyphPage * > Glyph_Pages
Definition CGUITTFont.h:324
void reset_images()
Definition CGUITTFont.cpp:368
u32 batch_load_size
Definition CGUITTFont.h:279
s32 GlobalKerningHeight
Definition CGUITTFont.h:328
core::array< SGUITTGlyph > Glyphs
Definition CGUITTFont.h:325
u32 shadow_alpha
Definition CGUITTFont.h:331
bool load(SGUITTFace *face, const u32 size, const bool antialias, const bool transparency, const bool preload)
Definition CGUITTFont.cpp:319
virtual void setKerningWidth(s32 kerning) override
Sets global kerning width for the font.
Definition CGUITTFont.cpp:819
u32 getLineHeight() const
Gets the overall font height, including a line gap of 1 px.
Definition CGUITTFont.h:311
void update_glyph_pages() const
Definition CGUITTFont.cpp:383
s32 getAscender() const
Definition CGUITTFont.h:272
std::u32string convertWCharToU32String(const wchar_t *const) const
Definition CGUITTFont.cpp:884
irr_ptr< gui::IGUIFont > fallback
Definition CGUITTFont.h:333
bool useAutoHinting() const
Check if the font auto-hinting is enabled.
Definition CGUITTFont.h:210
bool useHinting() const
Check if the font hinting is enabled.
Definition CGUITTFont.h:213
Holds a sheet of glyphs.
Definition CGUITTFont.h:139
io::path name
Definition CGUITTFont.h:182
video::ITexture * texture
Definition CGUITTFont.h:171
u32 available_slots
Definition CGUITTFont.h:172
std::vector< video::SColor > render_colors
Definition CGUITTFont.h:177
void pushGlyphToBePaged(const SGUITTGlyph *glyph, video::IImage *surface)
Add the glyph to a list of glyphs to be paged.
Definition CGUITTFont.h:156
bool isDirty() const
Definition CGUITTFont.h:163
video::IVideoDriver * driver
Definition CGUITTFont.h:181
std::vector< SGUITTGlyphPending > glyph_to_be_paged
Definition CGUITTFont.h:180
bool createPageTexture(u8 pixel_mode, core::dimension2du texture_size)
Create the actual page texture,.
Definition CGUITTFont.cpp:230
~CGUITTGlyphPage()
Definition CGUITTFont.h:145
void updateTexture()
Updates the texture atlas with new glyphs.
Definition CGUITTFont.cpp:260
std::vector< core::recti > render_source_rects
Definition CGUITTFont.h:176
std::vector< core::vector2di > render_positions
Definition CGUITTFont.h:175
u32 used_slots
Definition CGUITTFont.h:173
CGUITTGlyphPage(video::IVideoDriver *Driver, const io::path &texture_name)
Definition CGUITTFont.h:141
Definition fontengine.h:16
Definition CGUITTFont.h:54
static FT_Library getFreeTypeLibrary()
Definition CGUITTFont.cpp:50
std::string face_buffer
Definition CGUITTFont.h:64
static SGUITTFace * createFace(std::string &&buffer)
Definition CGUITTFont.cpp:79
static size_t n_faces
Definition CGUITTFont.h:58
static SGUITTFace * loadFace(const io::path &filename)
Definition CGUITTFont.cpp:91
FT_Face face
Definition CGUITTFont.h:70
static FT_Library freetype_library
Definition CGUITTFont.h:57
SGUITTFace(std::string &&buffer)
Definition CGUITTFont.cpp:61
~SGUITTFace()
Definition CGUITTFont.cpp:67
Wrapper struct for a preloaded glyph.
Definition CGUITTFont.h:116
video::IImage * surface
Definition CGUITTFont.h:134
SGUITTGlyphPending(const SGUITTGlyph *glyph, video::IImage *surface) noexcept
Definition CGUITTFont.h:117
const SGUITTGlyph * glyph
Definition CGUITTFont.h:133
~SGUITTGlyphPending()
Definition CGUITTFont.h:120
Structure representing a single TrueType glyph.
Definition CGUITTFont.h:79
core::vector2di offset
The offset of glyph when drawn.
Definition CGUITTFont.h:109
video::IImage * createGlyphImage(const FT_Bitmap &bits, video::IVideoDriver *driver) const
Creates the IImage object from the FT_Bitmap.
Definition CGUITTFont.cpp:103
SGUITTGlyph()
Definition CGUITTFont.h:80
~SGUITTGlyph()
Definition CGUITTFont.h:86
void preload(u32 char_index, FT_Face face, CGUITTFont *parent, u32 font_size, const FT_Int32 loadFlags)
Preload the glyph.
Definition CGUITTFont.cpp:176
void unload()
Unloads the glyph.
Definition CGUITTFont.cpp:224
core::recti source_rect
The source rectangle for the glyph.
Definition CGUITTFont.h:106
bool isLoaded() const
If true, the glyph has been loaded.
Definition CGUITTFont.h:89
core::vector2di advance
Glyph advance information.
Definition CGUITTFont.h:112
u32 glyph_page
The page the glyph is on.
Definition CGUITTFont.h:103