OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2014 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  {
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 
175  void createTextureFromFont(void);
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 
231  uint getCharacterSpacer(void) const;
232 
238  void setTrueTypeSize(Real ttfSize);
243  void setTrueTypeResolution(uint ttfResolution);
244 
251  Real getTrueTypeSize(void) const;
256  uint getTrueTypeResolution(void) const;
266  int getTrueTypeMaxBearingY() 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
FontType mType
The type of font.
Definition: OgreFont.h:121
float Real
Software floating point type.
size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
Definition: OgreFont.h:182
unsigned int uint32
Definition: OgrePlatform.h:344
const MaterialPtr & getMaterial()
Gets the material generated for this font, as a weak reference.
Definition: OgreFont.h:386
Loaded from an image created by an artist.
Definition: OgreFont.h:50
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
void clearCodePointRanges()
Clear the list of code point ranges.
Definition: OgreFont.h:363
uint mCharacterSpacer
Add a gap between letters vertically and horizonally prevents nasty artifacts caused by fonts atypica...
Definition: OgreFont.h:128
Command object for Font - see ParamCommand.
Definition: OgreFont.h:71
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
GlyphInfo(CodePoint id, const UVRect &rect, Real aspect)
Definition: OgreFont.h:148
Class representing a font in the system.
Definition: OgreFont.h:67
#define _OgreOverlayExport
int mTtfMaxBearingY
Max distance to baseline of this (truetype) font.
Definition: OgreFont.h:135
FontType
Enumerates the types of Font usable in the engine.
Definition: OgreFont.h:45
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
Information about the position and size of a glyph in a texture.
Definition: OgreFont.h:142
Ogre::uint32 CodePoint
Definition: OgreFont.h:139
Interface describing a manual resource loader.
Definition: OgreResource.h:514
map< CodePoint, GlyphInfo >::type CodePointMap
Map from unicode code point to texture coordinates.
Definition: OgreFont.h:159
Real mTtfSize
Size of the truetype font, in points.
Definition: OgreFont.h:131
CodePoint codePoint
Definition: OgreFont.h:144
Ogre::FloatRect UVRect
Definition: OgreFont.h:140
MaterialPtr mMaterial
The material which is generated for this font.
Definition: OgreFont.h:163
uint mTtfResolution
Resolution (dpi) of truetype font.
Definition: OgreFont.h:133
Command object for Font - see ParamCommand.
Definition: OgreFont.h:91
CodePointMap mCodePointMap
Definition: OgreFont.h:160
static CmdSource msSourceCmd
Definition: OgreFont.h:114
static CmdType msTypeCmd
Definition: OgreFont.h:113
const UVRect & getGlyphTexCoords(CodePoint id) const
Returns the texture coordinates of the associated glyph.
Definition: OgreFont.h:275
Generated from a truetype (.ttf) font.
Definition: OgreFont.h:48
Command object for Font - see ParamCommand.
Definition: OgreFont.h:98
String mSource
Source of the font (either an image name or a truetype font)
Definition: OgreFont.h:124
CodePointRangeList mCodePointRangeList
Range of code points to generate glyphs for (truetype only)
Definition: OgreFont.h:172
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
Command object for Font - see ParamCommand.
Definition: OgreFont.h:105
TexturePtr mTexture
Texture pointer.
Definition: OgreFont.h:166
void setGlyphAspectRatio(CodePoint id, Real ratio)
Sets the aspect ratio (width / height) of this character.
Definition: OgreFont.h:334
Command object for Font - see ParamCommand.
Definition: OgreFont.h:78
static CmdCodePoints msCodePointsCmd
Definition: OgreFont.h:118
static CmdResolution msResolutionCmd
Definition: OgreFont.h:117
Real getGlyphAspectRatio(CodePoint id) const
Gets the aspect ratio (width / height) of this character.
Definition: OgreFont.h:317
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:79
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
const MaterialPtr & getMaterial() const
Gets the material generated for this font, as a weak reference.
Definition: OgreFont.h:378
static CmdCharSpacer msCharacterSpacerCmd
Definition: OgreFont.h:115
std::pair< CodePoint, CodePoint > CodePointRange
A range of code points, inclusive on both ends.
Definition: OgreFont.h:155
Defines a generic resource handler.
_StringBase String
static CmdSize msSizeCmd
Definition: OgreFont.h:116
bool mAntialiasColour
for TRUE_TYPE font only
Definition: OgreFont.h:169
vector< CodePointRange >::type CodePointRangeList
Definition: OgreFont.h:156
unsigned int uint
Abstract class which is command object which gets/sets parameters.
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