OgreFont.h
Go to the documentation of this file.
/*-------------------------------------------------------------------------
This source file is a part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE
-------------------------------------------------------------------------*/
#ifndef _Font_H__
#define _Font_H__
#include "OgreOverlayPrerequisites.h"
#include "OgreResource.h"
#include "OgreTexture.h"
#include "OgreMaterial.h"
#include "OgreCommon.h"
namespace Ogre
{
enum FontType
{
FT_TRUETYPE = 1,
FT_IMAGE = 2
};
class _OgreOverlayExport Font : public Resource, public ManualResourceLoader
{
protected:
class _OgreOverlayExport CmdType : public ParamCommand
{
public:
String doGet(const void* target) const;
void doSet(void* target, const String& val);
};
class _OgreOverlayExport CmdSource : public ParamCommand
{
public:
String doGet(const void* target) const;
void doSet(void* target, const String& val);
};
class _OgreOverlayExport CmdCharSpacer : public ParamCommand
{
public:
String doGet(const void* target) const;
void doSet(void* target, const String& val);
};
class _OgreOverlayExport CmdSize : public ParamCommand
{
public:
String doGet(const void* target) const;
void doSet(void* target, const String& val);
};
class _OgreOverlayExport CmdResolution : public ParamCommand
{
public:
String doGet(const void* target) const;
void doSet(void* target, const String& val);
};
class _OgreOverlayExport CmdCodePoints : public ParamCommand
{
public:
String doGet(const void* target) const;
void doSet(void* target, const String& val);
};
// Command object for setting / getting parameters
static CmdType msTypeCmd;
static CmdSource msSourceCmd;
static CmdCharSpacer msCharacterSpacerCmd;
static CmdSize msSizeCmd;
static CmdResolution msResolutionCmd;
static CmdCodePoints msCodePointsCmd;
FontType mType;
String mSource;
uint mCharacterSpacer;
Real mTtfSize;
uint mTtfResolution;
int mTtfMaxBearingY;
public:
typedef Ogre::uint32 CodePoint;
typedef Ogre::FloatRect UVRect;
struct GlyphInfo
{
CodePoint codePoint;
UVRect uvRect;
Real aspectRatio;
GlyphInfo(CodePoint id, const UVRect& rect, Real aspect)
: codePoint(id), uvRect(rect), aspectRatio(aspect)
{
}
};
typedef std::pair<CodePoint, CodePoint> CodePointRange;
typedef vector<CodePointRange>::type CodePointRangeList;
protected:
typedef map<CodePoint, GlyphInfo>::type CodePointMap;
CodePointMap mCodePointMap;
MaterialPtr mMaterial;
TexturePtr mTexture;
bool mAntialiasColour;
CodePointRangeList mCodePointRangeList;
void createTextureFromFont(void);
virtual void loadImpl();
virtual void unloadImpl();
size_t calculateSize(void) const { return 0; } // permanent resource is in the texture
public:
Font(ResourceManager* creator, const String& name, ResourceHandle handle,
const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
virtual ~Font();
void setType(FontType ftype);
FontType getType(void) const;
void setSource(const String& source);
const String& getSource(void) const;
void setCharacterSpacer(uint charSpacer);
uint getCharacterSpacer(void) const;
void setTrueTypeSize(Real ttfSize);
void setTrueTypeResolution(uint ttfResolution);
Real getTrueTypeSize(void) const;
uint getTrueTypeResolution(void) const;
int getTrueTypeMaxBearingY() const;
inline const UVRect& getGlyphTexCoords(CodePoint id) const
{
CodePointMap::const_iterator i = mCodePointMap.find(id);
if (i != mCodePointMap.end())
{
return i->second.uvRect;
}
else
{
static UVRect nullRect(0.0, 0.0, 0.0, 0.0);
return nullRect;
}
}
inline void setGlyphTexCoords(CodePoint id, Real u1, Real v1, Real u2, Real v2, Real textureAspect)
{
CodePointMap::iterator i = mCodePointMap.find(id);
if (i != mCodePointMap.end())
{
i->second.uvRect.left = u1;
i->second.uvRect.top = v1;
i->second.uvRect.right = u2;
i->second.uvRect.bottom = v2;
i->second.aspectRatio = textureAspect * (u2 - u1) / (v2 - v1);
}
else
{
mCodePointMap.insert(
CodePointMap::value_type(id,
GlyphInfo(id, UVRect(u1, v1, u2, v2),
textureAspect * (u2 - u1) / (v2 - v1))));
}
}
inline Real getGlyphAspectRatio(CodePoint id) const
{
CodePointMap::const_iterator i = mCodePointMap.find(id);
if (i != mCodePointMap.end())
{
return i->second.aspectRatio;
}
else
{
return 1.0;
}
}
inline void setGlyphAspectRatio(CodePoint id, Real ratio)
{
CodePointMap::iterator i = mCodePointMap.find(id);
if (i != mCodePointMap.end())
{
i->second.aspectRatio = ratio;
}
}
const GlyphInfo& getGlyphInfo(CodePoint id) const;
void addCodePointRange(const CodePointRange& range)
{
mCodePointRangeList.push_back(range);
}
void clearCodePointRanges()
{
mCodePointRangeList.clear();
}
const CodePointRangeList& getCodePointRangeList() const
{
return mCodePointRangeList;
}
inline const MaterialPtr& getMaterial() const
{
return mMaterial;
}
inline const MaterialPtr& getMaterial()
{
return mMaterial;
}
inline void setAntialiasColour(bool enabled)
{
mAntialiasColour = enabled;
}
inline bool getAntialiasColour(void) const
{
return mAntialiasColour;
}
void loadResource(Resource* resource);
};
}
#endif
Ogre::Font::setGlyphTexCoords
void setGlyphTexCoords(CodePoint id, Real u1, Real v1, Real u2, Real v2, Real textureAspect)
Sets the texture coordinates of a glyph.
Definition: OgreFont.h:296
Ogre::Font::getMaterial
const MaterialPtr & getMaterial() const
Gets the material generated for this font, as a weak reference.
Definition: OgreFont.h:378
Ogre::FT_IMAGE
Loaded from an image created by an artist.
Definition: OgreFont.h:50
Ogre::Font::mTtfMaxBearingY
int mTtfMaxBearingY
Max distance to baseline of this (truetype) font.
Definition: OgreFont.h:135
Ogre::Font::msTypeCmd
static CmdType msTypeCmd
Definition: OgreFont.h:113
Ogre::Font::msResolutionCmd
static CmdResolution msResolutionCmd
Definition: OgreFont.h:117
Ogre::Font::clearCodePointRanges
void clearCodePointRanges()
Clear the list of code point ranges.
Definition: OgreFont.h:363
Ogre::Font::mAntialiasColour
bool mAntialiasColour
for TRUE_TYPE font only
Definition: OgreFont.h:169
Ogre::uint
unsigned int uint
Definition: OgrePrerequisites.h:114
Ogre::Font::getMaterial
const MaterialPtr & getMaterial()
Gets the material generated for this font, as a weak reference.
Definition: OgreFont.h:386
Ogre::Font::GlyphInfo
Information about the position and size of a glyph in a texture.
Definition: OgreFont.h:142
OgreResource.h
Ogre::Font::CodePointRangeList
vector< CodePointRange >::type CodePointRangeList
Definition: OgreFont.h:156
Ogre::Font::CodePoint
Ogre::uint32 CodePoint
Definition: OgreFont.h:139
Ogre::Font::mTtfSize
Real mTtfSize
Size of the truetype font, in points.
Definition: OgreFont.h:131
Ogre::Font::mSource
String mSource
Source of the font (either an image name or a truetype font)
Definition: OgreFont.h:124
Ogre::Font::CmdCharSpacer
Definition: OgreFont.h:84
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Font::mCharacterSpacer
uint mCharacterSpacer
Add a gap between letters vertically and horizonally prevents nasty artifacts caused by fonts atypica...
Definition: OgreFont.h:128
Ogre::Font::getGlyphAspectRatio
Real getGlyphAspectRatio(CodePoint id) const
Gets the aspect ratio (width / height) of this character.
Definition: OgreFont.h:317
Ogre::TRect< float >
_OgreOverlayExport
#define _OgreOverlayExport
Definition: OgreOverlayPrerequisites.h:58
Ogre::Resource
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:79
Ogre::Font::mCodePointMap
CodePointMap mCodePointMap
Definition: OgreFont.h:160
Ogre::ManualResourceLoader
Interface describing a manual resource loader.
Definition: OgreResource.h:514
Ogre::Font::msSizeCmd
static CmdSize msSizeCmd
Definition: OgreFont.h:116
Ogre::ResourceHandle
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
Ogre::Font::CodePointMap
map< CodePoint, GlyphInfo >::type CodePointMap
Map from unicode code point to texture coordinates.
Definition: OgreFont.h:159
OgreCommon.h
Ogre::Font::mTtfResolution
uint mTtfResolution
Resolution (dpi) of truetype font.
Definition: OgreFont.h:133
Ogre::Font::mType
FontType mType
The type of font.
Definition: OgreFont.h:121
Ogre::Font::setGlyphAspectRatio
void setGlyphAspectRatio(CodePoint id, Real ratio)
Sets the aspect ratio (width / height) of this character.
Definition: OgreFont.h:334
OgreTexture.h
Ogre::Font::CmdSize
Command object for Font - see ParamCommand.
Definition: OgreFont.h:91
Ogre::Font::UVRect
Ogre::FloatRect UVRect
Definition: OgreFont.h:140
Ogre::FontType
FontType
Enumerates the types of Font usable in the engine.
Definition: OgreFont.h:45
Ogre::Font::CodePointRange
std::pair< CodePoint, CodePoint > CodePointRange
A range of code points, inclusive on both ends.
Definition: OgreFont.h:155
Ogre::FT_TRUETYPE
Generated from a truetype (.ttf) font.
Definition: OgreFont.h:48
Ogre::Font::setAntialiasColour
void setAntialiasColour(bool enabled)
Sets whether or not the colour of this font is antialiased as it is generated from a true type font...
Definition: OgreFont.h:401
Ogre::Font::GlyphInfo::GlyphInfo
GlyphInfo(CodePoint id, const UVRect &rect, Real aspect)
Definition: OgreFont.h:148
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::Font::addCodePointRange
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.
Definition: OgreFont.h:356
Ogre::Font::mCodePointRangeList
CodePointRangeList mCodePointRangeList
Range of code points to generate glyphs for (truetype only)
Definition: OgreFont.h:172
OgreOverlayPrerequisites.h
Ogre::Font::GlyphInfo::aspectRatio
Real aspectRatio
Definition: OgreFont.h:146
Ogre::Font::GlyphInfo::uvRect
UVRect uvRect
Definition: OgreFont.h:145
Ogre::Font::mTexture
TexturePtr mTexture
Texture pointer.
Definition: OgreFont.h:166
Ogre::Font::CmdResolution
Command object for Font - see ParamCommand.
Definition: OgreFont.h:98
Ogre::Font::msSourceCmd
static CmdSource msSourceCmd
Definition: OgreFont.h:114
Ogre::Font::getAntialiasColour
bool getAntialiasColour(void) const
Gets whether or not the colour of this font is antialiased as it is generated from a true type font...
Definition: OgreFont.h:409
Ogre::ResourceManager
Defines a generic resource handler.
Definition: OgreResourceManager.h:122
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::Font::GlyphInfo::codePoint
CodePoint codePoint
Definition: OgreFont.h:144
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Font::CmdType
Command object for Font - see ParamCommand.
Definition: OgreFont.h:71
Ogre::Font::getGlyphTexCoords
const UVRect & getGlyphTexCoords(CodePoint id) const
Returns the texture coordinates of the associated glyph.
Definition: OgreFont.h:275
Ogre::Font::msCharacterSpacerCmd
static CmdCharSpacer msCharacterSpacerCmd
Definition: OgreFont.h:115
Ogre::Font::CmdCodePoints
Command object for Font - see ParamCommand.
Definition: OgreFont.h:105
Ogre::SharedPtr< Material >
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::Font::calculateSize
size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after &#39;load&#39;.
Definition: OgreFont.h:182
Ogre::Font::getCodePointRangeList
const CodePointRangeList & getCodePointRangeList() const
Get a const reference to the list of code point ranges to be used to generate glyphs from a truetype ...
Definition: OgreFont.h:370
Ogre::Font::CmdSource
Command object for Font - see ParamCommand.
Definition: OgreFont.h:78
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::ParamCommand
Abstract class which is command object which gets/sets parameters.
Definition: OgreStringInterface.h:79
OgreMaterial.h
Ogre::Font::mMaterial
MaterialPtr mMaterial
The material which is generated for this font.
Definition: OgreFont.h:163
Ogre::Font
Class representing a font in the system.
Definition: OgreFont.h:67
Ogre::Font::msCodePointsCmd
static CmdCodePoints msCodePointsCmd
Definition: OgreFont.h:118

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.