Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Ogre::Font Class Reference

Class representing a font in the system. More...

#include <OgreFont.h>

Inheritance diagram for Ogre::Font:

Ogre::Resource List of all members.

Public Methods

 Font (const String &name)
 Constructor. More...

virtual ~Font ()
void setType (FontType ftype)
 Sets the type of font. More...

FontType getType (void)
 Gets the type of font. More...

void setSource (const String &source)
 Sets the source of the font. More...

const String & getSource (void)
 Gets the source this font (either an image or a truetype font). More...

void setTrueTypeSize (Real ttfSize)
 Sets the size of a truetype font (only required for FT_TRUETYPE). More...

void setTrueTypeResolution (uint ttfResolution)
 Gets the resolution (dpi) of the font used to generate the texture (only required for FT_TRUETYPE). More...

Real getTrueTypeSize (void)
 Gets the point size of the font used to generate the texture. More...

uint getTrueTypeResolution (void)
 Gets the resolution (dpi) of the font used to generate the texture. More...

std::pair< uint, uint > StrBBox (const String &text, Real char_height, RenderWindow &window)
 Returns the size in pixels of a box that could contain the whole string. More...

virtual void load ()
 See Resource. More...

virtual void unload ()
 See Resource. More...

void getGlyphTexCoords (OgreChar id, Real &u1, Real &v1, Real &u2, Real &v2) const
 Returns the teture coordinates of the associated glyph. More...

void setGlyphTexCoords (OgreChar id, Real u1, Real v1, Real u2, Real v2)
 Sets the texture coordinates of a glyph. More...

Real getGlyphAspectRatio (OgreChar id) const
 Gets the aspect ratio (width / height) of this character. More...

void setGlyphAspectRatio (OgreChar id, Real ratio)
 Sets the aspect ratio (width / height) of this character. More...

const Material * getMaterial () const
 Gets the material generated for this font. More...

Material * getMaterial ()
 Gets the material generated for this font. More...

void setAntialiasColour (bool enabled)
 Sets whether or not the colour of this font is antialiased as it is generated from a true type font. More...

bool getAntialiasColour (void)
virtual size_t getSize (void)
 Retrieves info about the size of the resource. More...

void touch (void)
 'Touches' the resource to indicate it has been used. More...

time_t getLastAccess (void) const
 Gets the last time the resource was 'touched'. More...

const String & getName (void) const
 Gets resource name. More...

bool isLoaded (void) const
 Returns true if the Resource has been loaded, false otherwise. More...

virtual void destroy ()
 A method to make the resource delete itself. More...


Protected Methods

void createTextureFromFont (void)
 Internal method for loading from ttf. More...


Protected Attributes

FontType mType
 The type of font. More...

String mSource
 Source of the font (either an image name or a truetype font). More...

Real mTtfSize
 Size of the truetype font, in points. More...

uint mTtfResolution
 Resolution (dpi) of truetype font. More...

Real mTexCoords_u1 [OGRE_NUM_GLYPHS]
 Start u coords. More...

Real mTexCoords_u2 [OGRE_NUM_GLYPHS]
 End u coords. More...

Real mTexCoords_v1 [OGRE_NUM_GLYPHS]
 Start v coords. More...

Real mTexCoords_v2 [OGRE_NUM_GLYPHS]
 End v coords. More...

Real mAspectRatio [OGRE_NUM_GLYPHS]
 Aspect ratio between x and y (width / height). More...

Material * mpMaterial
 The material which is generated for this font. More...

bool mAntialiasColour
 for TRUE_TYPE font only. More...

String mName
bool mIsLoaded
time_t mLastAccess
size_t mSize

Detailed Description

Class representing a font in the system.

Remarks:
This class is simply a way of getting a font texture into the OGRE system and to easily retrieve the texture coordinates required to accurately render them. Fonts can either be loaded from precreated textures, or the texture can be generated using a truetype font. You can either create the texture manually in code, or you can use a .fontdef script to define it (probably more practical since you can reuse the definition more easily)


Constructor & Destructor Documentation

Ogre::Font::Font (  const String &    name ) 
 

Constructor.

Parameters:
name  Mandatory name, must be unique.

Ogre::Font::~Font (    )  [virtual]
 


Member Function Documentation

void Ogre::Font::createTextureFromFont (  void    )  [protected]
 

Internal method for loading from ttf.

virtual void Ogre::Resource::destroy (  void    )  [inline, virtual, inherited]
 

A method to make the resource delete itself.

Note:
This exists because Resource objects could be created in other processes, and they need to be destroyed in the process that created them.

bool Ogre::Font::getAntialiasColour (  void    )  [inline]
 

Real Ogre::Font::getGlyphAspectRatio (  OgreChar    id )  const [inline]
 

Gets the aspect ratio (width / height) of this character.

void Ogre::Font::getGlyphTexCoords (  OgreChar    id,
Real &    u1,
Real &    v1,
Real &    u2,
Real &    v2
)  const [inline]
 

Returns the teture coordinates of the associated glyph.

Remarks:
Parameter is a short to allow both ASCII and wide chars.
Parameters:
id  The character code
u1, u2, v1, v2  location to place the results

time_t Ogre::Resource::getLastAccess (  void    )  const [inline, inherited]
 

Gets the last time the resource was 'touched'.

Material* Ogre::Font::getMaterial (  void    )  [inline]
 

Gets the material generated for this font.

Remarks:
This will only be valid after the Font has been loaded.

const Material* Ogre::Font::getMaterial (  void    )  const [inline]
 

Gets the material generated for this font.

Remarks:
This will only be valid after the Font has been loaded.

