OGRE  2.0
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 "OgreCommon.h"
33 #include "OgreSharedPtr.h"
34 
35 namespace Ogre
36 {
44  enum FontType
45  {
50  };
51 
52 
67  {
68  protected:
71  {
72  public:
73  String doGet(const void* target) const;
74  void doSet(void* target, const String& val);
75  };
78  {
79  public:
80  String doGet(const void* target) const;
81  void doSet(void* target, const String& val);
82  };
84  {
85  public:
86  String doGet(const void* target) const;
87  void doSet(void* target, const String& val);
88  };
91  {
92  public:
93  String doGet(const void* target) const;
94  void doSet(void* target, const String& val);
95  };
98  {
99  public:
100  String doGet(const void* target) const;
101  void doSet(void* target, const String& val);
102  };
105  {
106  public:
107  String doGet(const void* target) const;
108  void doSet(void* target, const String& val);
109  };
110 
111  // Command object for setting / getting parameters
118 
121 
124 
128 
135 
136 
137  public:
141  struct GlyphInfo
142  {
146 
147  GlyphInfo(CodePoint id, const UVRect& rect, Real aspect)
148  : codePoint(id), uvRect(rect), aspectRatio(aspect)
149  {
150 
151  }
152  };
154  typedef std::pair<CodePoint, CodePoint> CodePointRange;
156  protected:
160 
163 
166 
169 
172 
174  void createTextureFromFont(void);
175 
177  virtual void loadImpl();
179  virtual void unloadImpl();
181  size_t calculateSize(void) const { return 0; } // permanent resource is in the texture
182  public:
183 
187  Font(ResourceManager* creator, const String& name, ResourceHandle handle,
188  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
189  virtual ~Font();
190 
192  void setType(FontType ftype);
193 
195  FontType getType(void) const;
196 
212  void setSource(const String& source);
213 
216  const String& getSource(void) const;
217 
223  void setCharacterSpacer(uint charSpacer);
224 
230  uint getCharacterSpacer(void) const;
231 
237  void setTrueTypeSize(Real ttfSize);
242  void setTrueTypeResolution(uint ttfResolution);
243 
250  Real getTrueTypeSize(void) const;
255  uint getTrueTypeResolution(void) const;
265  int getTrueTypeMaxBearingY() const;
266 
267 
274  inline const UVRect& getGlyphTexCoords(CodePoint id) const
275  {
276  CodePointMap::const_iterator i = mCodePointMap.find(id);
277  if (i != mCodePointMap.end())
278  {
279  return i->second.uvRect;
280  }
281  else
282  {
283  static UVRect nullRect(0.0, 0.0, 0.0, 0.0);
284  return nullRect;
285  }
286  }
287 
295  inline void setGlyphTexCoords(CodePoint id, Real u1, Real v1, Real u2, Real v2, Real textureAspect)
296  {
297  CodePointMap::iterator i = mCodePointMap.find(id);
298  if (i != mCodePointMap.end())
299  {
300  i->second.uvRect.left = u1;
301  i->second.uvRect.top = v1;
302  i->second.uvRect.right = u2;
303  i->second.uvRect.bottom = v2;
304  i->second.aspectRatio = textureAspect * (u2 - u1) / (v2 - v1);
305  }
306  else
307  {
308  mCodePointMap.insert(
309  CodePointMap::value_type(id,
310  GlyphInfo(id, UVRect(u1, v1, u2, v2),
311  textureAspect * (u2 - u1) / (v2 - v1))));
312  }
313 
314  }
317  {
318  CodePointMap::const_iterator i = mCodePointMap.find(id);
319  if (i != mCodePointMap.end())
320  {
321  return i->second.aspectRatio;
322  }
323  else
324  {
325  return 1.0;
326  }
327  }
333  inline void setGlyphAspectRatio(CodePoint id, Real ratio)
334  {
335  CodePointMap::iterator i = mCodePointMap.find(id);
336  if (i != mCodePointMap.end())
337  {
338  i->second.aspectRatio = ratio;
339  }
340  }
341 
345  const GlyphInfo& getGlyphInfo(CodePoint id) const;
346 
356  {
357  mCodePointRangeList.push_back(range);
358  }
359 
363  {
364  mCodePointRangeList.clear();
365  }
370  {
371  return mCodePointRangeList;
372  }
377  inline const MaterialPtr& getMaterial() const
378  {
379  return mMaterial;
380  }
385  inline const MaterialPtr& getMaterial()
386  {
387  return mMaterial;
388  }
400  inline void setAntialiasColour(bool enabled)
401  {
402  mAntialiasColour = enabled;
403  }
404 
408  inline bool getAntialiasColour(void) const
409  {
410  return mAntialiasColour;
411  }
412 
416  void loadResource(Resource* resource);
417  };
420 }
421 
422 #endif
FontType mType
The type of font.
Definition: OgreFont.h:120
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:181
unsigned int uint32
Definition: OgrePlatform.h:420
const MaterialPtr & getMaterial()
Gets the material generated for this font, as a weak reference.
Definition: OgreFont.h:385
Loaded from an image created by an artist.
Definition: OgreFont.h:49
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:408
void clearCodePointRanges()
Clear the list of code point ranges.
Definition: OgreFont.h:362
uint mCharacterSpacer
Add a gap between letters vertically and horizonally prevents nasty artifacts caused by fonts atypica...
Definition: OgreFont.h:127
Command object for Font - see ParamCommand.
Definition: OgreFont.h:70
void setGlyphTexCoords(CodePoint id, Real u1, Real v1, Real u2, Real v2, Real textureAspect)
Sets the texture coordinates of a glyph.
Definition: OgreFont.h:295
GlyphInfo(CodePoint id, const UVRect &rect, Real aspect)
Definition: OgreFont.h:147
Class representing a font in the system.
Definition: OgreFont.h:66
#define _OgreOverlayExport
int mTtfMaxBearingY
Max distance to baseline of this (truetype) font.
Definition: OgreFont.h:134
FontType
Enumerates the types of Font usable in the engine.
Definition: OgreFont.h:44
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:369
Information about the position and size of a glyph in a texture.
Definition: OgreFont.h:141
Ogre::uint32 CodePoint
Definition: OgreFont.h:138
Interface describing a manual resource loader.
Definition: OgreResource.h:498
map< CodePoint, GlyphInfo >::type CodePointMap
Map from unicode code point to texture coordinates.
Definition: OgreFont.h:158
Real mTtfSize
Size of the truetype font, in points.
Definition: OgreFont.h:130
CodePoint codePoint
Definition: OgreFont.h:143
Ogre::FloatRect UVRect
Definition: OgreFont.h:139
MaterialPtr mMaterial
The material which is generated for this font.
Definition: OgreFont.h:162
uint mTtfResolution
Resolution (dpi) of truetype font.
Definition: OgreFont.h:132
Command object for Font - see ParamCommand.
Definition: OgreFont.h:90
CodePointMap mCodePointMap
Definition: OgreFont.h:159
static CmdSource msSourceCmd
Definition: OgreFont.h:113
static CmdType msTypeCmd
Definition: OgreFont.h:112
const UVRect & getGlyphTexCoords(CodePoint id) const
Returns the texture coordinates of the associated glyph.
Definition: OgreFont.h:274
Generated from a truetype (.ttf) font.
Definition: OgreFont.h:47
Command object for Font - see ParamCommand.
Definition: OgreFont.h:97
String mSource
Source of the font (either an image name or a truetype font)
Definition: OgreFont.h:123
CodePointRangeList mCodePointRangeList
Range of code points to generate glyphs for (truetype only)
Definition: OgreFont.h:171
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:355
Command object for Font - see ParamCommand.
Definition: OgreFont.h:104
TexturePtr mTexture
Texture pointer.
Definition: OgreFont.h:165
void setGlyphAspectRatio(CodePoint id, Real ratio)
Sets the aspect ratio (width / height) of this character.
Definition: OgreFont.h:333
Command object for Font - see ParamCommand.
Definition: OgreFont.h:77
static CmdCodePoints msCodePointsCmd
Definition: OgreFont.h:117
static CmdResolution msResolutionCmd
Definition: OgreFont.h:116
Real getGlyphAspectRatio(CodePoint id) const
Gets the aspect ratio (width / height) of this character.
Definition: OgreFont.h:316
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:77
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
const MaterialPtr & getMaterial() const
Gets the material generated for this font, as a weak reference.
Definition: OgreFont.h:377
static CmdCharSpacer msCharacterSpacerCmd
Definition: OgreFont.h:114
std::pair< CodePoint, CodePoint > CodePointRange
A range of code points, inclusive on both ends.
Definition: OgreFont.h:154
Defines a generic resource handler.
_StringBase String
Definition: OgreCommon.h:53
static CmdSize msSizeCmd
Definition: OgreFont.h:115
bool mAntialiasColour
For TRUE_TYPE font only.
Definition: OgreFont.h:168
vector< CodePointRange >::type CodePointRangeList
Definition: OgreFont.h:155
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:400