OgreFont.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 This source file is a part of OGRE
3 (Object-oriented Graphics Rendering Engine)
4 
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE
25 -------------------------------------------------------------------------*/
26 
27 #ifndef _Font_H__
28 #define _Font_H__
29 
31 #include "OgreResource.h"
32 #include "OgreTexture.h"
33 #include "OgreMaterial.h"
34 #include "OgreCommon.h"
35 
36 namespace Ogre
37 {
45  enum FontType
46  {
50  FT_IMAGE = 2
51  };
52 
53 
68  {
69  protected:
72  {
73  public:
74  String doGet(const void* target) const;
75  void doSet(void* target, const String& val);
76  };
79  {
80  public:
81  String doGet(const void* target) const;
82  void doSet(void* target, const String& val);
83  };
85  {
86  public:
87  String doGet(const void* target) const;
88  void doSet(void* target, const String& val);
89  };
92  {
93  public:
94  String doGet(const void* target) const;
95  void doSet(void* target, const String& val);
96  };
99  {
100  public:
101  String doGet(const void* target) const;
102  void doSet(void* target, const String& val);
103  };
106  {
107  public:
108  String doGet(const void* target) const;
109  void doSet(void* target, const String& val);
110  };
111 
112  // Command object for setting / getting parameters
119 
122 
125 
129 
136 
137 
138  public:
142  struct GlyphInfo
143  {
147 
148  GlyphInfo(CodePoint id, const UVRect& rect, Real aspect)
149  : codePoint(id), uvRect(rect), aspectRatio(aspect)
150  {
151 
152  }
153  };
155  typedef std::pair<CodePoint, CodePoint> CodePointRange;
157  protected:
161 
164 
167 
170 
173 
176 
178  virtual void loadImpl();
180  virtual void unloadImpl();
182  size_t calculateSize(void) const { return 0; } // permanent resource is in the texture
183  public:
184 
188  Font(ResourceManager* creator, const String& name, ResourceHandle handle,
189  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
190  virtual ~Font();
191 
193  void setType(FontType ftype);
194 
196  FontType getType(void) const;
197 
213  void setSource(const String& source);
214 
217  const String& getSource(void) const;
218 
224  void setCharacterSpacer(uint charSpacer);
225 
232 
238  void setTrueTypeSize(Real ttfSize);
243  void setTrueTypeResolution(uint ttfResolution);
244 
251  Real getTrueTypeSize(void) const;
267 
268 
275  inline const UVRect& getGlyphTexCoords(CodePoint id) const
276  {
277  CodePointMap::const_iterator i = mCodePointMap.find(id);
278  if (i != mCodePointMap.end())
279  {
280  return i->second.uvRect;
281  }
282  else
283  {
284  static UVRect nullRect(0.0, 0.0, 0.0, 0.0);
285  return nullRect;
286  }
287  }
288 
296  inline void setGlyphTexCoords(CodePoint id, Real u1, Real v1, Real u2, Real v2, Real textureAspect)
297  {
298  CodePointMap::iterator i = mCodePointMap.find(id);
299  if (i != mCodePointMap.end())
300  {
301  i->second.uvRect.left = u1;
302  i->second.uvRect.top = v1;
303  i->second.uvRect.right = u2;
304  i->second.uvRect.bottom = v2;
305  i->second.aspectRatio = textureAspect * (u2 - u1) / (v2 - v1);
306  }
307  else
308  {
309  mCodePointMap.insert(
310  CodePointMap::value_type(id,
311  GlyphInfo(id, UVRect(u1, v1, u2, v2),
312  textureAspect * (u2 - u1) / (v2 - v1))));
313  }
314 
315  }
318  {
319  CodePointMap::const_iterator i = mCodePointMap.find(id);
320  if (i != mCodePointMap.end())
321  {
322  return i->second.aspectRatio;
323  }
324  else
325  {
326  return 1.0;
327  }
328  }
334  inline void setGlyphAspectRatio(CodePoint id, Real ratio)
335  {
336  CodePointMap::iterator i = mCodePointMap.find(id);
337  if (i != mCodePointMap.end())
338  {
339  i->second.aspectRatio = ratio;
340  }
341  }
342 
346  const GlyphInfo& getGlyphInfo(CodePoint id) const;
347 
357  {
358  mCodePointRangeList.push_back(range);
359  }
360 
364  {
365  mCodePointRangeList.clear();
366  }
371  {
372  return mCodePointRangeList;
373  }
378  inline const MaterialPtr& getMaterial() const
379  {
380  return mMaterial;
381  }
386  inline const MaterialPtr& getMaterial()
387  {
388  return mMaterial;
389  }
401  inline void setAntialiasColour(bool enabled)
402  {
403  mAntialiasColour = enabled;
404  }
405 
409  inline bool getAntialiasColour(void) const
410  {
411  return mAntialiasColour;
412  }
413 
417  void loadResource(Resource* resource);
418  };
421 }
422 
423 #endif
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,...
Definition: OgreFont.h:356
Ogre::Font::CmdResolution::doSet
void doSet(void *target, const String &val)
Ogre::ResourceHandle
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
Ogre::Font::CodePointRange
std::pair< CodePoint, CodePoint > CodePointRange
A range of code points, inclusive on both ends.
Definition: OgreFont.h:155
Ogre::Font::GlyphInfo::codePoint
CodePoint codePoint
Definition: OgreFont.h:144
Ogre::Font::getSource
const String & getSource(void) const
Gets the source this font (either an image or a truetype font).
Ogre::Font::GlyphInfo::aspectRatio
Real aspectRatio
Definition: OgreFont.h:146
Ogre::Font::getCharacterSpacer
uint getCharacterSpacer(void) const
Gets the spacing to allocate for font characters to overlap each other.
Ogre
Definition: OgreAndroidLogListener.h:35
Ogre::Font::mTexture
TexturePtr mTexture
Texture pointer.
Definition: OgreFont.h:166
Ogre::Font::getTrueTypeResolution
uint getTrueTypeResolution(void) const
Gets the resolution (dpi) of the font used to generate the texture.
Ogre::Font::CmdCharSpacer::doSet
void doSet(void *target, const String &val)
Ogre::Font::GlyphInfo::GlyphInfo
GlyphInfo(CodePoint id, const UVRect &rect, Real aspect)
Definition: OgreFont.h:148
Ogre::map
Definition: OgrePrerequisites.h:534
Ogre::Font::CmdCharSpacer
Definition: OgreFont.h:85
Ogre::Font::getGlyphAspectRatio
Real getGlyphAspectRatio(CodePoint id) const
Gets the aspect ratio (width / height) of this character.
Definition: OgreFont.h:317
Ogre::Font::mCodePointRangeList
CodePointRangeList mCodePointRangeList
Range of code points to generate glyphs for (truetype only)
Definition: OgreFont.h:172
OgreOverlayPrerequisites.h
Ogre::Font::clearCodePointRanges
void clearCodePointRanges()
Clear the list of code point ranges.
Definition: OgreFont.h:363
Ogre::Font
Class representing a font in the system.
Definition: OgreFont.h:68
Ogre::Font::msSourceCmd
static CmdSource msSourceCmd
Definition: OgreFont.h:114
Ogre::FT_IMAGE
@ FT_IMAGE
Loaded from an image created by an artist.
Definition: OgreFont.h:50
Ogre::Font::mAntialiasColour
bool mAntialiasColour
for TRUE_TYPE font only
Definition: OgreFont.h:169
Ogre::TRect< float >
Ogre::Font::GlyphInfo
Information about the position and size of a glyph in a texture.
Definition: OgreFont.h:143
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::CodePointRangeList
vector< CodePointRange >::type CodePointRangeList
Definition: OgreFont.h:156
Ogre::Font::getGlyphTexCoords
const UVRect & getGlyphTexCoords(CodePoint id) const
Returns the texture coordinates of the associated glyph.
Definition: OgreFont.h:275
Ogre::Font::CodePoint
Ogre::uint32 CodePoint
Definition: OgreFont.h:139
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::Font::mSource
String mSource
Source of the font (either an image name or a truetype font)
Definition: OgreFont.h:124
Ogre::Font::getType
FontType getType(void) const
Gets the type of font.
Ogre::Font::CmdResolution::doGet
String doGet(const void *target) const
Ogre::Font::Font
Font(ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual=false, ManualResourceLoader *loader=0)
Constructor.
Ogre::Font::CmdSource
Command object for Font - see ParamCommand.
Definition: OgreFont.h:79
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::Font::setType
void setType(FontType ftype)
Sets the type of font.
Ogre::Font::msCharacterSpacerCmd
static CmdCharSpacer msCharacterSpacerCmd
Definition: OgreFont.h:115
Ogre::FontType
FontType
Enumerates the types of Font usable in the engine.
Definition: OgreFont.h:46
Ogre::Font::mCodePointMap
CodePointMap mCodePointMap
Definition: OgreFont.h:160
Ogre::FT_TRUETYPE
@ FT_TRUETYPE
Generated from a truetype (.ttf) font.
Definition: OgreFont.h:48
Ogre::Font::setGlyphAspectRatio
void setGlyphAspectRatio(CodePoint id, Real ratio)
Sets the aspect ratio (width / height) of this character.
Definition: OgreFont.h:334
OgreMaterial.h
Ogre::Font::CmdCodePoints::doSet
void doSet(void *target, const String &val)
Ogre::ParamCommand
Abstract class which is command object which gets/sets parameters.
Definition: OgreStringInterface.h:80
Ogre::Font::UVRect
Ogre::FloatRect UVRect
Definition: OgreFont.h:140
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::CodePointMap
map< CodePoint, GlyphInfo >::type CodePointMap
Map from unicode code point to texture coordinates.
Definition: OgreFont.h:159
Ogre::Font::msCodePointsCmd
static CmdCodePoints msCodePointsCmd
Definition: OgreFont.h:118
Ogre::Font::CmdCodePoints::doGet
String doGet(const void *target) const
Ogre::Font::~Font
virtual ~Font()
Ogre::Font::GlyphInfo::uvRect
UVRect uvRect
Definition: OgreFont.h:145
Ogre::Font::loadResource
void loadResource(Resource *resource)
Implementation of ManualResourceLoader::loadResource, called when the Texture that this font creates ...
Ogre::Font::loadImpl
virtual void loadImpl()
Internal implementation of the meat of the 'load' action, only called if this resource is not being l...
Ogre::Font::setTrueTypeSize
void setTrueTypeSize(Real ttfSize)
Sets the size of a truetype font (only required for FT_TRUETYPE).
OgreTexture.h
_OgreOverlayExport
#define _OgreOverlayExport
Definition: OgreOverlayPrerequisites.h:58
Ogre::Font::mTtfMaxBearingY
int mTtfMaxBearingY
Max distance to baseline of this (truetype) font.
Definition: OgreFont.h:135
Ogre::Font::CmdResolution
Command object for Font - see ParamCommand.
Definition: OgreFont.h:99
Ogre::Font::getTrueTypeSize
Real getTrueTypeSize(void) const
Gets the point size of the font used to generate the texture.
Ogre::Font::getMaterial
const MaterialPtr & getMaterial() const
Gets the material generated for this font, as a weak reference.
Definition: OgreFont.h:378
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::Font::msResolutionCmd
static CmdResolution msResolutionCmd
Definition: OgreFont.h:117
Ogre::Font::CmdSize
Command object for Font - see ParamCommand.
Definition: OgreFont.h:92
OgreResource.h
OgreCommon.h
Ogre::Font::createTextureFromFont
void createTextureFromFont(void)
Internal method for loading from ttf.
Ogre::ResourceManager
Defines a generic resource handler.
Definition: OgreResourceManager.h:123
Ogre::Font::CmdSize::doGet
String doGet(const void *target) const
Ogre::Font::msTypeCmd
static CmdType msTypeCmd
Definition: OgreFont.h:113
Ogre::Font::CmdCharSpacer::doGet
String doGet(const void *target) const
Ogre::Font::mTtfSize
Real mTtfSize
Size of the truetype font, in points.
Definition: OgreFont.h:131
Ogre::Font::CmdCodePoints
Command object for Font - see ParamCommand.
Definition: OgreFont.h:106
Ogre::SharedPtr< Material >
Ogre::Font::CmdType::doGet
String doGet(const void *target) const
Ogre::Font::getMaterial
const MaterialPtr & getMaterial()
Gets the material generated for this font, as a weak reference.
Definition: OgreFont.h:386
Ogre::Resource
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:80
Ogre::Font::setSource
void setSource(const String &source)
Sets the source of the font.
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::uint
unsigned int uint
Definition: OgrePrerequisites.h:114
Ogre::Font::msSizeCmd
static CmdSize msSizeCmd
Definition: OgreFont.h:116
Ogre::Font::getGlyphInfo
const GlyphInfo & getGlyphInfo(CodePoint id) const
Gets the information available for a glyph corresponding to a given code point, or throws an exceptio...
Ogre::Font::CmdSource::doSet
void doSet(void *target, const String &val)
Ogre::Font::CmdSource::doGet
String doGet(const void *target) const
Ogre::Font::getTrueTypeMaxBearingY
int getTrueTypeMaxBearingY() const
Gets the maximum baseline distance of all glyphs used in the texture.
Ogre::Font::setTrueTypeResolution
void setTrueTypeResolution(uint ttfResolution)
Gets the resolution (dpi) of the font used to generate the texture (only required for FT_TRUETYPE).
Ogre::Font::CmdType
Command object for Font - see ParamCommand.
Definition: OgreFont.h:72
Ogre::Font::CmdSize::doSet
void doSet(void *target, const String &val)
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Font::unloadImpl
virtual void unloadImpl()
Internal implementation of the 'unload' action; called regardless of whether this resource is being l...
Ogre::Font::CmdType::doSet
void doSet(void *target, const String &val)
Ogre::Font::mTtfResolution
uint mTtfResolution
Resolution (dpi) of truetype font.
Definition: OgreFont.h:133
Ogre::Font::calculateSize
size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
Definition: OgreFont.h:182
Ogre::Font::setCharacterSpacer
void setCharacterSpacer(uint charSpacer)
Sets the spacing to allocate for font characters to overlap each other.
Ogre::vector
Definition: OgrePrerequisites.h:492
Ogre::ManualResourceLoader
Interface describing a manual resource loader.
Definition: OgreResource.h:515
Ogre::Font::mType
FontType mType
The type of font.
Definition: OgreFont.h:121
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::mMaterial
MaterialPtr mMaterial
The material which is generated for this font.
Definition: OgreFont.h:163

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