Public Member Functions
GUI::Font Class Reference

Class that encapsulates text rendering functionality for a typeface. More...

List of all members.

Public Member Functions

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.
bool isCodepointAvailable (int cp)
 Return whether this Font can draw the specified code-point.
void drawText (string text, Rect draw_area, float z=1.0, float x_scale=1.0, float y_scale=1.0)
void setNativeResolution (Size size)
 Set the native resolution for this Font.
void notifyScreenResolution (Size size)
 Notify the Font of the current (usually new) display resolution.
float getLineSpacing (float y_scale=1.0)
 Return the pixel line spacing value for.
float getFontHeight (float y_scale=1.0)
 return the exact pixel height of the font.
float getTextExtent (string text, float x_scale=1.0)
 Return the pixel width of the specified text if rendered with this Font.
int getCharAtPixel (string text, float pixel, float x_scale=1.0)
 Return the index of the closest text character in String text that corresponds to pixel location pixel if the text were rendered.
int getCharAtPixel (string text, int start_char, float pixel, float x_scale=1.0)
 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.
int getFormattedLineCount (string text, Rect format_area, int fmt, float x_scale=1.0)
 Return the number of lines the given text would be formatted to.
float getFormattedTextExtent (string text, Rect format_area, int fmt, float x_scale=1.0)
 Return the horizontal pixel extent given text would be formatted to.
void setDefaultResourceGroup (string resourceGroup)
 Sets the default resource group to be used when loading font data.
string getDefaultResourceGroup ()
 Returns the default resource group currently set for Fonts.

Detailed Description

Class that encapsulates text rendering functionality for a typeface.

A Font object is created for each unique typeface required. The Font class provides methods for loading typefaces from various sources, and then for outputting text via the Renderer object.

This class is not specific to any font renderer, it just provides the basic interfaces needed to manage fonts.


Member Function Documentation

bool GUI::Font::isCodepointAvailable ( int  cp)

Return whether this Font can draw the specified code-point.

Parameters:
cputf32 code point that is the subject of the query.
Returns:
true if the font contains a mapping for code point cp, false if it does not contain a mapping for cp.
void GUI::Font::setNativeResolution ( Size  size)

Set the native resolution for this Font.

Parameters:
sizeSize object describing the new native screen resolution for this Font.
Returns:
Nothing
void GUI::Font::notifyScreenResolution ( Size  size)

Notify the Font of the current (usually new) display resolution.

Parameters:
sizeSize object describing the display resolution
Returns:
Nothing
float GUI::Font::getLineSpacing ( float  y_scale = 1.0)

Return the pixel line spacing value for.

Parameters:
y_scaleScaling factor to be applied to the line spacing, where 1.0f is considered to be 'normal'.
Returns:
Number of pixels between vertical base lines, i.e. The minimum pixel space between two lines of text.
float GUI::Font::getFontHeight ( float  y_scale = 1.0)

return the exact pixel height of the font.

Parameters:
y_scaleScaling factor to be applied to the height, where 1.0f is considered to be 'normal'.
Returns:
float value describing the pixel height of the font without any additional padding.
float GUI::Font::getTextExtent ( string  text,
float  x_scale = 1.0 
)

Return the pixel width of the specified text if rendered with this Font.

Parameters:
textString object containing the text to return the rendered pixel width for.
x_scaleScaling factor to be applied to each glyph's x axis when measuring the extent, where 1.0f is considered to be 'normal'.
Returns:
Number of pixels that text will occupy when rendered with this Font.
int GUI::Font::getCharAtPixel ( string  text,
float  pixel,
float  x_scale = 1.0 
)

Return the index of the closest text character in String text that corresponds to pixel location pixel if the text were rendered.

Parameters:
textString object containing the text.
pixelSpecifies the (horizontal) pixel offset to return the character index for.
x_scaleScaling factor to be applied to each glyph's x axis when measuring the text extent, where 1.0f is considered to be 'normal'.
Returns:
Returns a character index into String text for the character that would be rendered closest to horizontal pixel offset pixel if the text were to be rendered via this Font. Range of the return is from 0 to text.length(), so may actually return an index past the end of the string, which indicates pixel was beyond the last character.
int GUI::Font::getCharAtPixel ( string  text,
int  start_char,
float  pixel,
float  x_scale = 1.0 
)

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.

Parameters:
textString object containing the text.
start_charindex of the first character to consider. This is the lowest value that will be returned from the call.
pixelSpecifies the (horizontal) pixel offset to return the character index for.
x_scaleScaling factor to be applied to each glyph's x axis when measuring the text extent, where 1.0f is considered to be 'normal'.
Returns:
Returns a character index into String text for the character that would be rendered closest to horizontal pixel offset pixel if the text were to be rendered via this Font. Range of the return is from 0 to text.length(), so may actually return an index past the end of the string, which indicates pixel was beyond the last character.
int GUI::Font::getFormattedLineCount ( string  text,
Rect  format_area,
int  fmt,
float  x_scale = 1.0 
)

Return the number of lines the given text would be formatted to.

Since text formatting can result in multiple lines of text being output, it can be useful to know how many lines would be output without actually rendering the text.

Parameters:
textString object containing the text to be measured.
format_areaRect object describing the area to be used when formatting the text depending upon the option specified in fmt.
fmtOne of the TextFormatting values specifying the text formatting required.
x_scaleScaling factor to be applied to each glyph's x axis, where 1.0f is considered to be 'normal'.
Returns:
The number of lines produced from the specified formatting
float GUI::Font::getFormattedTextExtent ( string  text,
Rect  format_area,
int  fmt,
float  x_scale = 1.0 
)

Return the horizontal pixel extent given text would be formatted to.

The value return by this method is basically the extent of the widest line within the formatted text.

Parameters:
textString object containing the text to be measured.
format_areaRect object describing the area to be used when formatting the text depending upon the option specified in fmt.
fmtOne of the TextFormatting values specifying the text formatting required.
x_scaleScaling factor to be applied to each glyph's x axis, where 1.0f is considered to be 'normal'.
Returns:
The widest pixel extent of the lines produced from the specified formatting.
void GUI::Font::setDefaultResourceGroup ( string  resourceGroup)

Sets the default resource group to be used when loading font data.

Parameters:
resourceGroupString describing the default resource group identifier to be used.
Returns:
Nothing.
string GUI::Font::getDefaultResourceGroup ( )

Returns the default resource group currently set for Fonts.

Returns:
String describing the default resource group identifier that will be used when loading font data.