Loading...
Searching...
No Matches
Ogre::Font Class Referencefinal
Optional Components » Overlay

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

`#include <OgreFont.h>`

Inheritance diagram for Ogre::Font:
[legend]

## Public Types

typedef GlyphInfo::CodePoint | CodePoint
typedef std::pair< CodePoint, CodePoint > | CodePointRange
| A range of code points, inclusive on both ends.
typedef std::vector< CodePointRange > | CodePointRangeList
typedef GlyphInfo::UVRect | UVRect
Public Types inherited from Ogre::Resource
enum | LoadingFlags { LF_DEFAULT = 0 , LF_INCLUDE_NON_RELOADABLE = 1 , LF_ONLY_UNREFERENCED = 2 , LF_ONLY_UNREFERENCED_INCLUDE_NON_RELOADABLE = 3 , LF_PRESERVE_STATE = 4 }
| Enum that allow to choose subset of unloaded/reloaded resources and to adjust reloading behavior. More...
enum | LoadingState { LOADSTATE_UNLOADED , LOADSTATE_LOADING , LOADSTATE_LOADED , LOADSTATE_UNLOADING , LOADSTATE_PREPARED , LOADSTATE_PREPARING }
| Enum identifying the loading state of the resource. More...

## Public Member Functions

| Font (ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual=false, ManualResourceLoader *loader=0)
| Constructor.
virtual | ~Font ()
void | _setMaterial (const MaterialPtr &mat)
| Manually set the material used for this font.
void | addCodePointRange (const CodePointRange &range)
| Adds a range of code points to the list of code point ranges to generate glyphs for, if this is a truetype based font.
void | addMergeFont (const FontPtr &font)
| Add a font to merge with this one.
void | clearCodePointRanges ()
| Clear the list of code point ranges.
bool | getAntialiasColour (void) const
| Gets whether or not the colour of this font is antialiased as it is generated from a true type font.
const CodePointRangeList & | getCodePointRangeList () const
| Get a const reference to the list of code point ranges to be used to generate glyphs from a truetype font.
float | getGlyphAspectRatio (CodePoint id) const
| Gets the aspect ratio (width / height) of this character.
const GlyphInfo & | getGlyphInfo (CodePoint id) const
| Gets the information available for a glyph corresponding to a given code point, or throws an exception if it doesn't exist;.
const UVRect & | getGlyphTexCoords (CodePoint id) const
| Returns the texture coordinates of the associated glyph.
const MaterialPtr & | getMaterial () const
| Gets the material generated for this font, as a weak reference.
const std::vector< FontPtr > & | getMergeFontList () const
const String & | getSource (void) const
| Gets the source this font (either an image or a truetype font).
int | getTrueTypeMaxBearingY () const
| Gets the maximum baseline distance of all glyphs used in the texture.
uint | getTrueTypeResolution (void) const
| Gets the resolution (dpi) of the font used to generate the texture.
Real | getTrueTypeSize (void) const
| Gets the point size of the font used to generate the texture.
FontType | getType (void) const
| Gets the type of font.
void | loadResource (Resource *resource) override
| Implementation of ManualResourceLoader::loadResource, called when the Texture that this font creates needs to (re)load.
void | putText (BillboardSet *bbs, String text, float height, const ColourValue &colour=ColourValue::White)
| Write a text into a BillboardSet for positioning in Space.
void | setAntialiasColour (bool enabled)
| Sets whether the colour of this font is multiplied with alpha as it is generated from a true type font.
void | setGlyphAspectRatio (CodePoint id, Real ratio)
| Sets the aspect ratio (width / height) of this character.
void | setGlyphInfo (const GlyphInfo &info)
void | setGlyphInfoFromTexCoords (CodePoint id, const UVRect &rect, float textureAspect=1.0)
| Sets the texture coordinates of a glyph.
void | setSource (const String &source)
| Sets the source of the font.
void | setTrueTypeResolution (uint ttfResolution)
| Gets the resolution (dpi) of the font used to generate the texture (only required for FT_TRUETYPE).
void | setTrueTypeSize (Real ttfSize)
| Sets the size of a truetype font (only required for FT_TRUETYPE).
void | setType (FontType ftype)
| Sets the type of font.
Public Member Functions inherited from Ogre::Resource
| Resource (ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual=false, ManualResourceLoader *loader=0)
| Standard constructor.
virtual | ~Resource ()
| Virtual destructor.
virtual void | _dirtyState ()
| Manually mark the state of this resource as having been changed.
void | _fireLoadingComplete (bool unused=false)
| Firing of loading complete event.
void | _firePreparingComplete (bool unused=false)
| Firing of preparing complete event.
void | _fireUnloadingComplete (void)
| Firing of unloading complete event.
void | _notifyOrigin (const String &origin)
| Notify this resource of it's origin.
virtual void | addListener (Listener *lis)
| Register a listener on this resource.
virtual void | changeGroupOwnership (const String &newGroup)
| Change the resource group ownership of a Resource.
virtual void | escalateLoading ()
| Escalates the loading of a background loaded resource.
ResourceManager * | getCreator (void)
| Gets the manager which created this resource.
const String & | getGroup (void) const
| Gets the group which this resource is a member of.
ResourceHandle | getHandle (void) const
LoadingState | getLoadingState () const
| Returns the current loading state.
const String & | getName (void) const
| Gets resource name.
const String & | getOrigin (void) const
| Get the origin of this resource, e.g.
size_t | getSize (void) const
| Retrieves info about the size of the resource.
virtual size_t | getStateCount () const
| Returns the number of times this resource has changed state, which generally means the number of times it has been loaded.
bool | isBackgroundLoaded (void) const
| Returns whether this Resource has been earmarked for background loading.
bool | isLoaded (void) const
| Returns true if the Resource has been loaded, false otherwise.
bool | isLoading () const
| Returns whether the resource is currently in the process of background loading.
bool | isManuallyLoaded (void) const
| Is this resource manually loaded?
bool | isPrepared (void) const
| Returns true if the Resource has been prepared, false otherwise.
bool | isReloadable (void) const
| Returns true if the Resource is reloadable, false otherwise.
virtual void | load (bool backgroundThread=false)
| Loads the resource, if it is not already.
virtual void | prepare (bool backgroundThread=false)
| Prepares the resource for load, if it is not already.
virtual void | reload (LoadingFlags flags=LF_DEFAULT)
| Reloads the resource, if it is already loaded.
virtual void | removeListener (Listener *lis)
| Remove a listener on this resource.
void | setBackgroundLoaded (bool bl)
| Tells the resource whether it is background loaded or not.
virtual void | touch (void)
| 'Touches' the resource to indicate it has been used.
virtual void | unload (void)
| Unloads the resource; this is not permanent, the resource can be reloaded later if required.
Public Member Functions inherited from Ogre::StringInterface
| StringInterface ()
virtual | ~StringInterface ()
| Virtual destructor, see Effective C++.
void | copyParametersTo (StringInterface *dest) const
| Method for copying this object's parameters to another object.
ParamDictionary * | getParamDictionary (void)
| Retrieves the parameter dictionary for this class.
const ParamDictionary * | getParamDictionary (void) const
String | getParameter (const String &name) const
| Generic parameter retrieval method.
const ParameterList & | getParameters (void) const
| Retrieves a list of parameters valid for this object.
bool | setParameter (const String &name, const String &value)
| Generic parameter setting method.
void | setParameterList (const NameValuePairList &paramList)
| Generic multiple parameter setting method.
Public Member Functions inherited from Ogre::ManualResourceLoader
| ManualResourceLoader ()
virtual | ~ManualResourceLoader ()
virtual void | prepareResource (Resource *resource)
| Called when a resource wishes to prepare instead of Resource::prepareImpl.

