Crazy Eddies GUI System  0.6.0
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
CEGUI::FreeTypeFont Class Reference

Implementation of the Font class interface using the FreeType library. More...

+ Inheritance diagram for CEGUI::FreeTypeFont:
+ Collaboration diagram for CEGUI::FreeTypeFont:

Public Member Functions

virtual void load ()
 Complete font loading. If you create the font from an XML file, this method is invoked automatically after reading all the required data from the XMLAttributes object. If you create the font manually, it is your responsability to call this function as soon as you set up all the appropiate fields of the Font object. More...
 
virtual void rasterize (utf32 start_codepoint, utf32 end_codepoint)
 This function prepares a certain range of glyphs to be ready for displaying. This means that after returning from this function glyphs from d_cp_map[start_codepoint] to d_cp_map[end_codepoint] should have their d_image member set. If there is an error during rasterization of some glyph, it's okay to leave the d_image field set to NULL, in which case such glyphs will be skipped from display. More...
 
- Public Member Functions inherited from CEGUI::Font
bool isCodepointAvailable (utf32 cp) const
 Return whether this Font can draw the specified code-point. More...
 
size_t drawText (const String &text, const Rect &draw_area, float z, const Rect &clip_rect, TextFormatting fmt, const ColourRect &colours, float x_scale=1.0f, float y_scale=1.0f)
 Draw text into a specified area of the display. More...
 
size_t drawText (const String &text, const Rect &draw_area, float z, const Rect &clip_rect, TextFormatting fmt, float x_scale=1.0f, float y_scale=1.0f)
 Draw text into a specified area of the display using default colours. More...
 
void drawText (const String &text, const Rect &draw_area, float z, const Rect &clip_rect, float x_scale=1.0f, float y_scale=1.0f)
 Draw text into a specified area of the display with default colours and default formatting (LeftAligned). More...
 
size_t drawText (const String &text, const Rect &draw_area, float z, TextFormatting fmt, const ColourRect &colours, float x_scale=1.0f, float y_scale=1.0f)
 Draw text into a specified area of the display. More...
 
size_t drawText (const String &text, const Rect &draw_area, float z, TextFormatting fmt, float x_scale=1.0f, float y_scale=1.0f)
 Draw text into a specified area of the display with default colours. More...
 
void drawText (const String &text, const Rect &draw_area, float z, float x_scale=1.0f, float y_scale=1.0f)
 Draw text into a specified area of the display with default colours and default formatting (LeftAligned). More...
 
void drawText (const String &text, const Vector3 &position, const Rect &clip_rect, const ColourRect &colours, float x_scale=1.0f, float y_scale=1.0f)
 Draw text at the specified location. More...
 
void drawText (const String &text, const Vector3 &position, const Rect &clip_rect, float x_scale=1.0f, float y_scale=1.0f)
 Draw text at the specified location with default colours. More...
 
virtual void setNativeResolution (const Size &size)
 Set the native resolution for this Font. More...
 
virtual void notifyScreenResolution (const Size &size)
 Notify the Font of the current (usually new) display resolution. More...
 
float getLineSpacing (float y_scale=1.0f) const
 Return the pixel line spacing value for. More...
 
float getFontHeight (float y_scale=1.0f) const
 return the exact pixel height of the font. More...
 
float getBaseline (float y_scale=1.0f) const
 Return the number of pixels from the top of the highest glyph to the baseline. More...
 
float getTextExtent (const String &text, float x_scale=1.0f)
 Return the pixel width of the specified text if rendered with this Font. More...
 
size_t getCharAtPixel (const String &text, float pixel, float x_scale=1.0f)
 Return the index of the closest text character in String text that corresponds to pixel location pixel if the text were rendered. More...
 
size_t getCharAtPixel (const String &text, size_t start_char, float pixel, float x_scale=1.0f)
 Return the index of the closest text character in String text, starting at character index start_char, that corresponds to pixel location pixel if the text were to be rendered. More...
 
size_t getFormattedLineCount (const String &text, const Rect &format_area, TextFormatting fmt, float x_scale=1.0f)
 Return the number of lines the given text would be formatted to. More...
 
