OGRE-Next  3.0.0
Object-Oriented Graphics Rendering Engine
Ogre::Font Class Referencefinal

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

#include <OgreFont.h>

+ Inheritance diagram for Ogre::Font:

Classes

struct  GlyphInfo
 Information about the position and size of a glyph in a texture. More...
 

Public Types

typedef Ogre::uint32 CodePoint
 
typedef std::pair< CodePoint, CodePointCodePointRange
 A range of code points, inclusive on both ends. More...
 
typedef vector< CodePointRange >::type CodePointRangeList
 
typedef Ogre::FloatRect 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 , LF_MARKED_FOR_RELOAD = 8
}
 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 , LOADSTATE_UNLOADED_MARKED_FOR_RELOAD
}
 Enum identifying the loading state of the resource. More...
 
- Public Types inherited from Ogre::TextureGpuListener
enum  Reason {
  Unknown , FromStorageToSysRam , FromSysRamToStorage , GainedResidency ,
  LostResidency , PoolTextureSlotChanged , ResidentToSysRamSync , MetadataCacheOutOfDate ,
  ExceptionThrown , FsaaSettingAlteredByApi , ReadyForRendering , Deleted
}
 

Public Member Functions

 Font (ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual=false, ManualResourceLoader *loader=0)
 Constructor. More...
 
 ~Font () override
 
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. More...
 
void clearCodePointRanges ()
 Clear the list of code point ranges. More...
 
bool getAntialiasColour () const
 Gets whether or not the colour of this font is antialiased as it is generated from a true type font. More...
 
uint getCharacterSpacer () const
 Gets the spacing to allocate for font characters to overlap each other. More...
 
const CodePointRangeListgetCodePointRangeList () const
 Get a const reference to the list of code point ranges to be used to generate glyphs from a truetype font. More...
 
Real getGlyphAspectRatio (CodePoint id) const
 Gets the aspect ratio (width / height) of this character. More...
 
const GlyphInfogetGlyphInfo (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;. More...
 
const UVRectgetGlyphTexCoords (CodePoint id) const
 Returns the texture coordinates of the associated glyph. More...
 
HlmsDatablockgetHlmsDatablock ()
 Gets the HLMS Datablock generated for this font. More...
 
const StringgetSource () const
 Gets the source this font (either an image or a truetype font). More...
 
int getTrueTypeMaxBearingY () const
 Gets the maximum baseline distance of all glyphs used in the texture. More...
 
uint getTrueTypeResolution () const
 Gets the resolution (dpi) of the font used to generate the texture. More...
 
Real getTrueTypeSize () const
 Gets the point size of the font used to generate the texture. More...
 
FontType getType () const
 Gets the type of font. More...
 
void notifyTextureChanged (TextureGpu *texture, TextureGpuListener::Reason reason, void *extraData) override
 Called when a TextureGpu changed in a way that affects how it is displayed: 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...
 
void setCharacterSpacer (uint charSpacer)
 Sets the spacing to allocate for font characters to overlap each other. More...
 
void setGlyphAspectRatio (CodePoint id, Real ratio)
 Sets the aspect ratio (width / height) of this character. More...
 
void setGlyphTexCoords (CodePoint id, Real u1, Real v1, Real u2, Real v2, Real textureAspect)
 Sets the texture coordinates of a glyph. More...
 
void setSource (const String &source)
 Sets the source of the font. More...
 
void setTrueTypeResolution (uint ttfResolution)
 Gets the resolution (dpi) of the font used to generate the texture (only required for FT_TRUETYPE). More...
 
void setTrueTypeSize (Real ttfSize)
 Sets the size of a truetype font (only required for FT_TRUETYPE). More...
 
void setType (FontType ftype)
 Sets the type of font. More...
 
- 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. More...
 
virtual ~Resource ()
 Virtual destructor. More...
 
virtual void _dirtyState ()
 Manually mark the state of this resource as having been changed. More...
 
virtual void _fireLoadingComplete (bool wasBackgroundLoaded)
 Firing of loading complete event. More...
 
virtual void _firePreparingComplete (bool wasBackgroundLoaded)
 Firing of preparing complete event. More...
 
virtual void _fireUnloadingComplete ()
 Firing of unloading complete event. More...
 
virtual void _notifyOrigin (const String &origin)
 Notify this resource of it's origin. More...
 
virtual void addListener (Listener *lis)
 Register a listener on this resource. More...
 
virtual void changeGroupOwnership (const String &newGroup)
 Change the resource group ownership of a Resource. More...
 
virtual void escalateLoading ()
 Escalates the loading of a background loaded resource. More...
 
virtual ResourceManagergetCreator ()
 Gets the manager which created this resource. More...
 
virtual const StringgetGroup () const
 Gets the group which this resource is a member of. More...
 
virtual ResourceHandle getHandle () const
 
virtual LoadingState getLoadingState () const
 Returns the current loading state. More...
 
virtual const StringgetName () const
 Gets resource name. More...
 
virtual const StringgetOrigin () const
 Get the origin of this resource, e.g. More...
 
virtual size_t getSize () const
 Retrieves info about the size of the resource. More...
 
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. More...
 
virtual bool isBackgroundLoaded () const
 Returns whether this Resource has been earmarked for background loading. More...
 
virtual bool isLoaded () const
 Returns true if the Resource has been loaded, false otherwise. More...
 
virtual bool isLoading () const
 Returns whether the resource is currently in the process of background loading. More...
 
virtual bool isManuallyLoaded () const
 Is this resource manually loaded? More...
 
virtual bool isPrepared () const
 Returns true if the Resource has been prepared, false otherwise. More...
 
virtual bool isReloadable () const
 Returns true if the Resource is reloadable, false otherwise. More...
 
virtual void load (bool backgroundThread=false)
 Loads the resource, if it is not already. More...
 
bool markForReload ()
 
virtual void prepare (bool backgroundThread=false)
 Prepares the resource for load, if it is not already. More...
 
virtual void reload (LoadingFlags flags=LF_DEFAULT)
 Reloads the resource, if it is already loaded. More...
 
virtual void removeListener (Listener *lis)
 Remove a listener on this resource. More...
 
virtual void setBackgroundLoaded (bool bl)
 Tells the resource whether it is background loaded or not. More...
 
virtual void setManuallyLoaded (bool isManual)
 Set "Is this resource manually loaded?". More...
 
virtual void setToLoaded ()
 Change the Resource loading state to loaded. More...
 
virtual void touch ()
 'Touches' the resource to indicate it has been used. More...
 
virtual void unload ()
 Unloads the resource; this is not permanent, the resource can be reloaded later if required. More...
 
- Public Member Functions inherited from Ogre::StringInterface
 StringInterface ()
 
virtual ~StringInterface ()
 Virtual destructor, see Effective C++. More...
 
virtual void copyParametersTo (StringInterface *dest) const
 Method for copying this object's parameters to another object. More...
 
ParamDictionarygetParamDictionary ()
 Retrieves the parameter dictionary for this class. More...
 
const ParamDictionarygetParamDictionary () const
 
virtual String getParameter (const String &name) const
 Generic parameter retrieval method. More...
 
const ParameterListgetParameters () const
 Retrieves a list of parameters valid for this object. More...
 
virtual bool setParameter (const String &name, const String &value)
 Generic parameter setting method. More...
 
virtual void setParameterList (const NameValuePairList &paramList)
 Generic multiple parameter setting method. More...
 
- Public Member Functions inherited from Ogre::TextureGpuListener
virtual ~TextureGpuListener ()
 
virtual bool shouldStayLoaded (TextureGpu *texture)
 Return true if this TextureGpu should likely stay loaded or else graphical changes could occur. More...
 

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. More...
 
- Public Attributes inherited from Ogre::Resource
 OGRE_AUTO_MUTEX
 

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)
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

