FontSystem Class Reference

Wrapper class for the libfreetype library. More...

#include <freetype.h>

List of all members.

Public Member Functions

 FontSystem (FT_UInt pointSize, u8 textureFormat=GX_TF_RGBA8)
 ~FontSystem ()
u16 drawText (u16 x, u16 y, char *text)
u16 drawText (u16 x, u16 y, char const *text)
u16 drawText (u16 x, u16 y, char *text, u32 *videoBuffer, u16 videoBufferWidth)
u16 drawText (u16 x, u16 y, char const *text, u32 *videoBuffer, u16 videoBufferWidth)

Private Member Functions

void cacheFontData ()
void loadFontData (FT_Bitmap *bmp, fontCharData *charData)
void converBufferToRGBA8 (u32 *glyphData, fontCharData *charData)
void copyTextureToFramebuffer (GXTexObj *texObj, u16 texWidth, u16 texHeight, u16 screenX, u16 screenY)
void drawCharacter (u16 x, u16 y, fontCharData *charData, u32 *videoBuffer, u16 videoBufferWidth)

Private Attributes

FT_Library ftLibrary
FT_Face ftFace
FT_GlyphSlot ftSlot
u8 textureFormat
std::map< char, fontCharDatafontData


Detailed Description

Wrapper class for the libfreetype library.

Constructor & Destructor Documentation

FontSystem::FontSystem ( FT_UInt  pointSize,
u8  textureFormat = GX_TF_RGBA8 
)

Default constructor for the FontSystem class.

Parameters:
pointSize The desired point size this wrapper's configured font face.
textureFormat The format (GX_TF_*) of the texture as defined by the libogc gx.h header file. Default value is GX_TF_RGBA8.

FontSystem::~FontSystem (  ) 

Default destructor for the FontSystem class.


Member Function Documentation

void FontSystem::cacheFontData (  )  [private]

Locates each character in this wrapper's configured font face and proccess them.

This routine locates each character in the configured font face and renders the glyph's bitmap. Each bitmap and relevant information is loaded into its own quickly addressible structure within an instance-specific map.

void FontSystem::loadFontData ( FT_Bitmap *  bmp,
fontCharData charData 
) [private]

Loads the rendered bitmap into the relevant structure's data buffer.

This routine does a simple byte-wise copy of the glyph's rendered 8-bit grayscale bitmap into the structure's buffer. Each byte is converted from the bitmap's intensity value into the a u32 RGBA value.

Parameters:
bmp A pointer to the most recently rendered glyph's bitmap.
charData A pointer to an allocated fontCharData structure whose data represent that of the last rendered glyph.

void FontSystem::converBufferToRGBA8 ( u32 *  glyphData,
fontCharData charData 
) [private]

Convert the specified glyph data buffer into the RGBA8 texture format

This routine converts the temporary RGBA data buffer into the RGBA8 texture format within the character storage structure. Although many RGBA->RGBA8 routines were tested the only that finally worked came from the GRRLIB Wii library and is fully attributed to its author NoNameNo.

Parameters:
glyphData Buffer containing the temporarily rendered RGBA data for the current glyph.
charData A pointer to an allocated fontCharData structure whose data represent that of the desired character

void FontSystem::copyTextureToFramebuffer ( GXTexObj *  texObj,
u16  texWidth,
u16  texHeight,
u16  screenX,
u16  screenY 
) [private]

Copies the supplied texture quad to the EFB.

This routine uses the in-built GX quad builder functions to define the texture bounds and location on the EFB target.

Parameters:
texObj A pointer to the glyph's initialized texture object.
texWidth The pixel width of the texture object.
texHeight The pixel height of the texture object.
screenX The screen X coordinate at which to output the rendered texture.
screenY The screen Y coordinate at which to output the rendered texture

void FontSystem::drawCharacter ( u16  x,
u16  y,
fontCharData charData,
u32 *  videoBuffer,
u16  videoBufferWidth 
) [private]

Renders the bitmap buffer from the supplied structure directly into the supplied XFB.

This routine performs a u32-wise copy from the glyphs bitmap buffer directly into the supplied XFB. Note that since this routine must process the entire buffer each time it is called on larger fonts peformance will be highly degraded and its use overall lacks an optimal flair. At most this routine should only be used for debugging purposes.

Parameters:
x Screen X coordinate at which to output the text.
y Screen Y coordinate at which to output the text.
charData A pointer to an allocated fontCharData structure whose data represent that of the desired character.
videoBuffer The XFB in which to render the glyph's bitmap.
videoBufferWidth The pixel width of the XFB referenced by videoBuffer.

u16 FontSystem::drawText ( u16  x,
u16  y,
char *  text 
)

Processes the supplied text string and prints the results at the specified coordinates.

This routine processes each character of the supplied text string, loads the relevant preprocessed bitmap buffer, a texture from said buffer, and loads the resultant texture into the EFB. Since this routine utilizes a preprocess methodology and in-built GX texture functions rendering performance should be very high.

Parameters:
x Screen X coordinate at which to output the text.
y Screen Y coordinate at which to output the text.
text NULL terminated string to output.
Returns:
The number of characters printed.

u16 FontSystem::drawText ( u16  x,
u16  y,
char const *  text 
)

Processes the supplied text string and prints the results at the specified coordinates.

Overloaded utility version of the performant drawText function which accepts a char const text string.

Parameters:
x Screen X coordinate at which to output the text.
y Screen Y coordinate at which to output the text.
text NULL terminated string to output.
Returns:
The number of characters printed.

u16 FontSystem::drawText ( u16  x,
u16  y,
char *  text,
u32 *  videoBuffer,
u16  videoBufferWidth 
)

Processes the supplied text string and prints the results at the specified coordinates.

This routine processes each character of the supplied text string, loads the relevant preprocessed bitmap buffer and renders the bitmap buffer directly into the supplied XFB using a much slower pixel-based copy function.

Parameters:
x Screen X coordinate at which to output the text.
y Screen Y coordinate at which to output the text.
text NULL terminated string to output.
videoBuffer The XFB in which to render the glyph's bitmap.
videoBufferWidth The pixel width of the XFB referenced by videoBuffer.
Returns:
The number of characters printed.

u16 FontSystem::drawText ( u16  x,
u16  y,
char const *  text,
u32 *  videoBuffer,
u16  videoBufferWidth 
)

Processes the supplied text string and prints the results at the specified coordinates.

Overloaded utility version of the non-performant drawText function which accepts a char const text string.

Parameters:
x Screen X coordinate at which to output the text.
y Screen Y coordinate at which to output the text.
text NULL terminated string to output.
videoBuffer The XFB in which to render the glyph's bitmap.
videoBufferWidth The pixel width of the XFB referenced by videoBuffer.
Returns:
The number of characters printed.


Member Data Documentation

FT_Library FontSystem::ftLibrary [private]

FreeType FT_Library instance.

FT_Face FontSystem::ftFace [private]

FreeType reusable FT_Face typographic object.

FT_GlyphSlot FontSystem::ftSlot [private]

FreeType reusable FT_GlyphSlot glyph container object.

Defined texture format of the target EFB.

std::map<char, fontCharData> FontSystem::fontData [private]

Map which holds the glyph data structures for the corresponding characters.


The documentation for this class was generated from the following files:

Generated on Fri Nov 28 15:24:37 2008 by  doxygen 1.5.6