OgreFont.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2This source file is a part of OGRE
3(Object-oriented Graphics Rendering Engine)
4
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2013 Torus Knot Software Ltd
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24THE 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
36namespace Ogre
37{
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
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
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
#define _OgreOverlayExport
String doGet(const void *target) const
void doSet(void *target, const String &val)
Command object for Font - see ParamCommand.
Definition OgreFont.h:106
String doGet(const void *target) const
void doSet(void *target, const String &val)
Command object for Font - see ParamCommand.
Definition OgreFont.h:99
void doSet(void *target, const String &val)
String doGet(const void *target) const
Command object for Font - see ParamCommand.
Definition OgreFont.h:92
String doGet(const void *target) const
void doSet(void *target, const String &val)
Command object for Font - see ParamCommand.
Definition OgreFont.h:79
void doSet(void *target, const String &val)
String doGet(const void *target) const
Command object for Font - see ParamCommand.
Definition OgreFont.h:72
String doGet(const void *target) const
void doSet(void *target, const String &val)
Class representing a font in the system.
Definition OgreFont.h:68
virtual ~Font()
bool mAntialiasColour
for TRUE_TYPE font only
Definition OgreFont.h:169
void setSource(const String &source)
Sets the source of the font.
FontType getType(void) const
Gets the type of font.
void createTextureFromFont(void)
Internal method for loading from ttf.
Ogre::FloatRect UVRect
Definition OgreFont.h:140
Real getGlyphAspectRatio(CodePoint id) const
Gets the aspect ratio (width / height) of this character.
Definition OgreFont.h:317
void setTrueTypeSize(Real ttfSize)
Sets the size of a truetype font (only required for FT_TRUETYPE).
map< CodePoint, GlyphInfo >::type CodePointMap
Map from unicode code point to texture coordinates.
Definition OgreFont.h:159
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
MaterialPtr mMaterial
The material which is generated for this font.
Definition OgreFont.h:163
static CmdCharSpacer msCharacterSpacerCmd
Definition OgreFont.h:115
size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
Definition OgreFont.h:182
FontType mType
The type of font.
Definition OgreFont.h:121
virtual void loadImpl()
Internal implementation of the meat of the 'load' action, only called if this resource is not being l...
static CmdCodePoints msCodePointsCmd
Definition OgreFont.h:118
int getTrueTypeMaxBearingY() const
Gets the maximum baseline distance of all glyphs used in the texture.
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
const String & getSource(void) const
Gets the source this font (either an image or a truetype font).
const MaterialPtr & getMaterial() const
Gets the material generated for this font, as a weak reference.
Definition OgreFont.h:378
int mTtfMaxBearingY
Max distance to baseline of this (truetype) font.
Definition OgreFont.h:135
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
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
Font(ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual=false, ManualResourceLoader *loader=0)
Constructor.
std::pair< CodePoint, CodePoint > CodePointRange
A range of code points, inclusive on both ends.
Definition OgreFont.h:155
CodePointMap mCodePointMap
Definition OgreFont.h:160
uint mTtfResolution
Resolution (dpi) of truetype font.
Definition OgreFont.h:133
void setGlyphAspectRatio(CodePoint id, Real ratio)
Sets the aspect ratio (width / height) of this character.
Definition OgreFont.h:334
void setCharacterSpacer(uint charSpacer)
Sets the spacing to allocate for font characters to overlap each other.
const MaterialPtr & getMaterial()
Gets the material generated for this font, as a weak reference.
Definition OgreFont.h:386
void setType(FontType ftype)
Sets the type of font.
void setTrueTypeResolution(uint ttfResolution)
Gets the resolution (dpi) of the font used to generate the texture (only required for FT_TRUETYPE).
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
const GlyphInfo & getGlyphInfo(CodePoint id) const
Gets the information available for a glyph corresponding to a given code point, or throws an exceptio...
Ogre::uint32 CodePoint
Definition OgreFont.h:139
Real getTrueTypeSize(void) const
Gets the point size of the font used to generate the texture.
Real mTtfSize
Size of the truetype font, in points.
Definition OgreFont.h:131
void loadResource(Resource *resource)
Implementation of ManualResourceLoader::loadResource, called when the Texture that this font creates ...
CodePointRangeList mCodePointRangeList
Range of code points to generate glyphs for (truetype only)
Definition OgreFont.h:172
uint getTrueTypeResolution(void) const
Gets the resolution (dpi) of the font used to generate the texture.
uint mCharacterSpacer
Add a gap between letters vertically and horizonally prevents nasty artifacts caused by fonts atypica...
Definition OgreFont.h:128
virtual void unloadImpl()
Internal implementation of the 'unload' action; called regardless of whether this resource is being l...
static CmdSource msSourceCmd
Definition OgreFont.h:114
static CmdSize msSizeCmd
Definition OgreFont.h:116
static CmdResolution msResolutionCmd
Definition OgreFont.h:117
uint getCharacterSpacer(void) const
Gets the spacing to allocate for font characters to overlap each other.
String mSource
Source of the font (either an image name or a truetype font)
Definition OgreFont.h:124
TexturePtr mTexture
Texture pointer.
Definition OgreFont.h:166
static CmdType msTypeCmd
Definition OgreFont.h:113
vector< CodePointRange >::type CodePointRangeList
Definition OgreFont.h:156
const UVRect & getGlyphTexCoords(CodePoint id) const
Returns the texture coordinates of the associated glyph.
Definition OgreFont.h:275
void clearCodePointRanges()
Clear the list of code point ranges.
Definition OgreFont.h:363
Interface describing a manual resource loader.
Abstract class which is command object which gets/sets parameters.
Defines a generic resource handler.
Abstract class representing a loadable resource (e.g.
FontType
Enumerates the types of Font usable in the engine.
Definition OgreFont.h:46
@ FT_TRUETYPE
Generated from a truetype (.ttf) font.
Definition OgreFont.h:48
@ FT_IMAGE
Loaded from an image created by an artist.
Definition OgreFont.h:50
float Real
Software floating point type.
unsigned int uint
unsigned int uint32
unsigned long long int ResourceHandle
_StringBase String
Information about the position and size of a glyph in a texture.
Definition OgreFont.h:143
GlyphInfo(CodePoint id, const UVRect &rect, Real aspect)
Definition OgreFont.h:148
std::map< K, V, P, A > type
std::vector< T, A > type

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