◆ CodePointRange

A range of code points, inclusive on both ends.

◆ CodePointRangeList

◆ UVRect

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

◆ ~Font()

Ogre::Font::~Font ( )
override

Member Function Documentation

◆ 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.

Remarks
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.

◆ getAntialiasColour()

bool Ogre::Font::getAntialiasColour ( ) const
inline

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

◆ getCharacterSpacer()

uint Ogre::Font::getCharacterSpacer ( ) const

Gets the spacing to allocate for font characters to overlap each other.

Remarks
Returns the size of the character spacer, in points. A higher value allows for more stretched-out fonts. A low value reduces memory and processing time. The default is "5".

◆ 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.

◆ getGlyphAspectRatio()

Real Ogre::Font::getGlyphAspectRatio ( CodePoint  id) const
inline

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

◆ getGlyphInfo()

const GlyphInfo& Ogre::Font::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;.

◆ 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
idThe code point (unicode)
Returns
A rectangle with the UV coordinates, or null UVs if the code point was not present

◆ getHlmsDatablock()

HlmsDatablock* Ogre::Font::getHlmsDatablock ( )
inline

Gets the HLMS Datablock generated for this font.

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

◆ getSource()

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

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

◆ getTrueTypeMaxBearingY()

int Ogre::Font::getTrueTypeMaxBearingY ( ) const

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

Remarks
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.

◆ getTrueTypeResolution()

uint Ogre::Font::getTrueTypeResolution ( ) const

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

Remarks
Only applicable for FT_TRUETYPE Font objects.

◆ getTrueTypeSize()

Real Ogre::Font::getTrueTypeSize ( ) const

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.

◆ getType()

FontType Ogre::Font::getType ( ) const

Gets the type of font.

◆ notifyTextureChanged()

void Ogre::Font::notifyTextureChanged ( TextureGpu texture,
TextureGpuListener::Reason  reason,
void *  extraData 
)
overridevirtual

Called when a TextureGpu changed in a way that affects how it is displayed:

  1. TextureGpu::notifyDataIsReady got called (texture is ready to be displayed)
  2. Texture changed residency status.
  3. Texture is being deleted. It won't be a valid pointer after this call.

Implements Ogre::TextureGpuListener.

◆ setAntialiasColour()

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.

◆ setCharacterSpacer()

void Ogre::Font::setCharacterSpacer ( uint  charSpacer)

Sets the spacing to allocate for font characters to overlap each other.

Parameters
charSpacerThe size of the character spacer, in points. Increasing it allows for more stretched-out fonts; decreasing it reduces memory and processing time. The default is "5".

◆ setGlyphAspectRatio()

void Ogre::Font::setGlyphAspectRatio ( CodePoint  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.

◆ setGlyphTexCoords()

void Ogre::Font::setGlyphTexCoords ( CodePoint  id,
Real  u1,
Real  v1,
Real  u2,
Real  v2,
Real  textureAspect 
)
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. textureAspect is the width/height of the texture (may be non-square)

◆ setSource()

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, and call addCodePointRange as many times as required to define the range of glyphs you want to be available.
Parameters
sourceAn image file or a truetype font, depending on the type of this font

◆ 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
ttfResolutionThe resolution in dpi

◆ setTrueTypeSize()

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

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

Parameters
ttfSizeThe 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.

◆ setType()

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

Sets the type of font.

Must be set before loading.


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