## Additional Inherited Members

Static Public Member Functions inherited from Ogre::StringInterface
static void | cleanupDictionary ()
| Cleans up the static 'msDictionary' required to reset Ogre, otherwise the containers are left with invalid pointers, which will lead to a crash as soon as one of the ResourceManager implementers (e.g.

## Detailed Description

Class representing a font in the system.

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)

Note
  This class extends both Resource and ManualResourceLoader since it is both a resource in it's own right, but it also provides the manual load implementation for the Texture it creates.

## Member Typedef Documentation

## CodePoint

typedef GlyphInfo::CodePoint Ogre::Font::CodePoint

## UVRect

typedef GlyphInfo::UVRect Ogre::Font::UVRect

## CodePointRange

typedef std::pair<CodePoint, CodePoint> Ogre::Font::CodePointRange

A range of code points, inclusive on both ends.

## CodePointRangeList

typedef std::vector<CodePointRange> Ogre::Font::CodePointRangeList

## Constructor & Destructor Documentation

## Font()

Ogre::Font::Font | ( | ResourceManager * | creator,
|  | const String & | name,
|  | ResourceHandle | handle,
|  | const String & | group,
|  | bool | isManual = false,
|  | ManualResourceLoader * | loader = 0 )

Constructor.

See also
  Resource

References Ogre::ManualResourceLoader::ManualResourceLoader().

## ~Font()

virtual Ogre::Font::~Font | ( |  | ) |

virtual

## Member Function Documentation

## setType()

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

Sets the type of font.

Must be set before loading.

## getType()

FontType Ogre::Font::getType | ( | void |  | ) | const

Gets the type of font.

## setSource()

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

Sets the source of the font.

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, and call addCodePointRange as many times as required to define the range of glyphs you want to be available.

Parameters

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

## getSource()

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

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

## setTrueTypeSize()

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.

## setTrueTypeResolution()

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

## getTrueTypeSize()

Real Ogre::Font::getTrueTypeSize | ( | void |  | ) | const

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

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.

## getTrueTypeResolution()

uint Ogre::Font::getTrueTypeResolution | ( | void |  | ) | const

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

Only applicable for FT_TRUETYPE Font objects.

## getTrueTypeMaxBearingY()

