OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-2011 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 
30 #include "OgrePrerequisites.h"
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  };
86  {
87  public:
88  String doGet(const void* target) const;
89  void doSet(void* target, const String& val);
90  };
93  {
94  public:
95  String doGet(const void* target) const;
96  void doSet(void* target, const String& val);
97  };
100  {
101  public:
102  String doGet(const void* target) const;
103  void doSet(void* target, const String& val);
104  };
105 
106  // Command object for setting / getting parameters
112 
115 
118 
125 
126 
127  public:
131  struct GlyphInfo
132  {
136 
137  GlyphInfo(CodePoint id, const UVRect& rect, Real aspect)
138  : codePoint(id), uvRect(rect), aspectRatio(aspect)
139  {
140 
141  }
142  };
144  typedef std::pair<CodePoint, CodePoint> CodePointRange;
146  protected:
150 
153 
156 
159 
162 
164  void createTextureFromFont(void);
165 
167  virtual void loadImpl();
169  virtual void unloadImpl();
171  size_t calculateSize(void) const { return 0; } // permanent resource is in the texture
172  public:
173 
177  Font(ResourceManager* creator, const String& name, ResourceHandle handle,
178  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
179  virtual ~Font();
180 
182  void setType(FontType ftype);
183 
185  FontType getType(void) const;
186 
202  void setSource(const String& source);
203 
206  const String& getSource(void) const;
207 
213  void setTrueTypeSize(Real ttfSize);
218  void setTrueTypeResolution(uint ttfResolution);
219 
226  Real getTrueTypeSize(void) const;
231  uint getTrueTypeResolution(void) const;
241  int getTrueTypeMaxBearingY() const;
242 
243 
250  inline const UVRect& getGlyphTexCoords(CodePoint id) const
251  {
252  CodePointMap::const_iterator i = mCodePointMap.find(id);
253  if (i != mCodePointMap.end())
254  {
255  return i->second.uvRect;
256  }
257  else
258  {
259  static UVRect nullRect(0.0, 0.0, 0.0, 0.0);
260  return nullRect;
261  }
262  }
263 
271  inline void setGlyphTexCoords(CodePoint id, Real u1, Real v1, Real u2, Real v2, Real textureAspect)
272  {
273  CodePointMap::iterator i = mCodePointMap.find(id);
274  if (i != mCodePointMap.end())
275  {
276  i->second.uvRect.left = u1;
277  i->second.uvRect.top = v1;
278  i->second.uvRect.right = u2;
279  i->second.uvRect.bottom = v2;
280  i->second.aspectRatio = textureAspect * (u2 - u1) / (v2 - v1);
281  }
282  else
283  {
284  mCodePointMap.insert(
285  CodePointMap::value_type(id,
286  GlyphInfo(id, UVRect(u1, v1, u2, v2),
287  textureAspect * (u2 - u1) / (v2 - v1))));
288  }
289 
290  }
293  {
294  CodePointMap::const_iterator i = mCodePointMap.find(id);
295  if (i != mCodePointMap.end())
296  {
297  return i->second.aspectRatio;
298  }
299  else
300  {
301  return 1.0;
302  }
303  }
309  inline void setGlyphAspectRatio(CodePoint id, Real ratio)
310  {
311  CodePointMap::iterator i = mCodePointMap.find(id);
312  if (i != mCodePointMap.end())
313  {
314  i->second.aspectRatio = ratio;
315  }
316  }
317 
321  const GlyphInfo& getGlyphInfo(CodePoint id) const;
322 
332  {
333  mCodePointRangeList.push_back(range);
334  }
335 
339  {
340  mCodePointRangeList.clear();
341  }
346  {
347  return mCodePointRangeList;
348  }
353  inline const MaterialPtr& getMaterial() const
354  {
355  return mpMaterial;
356  }
361  inline const MaterialPtr& getMaterial()
362  {
363  return mpMaterial;
364  }
376  inline void setAntialiasColour(bool enabled)
377  {
378  mAntialiasColour = enabled;
379  }
380 
384  inline bool getAntialiasColour(void) const
385  {
386  return mAntialiasColour;
387  }
388 
392  void loadResource(Resource* resource);
393  };
400  class _OgreExport FontPtr : public SharedPtr<Font>
401  {
402  public:
404  explicit FontPtr(Font* rep) : SharedPtr<Font>(rep) {}
405  FontPtr(const FontPtr& r) : SharedPtr<Font>(r) {}
407  {
408  // lock & copy other mutex pointer
409  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
410  {
411  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
412  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
413  pRep = static_cast<Font*>(r.getPointer());
414  pUseCount = r.useCountPointer();
415  if (pUseCount)
416  {
417  ++(*pUseCount);
418  }
419  }
420  }
421 
424  {
425  if (pRep == static_cast<Font*>(r.getPointer()))
426  return *this;
427  release();
428  // lock & copy other mutex pointer
429  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
430  {
431  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
432  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
433  pRep = static_cast<Font*>(r.getPointer());
434  pUseCount = r.useCountPointer();
435  if (pUseCount)
436  {
437  ++(*pUseCount);
438  }
439  }
440  else
441  {
442  // RHS must be a null pointer
443  assert(r.isNull() && "RHS must be null if it has no mutex!");
444  setNull();
445  }
446  return *this;
447  }
448  };
451 }
452 
453 #endif
FontPtr(Font *rep)
Definition: OgreFont.h:404
FontType mType
The type of font.
Definition: OgreFont.h:114
T * getPointer() const
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:171
unsigned int uint32
Definition: OgrePlatform.h:246
FontPtr(const FontPtr &r)
Definition: OgreFont.h:405
#define _OgreExport
Definition: OgrePlatform.h:203
const MaterialPtr & getMaterial()
Gets the material generated for this font, as a weak reference.
Definition: OgreFont.h:361
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:384
void clearCodePointRanges()
Clear the list of code point ranges.
Definition: OgreFont.h:338
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:271
GlyphInfo(CodePoint id, const UVRect &rect, Real aspect)
Definition: OgreFont.h:137
Class representing a font in the system.
Definition: OgreFont.h:67
int mTtfMaxBearingY
Max distance to baseline of this (truetype) font.
Definition: OgreFont.h:124
#define OGRE_MUTEX_CONDITIONAL(name)
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:345
FontPtr & operator=(const ResourcePtr &r)
Operator used to convert a ResourcePtr to a FontPtr.
Definition: OgreFont.h:423
Information about the position and size of a glyph in a texture.
Definition: OgreFont.h:131
Ogre::uint32 CodePoint
Definition: OgreFont.h:128
Interface describing a manual resource loader.
Definition: OgreResource.h:512
map< CodePoint, GlyphInfo >::type CodePointMap
Map from unicode code point to texture coordinates.
Definition: OgreFont.h:148
Real mTtfSize
Size of the truetype font, in points.
Definition: OgreFont.h:120
CodePoint codePoint
Definition: OgreFont.h:133
Ogre::FloatRect UVRect
Definition: OgreFont.h:129
uint mTtfResolution
Resolution (dpi) of truetype font.
Definition: OgreFont.h:122
Command object for Font - see ParamCommand.
Definition: OgreFont.h:85
CodePointMap mCodePointMap
Definition: OgreFont.h:149
static CmdSource msSourceCmd
Definition: OgreFont.h:108
static CmdType msTypeCmd
Definition: OgreFont.h:107
const UVRect & getGlyphTexCoords(CodePoint id) const
Returns the texture coordinates of the associated glyph.
Definition: OgreFont.h:250
Generated from a truetype (.ttf) font.
Definition: OgreFont.h:48
Command object for Font - see ParamCommand.
Definition: OgreFont.h:92
String mSource
Source of the font (either an image name or a truetype font)
Definition: OgreFont.h:117
CodePointRangeList mCodePointRangeList
Range of code points to generate glyphs for (truetype only)
Definition: OgreFont.h:161
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:331
MaterialPtr mpMaterial
The material which is generated for this font.
Definition: OgreFont.h:152
Command object for Font - see ParamCommand.
Definition: OgreFont.h:99
TexturePtr mTexture
Texture pointer.
Definition: OgreFont.h:155
void setGlyphAspectRatio(CodePoint id, Real ratio)
Sets the aspect ratio (width / height) of this character.
Definition: OgreFont.h:309
Command object for Font - see ParamCommand.
Definition: OgreFont.h:78
Specialisation of SharedPtr to allow SharedPtr to be assigned to TexturePtr.
Definition: OgreTexture.h:440
static CmdCodePoints msCodePointsCmd
Definition: OgreFont.h:111
static CmdResolution msResolutionCmd
Definition: OgreFont.h:110
Real getGlyphAspectRatio(CodePoint id) const
Gets the aspect ratio (width / height) of this character.
Definition: OgreFont.h:292
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:77
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
#define OGRE_LOCK_MUTEX(name)
Specialisation of SharedPtr to allow SharedPtr to be assigned to FontPtr.
Definition: OgreFont.h:400
const MaterialPtr & getMaterial() const
Gets the material generated for this font, as a weak reference.
Definition: OgreFont.h:353
std::pair< CodePoint, CodePoint > CodePointRange
A range of code points, inclusive on both ends.
Definition: OgreFont.h:144
Defines a generic resource handler.
unsigned int * useCountPointer() const
FontPtr(const ResourcePtr &r)
Definition: OgreFont.h:406
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgreSharedPtr.h:60
_StringBase String
static CmdSize msSizeCmd
Definition: OgreFont.h:109
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:677
bool mAntialiasColour
for TRUE_TYPE font only
Definition: OgreFont.h:158
vector< CodePointRange >::type CodePointRangeList
Definition: OgreFont.h:145
#define OGRE_COPY_AUTO_SHARED_MUTEX(from)
unsigned int uint
Abstract class which is command object which gets/sets parameters.
bool isNull(void) const
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:376