This class is discussed in the following forum-thread: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=6&t=37296
Changes by Michael Zeilfelder to adapt it to HCraft:
- Remove ustring (otherwise I risk converting strings twice in my project as they are UCS-2 or UCS-4 already)
- Remove const-ref in places where it makes no sense
- Remove additional create functions and keep just one. Pass only the parameters actually needed to it.
- Removing allocater as I get memory-leaks and don't understand what the allocater was meant for.
- Glyph_Pages no longer mutable (doesn't seem to need that)
- remove textscenenodes. Probably shouldn't be in this class and make understanding it harder.
- remove createTextureFromChar (it also had a memory leak probably as it wasn't dropping pageholder)
- remove Glyphs.set_free_when_destroyed(false). That function prevents clearing the array - it's not about pointers. Rather fix SGUITTGlyph (which didn't care about rule of three).
- don't drop the driver (not grabbed - but I changed that stuff a lot so might not have been there originally)
- remove a few memory re-allocations in drawing
- CGUITTGlyphPage::updateTexture replaced dirtyflag by check for glpyhs to handle
- CGUITTGlyphPage::updateTexture works with ::texture->getSize() instead of getOriginalSize. Same result in this case, but more correct.
TODO:
- Hinting should be one enum with explanation (have to figure it out first, results are strange currently when I enable it)
- max_font_height shouldn't have to be calculated each time. Set test-characters when font-size can change. And update each time getHeightFromCharacter is called.
*/
#ifndef __C_GUI_TTFONT_H_INCLUDED__
#define __C_GUI_TTFONT_H_INCLUDED__
#include <irrlicht.h>
#include <ft2build.h>
#include FT_FREETYPE_H // official way to include freetype.h correct according to freetype documenation
// TODO: Shouldn't be in irr namespace as long as it's not in the engine (but leaving it for now in the hope that will change)
namespaceirr
{
namespacegui
{
structSGUITTFace;
classCGUITTFont;
//! Structure representing a single TrueType glyph.
structSGUITTGlyph
{
#include "irrUString.h"
#include FT_FREETYPE_H
namespaceirr{
namespacegui{
structSGUITTFace;
classCGUITTFont;
//! Class to assist in deleting glyphs.
classCGUITTAssistDelete{
public:
template<classT,typenameTAlloc>
staticvoidDelete(core::array<T,TAlloc>&a){
TAllocallocator;
allocator.deallocate(a.pointer());
}
};
//! Structure representing a single TrueType glyph.
//currently, if we failed to create the image, just ignore this operation.
}
}
}
texture->unlock();
pageholder->drop();
texture->unlock();
glyph_to_be_paged.clear();
dirty=false;
}
video::ITexture*texture;
u32available_slots;
u32used_slots;
booldirty;
core::array<core::vector2di>render_positions;
core::array<core::recti>render_source_rects;
private:
core::dimension2dutexture_size;
u8pixel_mode;
private:
core::array<constSGUITTGlyph*>glyph_to_be_paged;
video::IVideoDriver*driver;
io::pathname;
};
};
//! Class representing a TrueType font.
classCGUITTFont:publicIGUIFont
{
public:
//! Class representing a TrueType font.
classCGUITTFont:publicIGUIFont{
public:
//! Creates a new TrueType font and returns a pointer to it. The pointer must be drop()'ed when finished.
//! \param driver Irrlicht video driver
//! \param fileSystem Irrlicht filesystem
//! \param env The IGUIEnvironment the font loads out of.
//! \param filename The filename of the font.
//! \param size The size of the font glyphs in pixels. Since this is the size of the individual glyphs, the true height of the font may change depending on the characters used.
//! \param antialias set the use_monochrome (opposite to antialias) flag
//! \param transparency set the use_transparency flag
//! \param invisibleChars Set characters which don't need drawing (speed optimization)
//! \param logger Irrlicht logging, for printing out additinal warnings/errors
//! \return Returns a pointer to a CGUITTFont. Will return 0 if the font failed to load.
//! Finds first position of a character not in a given list.
//! \param c A list of characters to NOT find. For example if the method should find the first occurrence of a character not 'a' or 'b', this parameter should be "ab".
//! \param count The amount of characters in the list. Usually, this should be strlen(c).
//! \return Position where the character has been found, or -1 if not found.
//! Finds last position of a character not in a given list.
//! \param c A list of characters to NOT find. For example if the method should find the first occurrence of a character not 'a' or 'b', this parameter should be "ab".
//! \param count The amount of characters in the list. Usually, this should be strlen(c).
//! \return Position where the character has been found, or -1 if not found.