ork::Font Class Reference
[util]

Helper class to draw text in a given font. More...

#include <Font.h>

Inheritance diagram for ork::Font:
ork::Object

List of all members.

Classes

struct  Vertex
 Vertex format for a text mesh. More...

Public Member Functions

 Font (ptr< Texture2D > fontTex, int nCols, int nRows, int minChar, int maxChar, int invalidChar, bool fixedWidth, std::vector< int > charWidths)
 Creates a new Font.
virtual ~Font ()
 Deletes this Font.
ptr< Texture2DgetImage () const
 Returns the texture containing the image of this font.
float getTileWidth () const
 Returns the width of a character tile.
float getTileHeight () const
 Returns the height of a character tile.
float getTileAspectRatio () const
 Returns the aspect ratio of a character tile.
float getCharWidth (char c) const
 Returns the space between this char and the next one.
vec2f getSize (const string &line, float height) const
 Returns the size of a given line of text.
vec2f addLine (const vec4f &viewport, float xs, float ys, const string &line, float height, int color, ptr< Mesh< Vertex, unsigned int > > textMesh)
 Add a given line of text in a given Mesh and returns the final position of the line.
vec2f addCenteredLine (const vec4f &viewport, float xs, float ys, const string &line, float height, int color, ptr< Mesh< Vertex, unsigned int > > textMesh)
 Add a given line of text in a given Mesh centered at a given position and returns the size of the line.

Protected Member Functions

 Font ()
 Creates an uninitialized Font.
virtual void init (ptr< Texture2D > fontTex, int nCols, int nRows, int minChar, int maxChar, int invalidChar, bool fixedWidth, std::vector< int > charWidths)
 Initializes the fields of a Font.
int charCount (char c) const
 Get the tile index for this character.

Protected Attributes

ptr< Texture2DfontTex
 The Texture2D which contains the images of the font.
int nCols
 The number of character columns in the texture.
int nRows
 The number of character rows in the texture.
int minChar
 The first ascii char code to take into account.
int maxChar
 The last ascii char code to take into account.
int invalidChar
 The character to be used to display invalid characters.
bool fixedWidth
 If the font has fixed-width characters.
std::vector< int > charWidths
 The width of a char (in texels).

Detailed Description

Helper class to draw text in a given font.

A Font allows to easily write a line of text directly in a FrameBuffer at a given position. It has a texture containing ascii chars, and knows which can be displayed. Any character outside its range will be displayed as a blank character defined in the texture (for example a square, or a question mark).


Constructor & Destructor Documentation

ork::Font::Font ( ptr< Texture2D fontTex,
int  nCols,
int  nRows,
int  minChar,
int  maxChar,
int  invalidChar,
bool  fixedWidth,
std::vector< int >  charWidths 
)

Creates a new Font.

Parameters:
fontTex the Texture2D which contains the images of the font.
nCols the number of characters columns in the texture.
nRows the number of characters rows in the texture.
minChar the first ascii char code to take into account. Lower chars will be replaced with 'invalidChar'.
maxChar the last ascii char code to take into account. Higher chars will be replaced with 'invalidChar'.
invalidChar the character to be used to display invalid characters.
fixedWidth whether the font is fixed-width (faster draw call, disallow overlapping characters)
charWidths an array of (maxChar - minChar + 1) character widths in texel NOTE: charWidth does NOT give texture coordinates, it gives spaces between characters.
virtual ork::Font::~Font (  )  [virtual]

Deletes this Font.

ork::Font::Font (  )  [protected]

Creates an uninitialized Font.


Member Function Documentation

vec2f ork::Font::addCenteredLine ( const vec4f viewport,
float  xs,
float  ys,
const string &  line,
float  height,
int  color,
ptr< Mesh< Vertex, unsigned int > >  textMesh 
)

Add a given line of text in a given Mesh centered at a given position and returns the size of the line.

Parameters:
viewport the framebuffer viewport, in pixels.
xs the x coordinate of the center of the line to display.
ys the y coordinate of the center of the line to display.
line the line of text to display.
height height of a char in pixels.
color color of this line of text (in RGBA8 format).
textMesh the mesh to write into.
vec2f ork::Font::addLine ( const vec4f viewport,
float  xs,
float  ys,
const string &  line,
float  height,
int  color,
ptr< Mesh< Vertex, unsigned int > >  textMesh 
)

Add a given line of text in a given Mesh and returns the final position of the line.

Parameters:
viewport the framebuffer viewport, in pixels.
xs the x coordinate of the first character to display.
ys the y coordinate of the first character to display.
line the line of text to display.
height height of a char in pixels.
color color of this line of text (in RGBA8 format).
textMesh the mesh to write into.
int ork::Font::charCount ( char  c  )  const [protected]

Get the tile index for this character.

Force the last character if c is not supported by this Font.

float ork::Font::getCharWidth ( char  c  )  const

Returns the space between this char and the next one.

Approximate the width of the drawed char (it's a bit different for legibility purpose).

ptr<Texture2D> ork::Font::getImage (  )  const

Returns the texture containing the image of this font.

vec2f ork::Font::getSize ( const string &  line,
float  height 
) const

Returns the size of a given line of text.

Parameters:
line the line of text.
height the height of output text in pixels
float ork::Font::getTileAspectRatio (  )  const

Returns the aspect ratio of a character tile.

float ork::Font::getTileHeight (  )  const

Returns the height of a character tile.

float ork::Font::getTileWidth (  )  const

Returns the width of a character tile.

virtual void ork::Font::init ( ptr< Texture2D fontTex,
int  nCols,
int  nRows,
int  minChar,
int  maxChar,
int  invalidChar,
bool  fixedWidth,
std::vector< int >  charWidths 
) [protected, virtual]

Initializes the fields of a Font.

Parameters:
fontTex the Texture2D which contains the images of the font.
nCols the number of characters columns in the texture.
nRows the number of characters rows in the texture.
minChar the first ascii char code to take into account. Lower chars will be replaced with 'invalidChar'.
maxChar the last ascii char code to take into account. Higher chars will be replaced with 'invalidChar'.
invalidChar the character to be used to display invalid characters.
fixedWidth whether the font is fixed-width (faster draw call, disallow overlapping characters)
charWidths an array of (maxChar - minChar + 1) character widths in texel NOTE: charWidth does NOT give texture coordinates, it gives spaces between characters.

Member Data Documentation

std::vector<int> ork::Font::charWidths [protected]

The width of a char (in texels).

Allows to have good-looking variable sized fonts. The ratio width/height of a given character is logicalWidth[c] / (textureHeight /

bool ork::Font::fixedWidth [protected]

If the font has fixed-width characters.

The Texture2D which contains the images of the font.

This texture is splitted in rows and colums which form "tiles".

int ork::Font::invalidChar [protected]

The character to be used to display invalid characters.

Must be between minChar and maxChar.

int ork::Font::maxChar [protected]

The last ascii char code to take into account.

Higher chars will be replaced with invalidChar.

int ork::Font::minChar [protected]

The first ascii char code to take into account.

Lower chars will be replaced with invalidChar.

int ork::Font::nCols [protected]

The number of character columns in the texture.

int ork::Font::nRows [protected]

The number of character rows in the texture.


Generated on Mon Oct 18 09:36:12 2010 for ork by  doxygen 1.6.1