float getFormattedTextExtent (const String &text, const Rect &format_area, TextFormatting fmt, float x_scale=1.0f)
 Return the horizontal pixel extent given text would be formatted to. More...
 
- Public Member Functions inherited from CEGUI::PropertySet
 PropertySet (void)
 Constructs a new PropertySet object.
 
virtual ~PropertySet (void)
 Destructor for PropertySet objects.
 
void addProperty (Property *property)
 Adds a new Property to the PropertySet. More...
 
void removeProperty (const String &name)
 Removes a Property from the PropertySet. More...
 
void clearProperties (void)
 Removes all Property objects from the PropertySet. More...
 
bool isPropertyPresent (const String &name) const
 Checks to see if a Property with the given name is in the PropertySet. More...
 
const StringgetPropertyHelp (const String &name) const
 Return the help text for the specified Property. More...
 
String getProperty (const String &name) const
 Gets the current value of the specified Property. More...
 
void setProperty (const String &name, const String &value)
 Sets the current value of a Property. More...
 
bool isPropertyDefault (const String &name) const
 Returns whether a Property is at it's default value. More...
 
String getPropertyDefault (const String &name) const
 Returns the default value of a Property as a String. More...
 
Iterator getIterator (void) const
 Return a PropertySet::Iterator object to iterate over the available Properties.
 

Protected Types

typedef std::vector< Imageset * > ImagesetVector
 
- Protected Types inherited from CEGUI::Font
typedef std::map< utf32,
FontGlyph
CodepointMap
 

Protected Member Functions

void drawGlyphToBuffer (argb_t *buffer, uint buf_width)
 Copy the current glyph data into buffer, which has a width of buf_width pixels (not bytes). More...
 
uint getTextureSize (CodepointMap::const_iterator s, CodepointMap::const_iterator e)
 Return the required texture size required to store imagery for the glyphs from s to e. More...
 
 FreeTypeFont (const String &name, const String &filename, const String &resourceGroup)
 Constructs a new semi-complete Font object. It is the responsability of the user to set up all remaining font parameters after constructing the Font object, and finally calling the load() method which will make font available for use. All font parameters that are not initialized are set to sensible default values. More...
 
 FreeTypeFont (const XMLAttributes &attributes)
 Constructs a new semi-complete Font object. It is the responsability of the user to set up all remaining font parameters after constructing the Font object, and finally calling the load() method which will make font available for use. All font parameters that are not initialized are set to sensible default values. More...
 
virtual ~FreeTypeFont ()
 Destroys a Font object. More...
 
virtual void updateFont ()
 Update the font as required according to the current parameters. More...
 
virtual void writeXMLToStream_impl (XMLSerializer &xml_stream) const
 Same as writeXMLToStream() but called from inside writeXMLToStream() so that derived classes may add their own attributes to stream. More...
 
void addFreeTypeFontProperties ()
 Register all properties of this class.
 
void free ()
 Free all allocated font data.
 
- Protected Member Functions inherited from CEGUI::Font
 Font (const String &name, const String &fontname, const String &resourceGroup="")
 Constructs a new semi-complete Font object. It is the responsability of the user to set up all remaining font parameters after constructing the Font object, and finally calling the load() method which will make font available for use. All font parameters that are not initialized are set to sensible default values. More...
 
 Font (const XMLAttributes &attributes)
 Constructs a new Font object and instantly loads it. The font is ready for use right after creation, there is no need to load() it. All data required by this font is loaded from the provided XMLAttributes object. More...
 
virtual ~Font ()
 Destroys a Font object.
 
virtual void defineMapping (const XMLAttributes &attributes)
 Define a glyph mapping (handle a <Mapping> XML element)
 
size_t drawWrappedText (const String &text, const Rect &draw_area, float z, const Rect &clip_rect, TextFormatting fmt, const ColourRect &colours, float x_scale=1.0f, float y_scale=1.0f)
 draws wrapped text. returns number of lines output.
 
size_t getNextWord (const String &in_string, size_t start_idx, String &out_string) const
 helper function for renderWrappedText to get next word of a string
 
void drawTextLine (const String &text, const Vector3 &position, const Rect &clip_rect, const ColourRect &colours, float x_scale=1.0f, float y_scale=1.0f)
 Draw a line of text. No formatting is applied.
 