int Ogre::Font::getTrueTypeMaxBearingY | ( |  | ) | const

Gets the maximum baseline distance of all glyphs used in the texture.

Only applicable for FT_TRUETYPE Font objects. The baseline is the vertical origin of horizontal based glyphs. The bearingY attribute is the distance from the baseline (origin) to the top of the glyph's bounding box.

Note
  This value is only available after the font has been loaded.

## getGlyphTexCoords()

const UVRect & Ogre::Font::getGlyphTexCoords | ( | CodePoint | id | ) | const

inline

Returns the texture coordinates of the associated glyph.

Remarks
  Parameter is a short to allow both ASCII and wide chars.

Parameters

  id | The code point (unicode)

Returns
  A rectangle with the UV coordinates, or null UVs if the code point was not present

References getGlyphInfo().

## setGlyphInfoFromTexCoords()

void Ogre::Font::setGlyphInfoFromTexCoords | ( | CodePoint | id,
|  | const UVRect & | rect,
|  | float | textureAspect = 1.0 )

inline

Sets the texture coordinates of a glyph.

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. textureAspect is the width/height of the texture (may be non-square)

References Ogre::TRect< T >::height(), setGlyphInfo(), and Ogre::TRect< T >::width().

## setGlyphInfo()

void Ogre::Font::setGlyphInfo | ( | const GlyphInfo & | info | ) |

inline

References Ogre::GlyphInfo::codePoint.

Referenced by setGlyphInfoFromTexCoords().

## getGlyphAspectRatio()

float Ogre::Font::getGlyphAspectRatio | ( | CodePoint | id | ) | const

inline

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

References getGlyphInfo().

## setGlyphAspectRatio()

void Ogre::Font::setGlyphAspectRatio | ( | CodePoint | id,
|  | Real | ratio )

inline

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

You only need to call this if you're setting up a font loaded from a texture manually.

## getGlyphInfo()

const GlyphInfo & Ogre::Font::getGlyphInfo | ( | CodePoint | id | ) | const

inline

Gets the information available for a glyph corresponding to a given code point, or throws an exception if it doesn't exist;.

References Ogre::Exception::ERR_ITEM_NOT_FOUND, Ogre::StringUtil::format(), and OGRE_EXCEPT.

Referenced by getGlyphAspectRatio(), and getGlyphTexCoords().

## addCodePointRange()

void Ogre::Font::addCodePointRange | ( | const CodePointRange & | range | ) |

inline

Adds a range of code points to the list of code point ranges to generate glyphs for, if this is a truetype based font.

In order to save texture space, only the glyphs which are actually needed by the application are generated into the texture. Before this object is loaded you must call this method as many times as necessary to define the code point range that you need.

## clearCodePointRanges()

void Ogre::Font::clearCodePointRanges | ( |  | ) |

inline

Clear the list of code point ranges.

## getCodePointRangeList()

const CodePointRangeList & Ogre::Font::getCodePointRangeList | ( |  | ) | const

inline

Get a const reference to the list of code point ranges to be used to generate glyphs from a truetype font.

## addMergeFont()

void Ogre::Font::addMergeFont | ( | const FontPtr & | font | ) |

inline

Add a font to merge with this one.

This is useful when you want to use a font for most of the characters, but fall back to another font for characters not present in the current font. e.g. icons.

## getMergeFontList()

const std::vector< FontPtr > & Ogre::Font::getMergeFontList | ( |  | ) | const

inline

## getMaterial()

const MaterialPtr & Ogre::Font::getMaterial | ( |  | ) | const

inline

Gets the material generated for this font, as a weak reference.

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

## putText()

void Ogre::Font::putText | ( | BillboardSet * | bbs,
|  | String | text,
|  | float | height,
|  | const ColourValue & | colour = ColourValue::White )

Write a text into a BillboardSet for positioning in Space.

Text is laid out in the x-y plane, running into x+ and using y+ as up

Parameters

  bbs | the target BillboardSet
  text | text to write
  height | character height in world units
  colour | text colour

References Ogre::ColourValue::White.

## setAntialiasColour()

void Ogre::Font::setAntialiasColour | ( | bool | enabled | ) |

inline

Sets whether the colour of this font is multiplied with alpha as it is generated from a true type font.

This is valid only for a FT_TRUETYPE font. If you are planning on using alpha blending to draw your font, then 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 use premultipled alpha or a colour blending mode (add or modulate for example) then set this to true, in order to soften your font edges.

## getAntialiasColour()

bool Ogre::Font::getAntialiasColour | ( | void |  | ) | const

inline

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

## loadResource()

void Ogre::Font::loadResource | ( | Resource * | resource | ) |

override virtual

Implementation of ManualResourceLoader::loadResource, called when the Texture that this font creates needs to (re)load.

Implements Ogre::ManualResourceLoader.

## _setMaterial()

void Ogre::Font::_setMaterial | ( | const MaterialPtr & | mat | ) |

Manually set the material used for this font.

This should only be used when the font is being loaded from a ManualResourceLoader.

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

- OgreFont.h