const String& Ogre::Resource::getName (  void    )  const [inline, inherited]
 

Gets resource name.

Reimplemented in Ogre::Material.

virtual size_t Ogre::Resource::getSize (  void    )  [inline, virtual, inherited]
 

Retrieves info about the size of the resource.

const String & Ogre::Font::getSource (  void    ) 
 

Gets the source this font (either an image or a truetype font).

uint Ogre::Font::getTrueTypeResolution (  void    ) 
 

Gets the resolution (dpi) of the font used to generate the texture.

Remarks:
Only applicable for FT_TRUETYPE Font objects.

Real Ogre::Font::getTrueTypeSize (  void    ) 
 

Gets the point size of the font used to generate the texture.

Remarks:
Only applicable for FT_TRUETYPE Font objects. Note that the size of the font does not affect how big it is on the screen, just how large it is in the texture and thus how detailed it is.

FontType Ogre::Font::getType (  void    ) 
 

Gets the type of font.

bool Ogre::Resource::isLoaded (  void    )  const [inline, inherited]
 

Returns true if the Resource has been loaded, false otherwise.

void Ogre::Font::load (    )  [virtual]
 

See Resource.

Implements Ogre::Resource.

void Ogre::Font::setAntialiasColour (  bool    enabled )  [inline]
 

Sets whether or not the colour of this font is antialiased as it is generated from a true type font.

Remarks:
This is valid only for a FT_TRUETYPE font. If you are planning on using alpha blending to draw your font, then it is a good idea to set this to false (which is the default), otherwise the darkening of the font will combine with the fading out of the alpha around the edges and make your font look thinner than it should. However, if you intend to blend your font using a colour blending mode (add or modulate for example) then it's a good idea to set this to true, in order to soften your font edges.

void Ogre::Font::setGlyphAspectRatio (  OgreChar    id,
Real    ratio
)  [inline]
 

Sets the aspect ratio (width / height) of this character.

Remarks:
You only need to call this if you're setting up a font loaded from a texture manually, and your aspect ratio is really freaky.

void Ogre::Font::setGlyphTexCoords (  OgreChar    id,
Real    u1,
Real    v1,
Real    u2,
Real    v2
)  [inline]
 

Sets the texture coordinates of a glyph.

Remarks:
You only need to call this if you're setting up a font loaded from a texture manually.
Note:
Also sets the aspect ratio (width / height) of this character.

void Ogre::Font::setSource (  const String &    source ) 
 

Sets the source of the font.

Remarks:
If you have created a font of type FT_IMAGE, this method tells the Font which image to use as the source for the characters. So the parameter should be the name of an appropriate image file. Note that when using an image as a font source, you will also need to tell the font where each character is located using setGlyphTexCoords (for each character).

If you have created a font of type FT_TRUETYPE, this method tells the Font which .ttf file to use to generate the text. You will also need to call setTrueTypeSize and setTrueTypeResolution.

Parameters:
source  An image file or a truetype font, depending on the type of this font

void Ogre::Font::setTrueTypeResolution (  uint    ttfResolution ) 
 

Gets the resolution (dpi) of the font used to generate the texture (only required for FT_TRUETYPE).

Parameters:
ttfResolution  The resolution in dpi

void Ogre::Font::setTrueTypeSize (  Real    ttfSize ) 
 

Sets the size of a truetype font (only required for FT_TRUETYPE).

Parameters:
ttfSize  The size of the font in points. Note that the size of the font does not affect how big it is on the screen, just how large it is in the texture and thus how detailed it is.

void Ogre::Font::setType (  FontType    ftype ) 
 

Sets the type of font.

Must be set before loading.

std::pair< uint, uint > Ogre::Font::StrBBox (  const String &    text,
Real    char_height,
RenderWindow &    window
) 
 

Returns the size in pixels of a box that could contain the whole string.

void Ogre::Resource::touch (  void    )  [inline, inherited]
 

'Touches' the resource to indicate it has been used.

void Ogre::Font::unload (    )  [virtual]
 

See Resource.

Reimplemented from Ogre::Resource.


Member Data Documentation

bool Ogre::Font::mAntialiasColour [protected]
 

for TRUE_TYPE font only.

Real Ogre::Font::mAspectRatio[OGRE_NUM_GLYPHS] [protected]
 

Aspect ratio between x and y (width / height).

bool Ogre::Resource::mIsLoaded [protected, inherited]
 

time_t Ogre::Resource::mLastAccess [protected, inherited]
 

String Ogre::Resource::mName [protected, inherited]
 

Material* Ogre::Font::mpMaterial [protected]
 

The material which is generated for this font.

size_t Ogre::Resource::mSize [protected, inherited]
 

String Ogre::Font::mSource [protected]
 

Source of the font (either an image name or a truetype font).

Real Ogre::Font::mTexCoords_u1[OGRE_NUM_GLYPHS] [protected]
 

Start u coords.

Real Ogre::Font::mTexCoords_u2[OGRE_NUM_GLYPHS] [protected]
 

End u coords.

Real Ogre::Font::mTexCoords_v1[OGRE_NUM_GLYPHS] [protected]
 

Start v coords.

Real Ogre::Font::mTexCoords_v2[OGRE_NUM_GLYPHS] [protected]
 

End v coords.

uint Ogre::Font::mTtfResolution [protected]
 

Resolution (dpi) of truetype font.

Real Ogre::Font::mTtfSize [protected]
 

Size of the truetype font, in points.

FontType Ogre::Font::mType [protected]
 

The type of font.

Copyright © 2002 by The OGRE Team