void drawTextLineJustified (const String &text, const Rect &draw_area, const Vector3 &position, const Rect &clip_rect, const ColourRect &colours, float x_scale=1.0f, float y_scale=1.0f)
 Draw a justified line of text.
 
float getWrappedTextExtent (const String &text, float wrapWidth, float x_scale=1.0f)
 returns extent of widest line of wrapped text.
 
const FontGlyphgetGlyphData (utf32 codepoint)
 Return a pointer to the glyphDat struct for the given codepoint, or 0 if the codepoint does not have a glyph defined. More...
 
void setMaxCodepoint (utf32 codepoint)
 Set the maximal glyph index. This reserves the respective number of bits in the d_glyphPageLoaded array.
 
void writeXMLToStream (XMLSerializer &xml_stream) const
 Writes an xml representation of this Font to out_stream. More...
 
void addFontProperties ()
 Register all properties of this class.
 

Protected Attributes

ImagesetVector d_glyphImages
 Imagesets that holds the glyphs for this font.
 
float d_ptSize
 Point size of font.
 
bool d_antiAliased
 True if the font should be rendered as anti-alaised by freeType.
 
FT_Face d_fontFace
 FreeType-specific font handle.
 
RawDataContainer d_fontData
 Font file data.
 
- Protected Attributes inherited from CEGUI::Font
CodepointMap d_cp_map
 Contains mappings from code points to Image objects.
 
String d_name
 Name of this font.
 
String d_fileName
 Holds the name of the file used to create this font (either font file or imagset)
 
String d_resourceGroup
 Holds the name of the font file's resource group.
 
float d_ascender
 maximal font ascender (pixels above the baseline)
 
float d_descender
 maximal font descender (negative pixels below the baseline)
 
float d_height
 (ascender - descender) + linegap
 
bool d_autoScale
 true when auto-scaling is enabled.
 
float d_horzScaling
 current horizontal scaling factor.
 
float d_vertScaling
 current vertical scaling factor.
 
float d_nativeHorzRes
 native horizontal resolution for this Imageset.
 
float d_nativeVertRes
 native vertical resolution for this Imageset.
 
utf32 d_maxCodepoint
 Maximal codepoint for font glyphs.
 
uint * d_glyphPageLoaded
 This bitmap holds information about loaded 'pages' of glyphs. A glyph page is a set of 256 codepoints, starting at 256-multiples. For example, the 1st glyph page is 0-255, fourth is 1024-1279 etc. When a specific glyph is required for painting, the corresponding bit is checked to see if the respective page has been rasterized. If not, the rasterize() method is invoked, which prepares the glyphs from the respective glyph page for being painted. More...
 

Friends

class FontManager
 
class FontProperties::FreeTypePointSize
 
class FontProperties::FreeTypeAntialiased
 

Additional Inherited Members

- Public Types inherited from CEGUI::PropertySet
typedef ConstBaseIterator
< PropertyRegistry > 
Iterator
 
- Static Public Member Functions inherited from CEGUI::Font
static void setDefaultResourceGroup (const String &resourceGroup)
 Sets the default resource group to be used when loading font data. More...
 
static const StringgetDefaultResourceGroup ()
 Returns the default resource group currently set for Fonts. More...
 
- Static Public Attributes inherited from CEGUI::Font
static const argb_t DefaultColour = 0xFFFFFFFF
 Colour value used whenever a colour is not specified.
 
- Static Protected Attributes inherited from CEGUI::Font
static String d_defaultResourceGroup
 hold default resource group for font loading.
 

Detailed Description

Implementation of the Font class interface using the FreeType library.

This implementation tries to provide maximal support for any kind of fonts supported by FreeType. It has been tested on outline font formats like TTF and PS as well as on bitmap font formats like PCF and FON.

Glyphs are rendered dynamically on demand, so a large font with lots of glyphs won't slow application startup time.

Constructor & Destructor Documentation

CEGUI::FreeTypeFont::FreeTypeFont ( const String name,
const String filename,
const String resourceGroup 
)
protected

Constructs a new semi-complete Font object. It is the responsability of the user to set up all remaining font parameters after constructing the Font object, and finally calling the load() method which will make font available for use. All font parameters that are not initialized are set to sensible default values.

Parameters
nameThe unique name that will be used to identify this Font.
fontnameThe filename of the font file, which contains the font data. This can be a TrueType, PostScript, bitmap font etc file.
resourceGroupResource group identifier to be passed to the resource provider to load the font definition file.

References addFreeTypeFontProperties().

CEGUI::FreeTypeFont::FreeTypeFont ( const XMLAttributes attributes)
protected

Constructs a new semi-complete Font object. It is the responsability of the user to set up all remaining font parameters after constructing the Font object, and finally calling the load() method which will make font available for use. All font parameters that are not initialized are set to sensible default values.

Parameters
nameThe unique name that will be used to identify this Font.
fontnameThe filename of the font file, which contains the font data. This can be a TrueType, PostScript, bitmap font etc file.
resourceGroupResource group identifier to be passed to the resource provider to load the font definition file.

References addFreeTypeFontProperties().

CEGUI::FreeTypeFont::~FreeTypeFont ( )
protectedvirtual

Destroys a Font object.

References free().

Member Function Documentation

void CEGUI::FreeTypeFont::drawGlyphToBuffer ( argb_t buffer,
uint  buf_width 
)
protected

Copy the current glyph data into buffer, which has a width of buf_width pixels (not bytes).

Parameters
bufferMemory buffer large enough to receive the imagery for the currently loaded glyph.
buf_widthWidth of buffer in pixels (where each pixel is a argb_t).
Returns
Nothing.

References d_fontFace.

Referenced by rasterize().

uint CEGUI::FreeTypeFont::getTextureSize ( CodepointMap::const_iterator  s,
CodepointMap::const_iterator  e 
)
protected

Return the required texture size required to store imagery for the glyphs from s to e.

Parameters
sThe first glyph in set
eThe last glyph in set

References d_fontFace, CEGUI::Renderer::getMaxTextureSize(), CEGUI::System::getRenderer(), and CEGUI::System::getSingleton().

Referenced by rasterize().

void CEGUI::FreeTypeFont::load ( )
virtual

Complete font loading. If you create the font from an XML file, this method is invoked automatically after reading all the required data from the XMLAttributes object. If you create the font manually, it is your responsability to call this function as soon as you set up all the appropiate fields of the Font object.

Implements CEGUI::Font.

References CEGUI::Font::d_cp_map, CEGUI::Font::d_fileName, CEGUI::Font::d_name, d_ptSize, CEGUI::Font::d_resourceGroup, CEGUI::String::empty(), and updateFont().

void CEGUI::FreeTypeFont::rasterize ( utf32  start_codepoint,
utf32  end_codepoint 
)
virtual

This function prepares a certain range of glyphs to be ready for displaying. This means that after returning from this function glyphs from d_cp_map[start_codepoint] to d_cp_map[end_codepoint] should have their d_image member set. If there is an error during rasterization of some glyph, it's okay to leave the d_image field set to NULL, in which case such glyphs will be skipped from display.

Parameters
start_codepointThe lowest codepoint that should be rasterized
end_codepointThe highest codepoint that should be rasterized

Reimplemented from CEGUI::Font.

References CEGUI::Renderer::createTexture(), d_antiAliased, CEGUI::Font::d_cp_map, d_fontFace, d_glyphImages, CEGUI::Font::d_name, CEGUI::Imageset::defineImage(), drawGlyphToBuffer(), CEGUI::Errors, CEGUI::Imageset::getImage(), CEGUI::System::getRenderer(), CEGUI::System::getSingleton(), CEGUI::Imageset::getTexture(), getTextureSize(), CEGUI::Texture::loadFromMemory(), and CEGUI::Texture::PF_RGBA.

void CEGUI::FreeTypeFont::updateFont ( )
protectedvirtual
void CEGUI::FreeTypeFont::writeXMLToStream_impl ( XMLSerializer xml_stream) const
protectedvirtual

Same as writeXMLToStream() but called from inside writeXMLToStream() so that derived classes may add their own attributes to stream.

Parameters
xml_streamStream where xml data should be output.

Implements CEGUI::Font.

References CEGUI::XMLSerializer::attribute(), d_antiAliased, and d_ptSize.