OGRE: OgreFont.h Source File - OGRE Documentation

# OgreFont.h

Go to the documentation of this file.

    00001 /*-------------------------------------------------------------------------
    00002 This source file is a part of OGRE
    00003 (Object-oriented Graphics Rendering Engine)
    00004
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This library is free software; you can redistribute it and/or modify it
    00011 under the terms of the GNU Lesser General Public License (LGPL) as
    00012 published by the Free Software Foundation; either version 2.1 of the
    00013 License, or (at your option) any later version.
    00014
    00015 This library is distributed in the hope that it will be useful, but
    00016 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    00017 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00018 License for more details.
    00019
    00020 You should have received a copy of the GNU Lesser General Public License
    00021 along with this library; if not, write to the Free Software Foundation,
    00022 Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA or go to
    00023 http://www.gnu.org/copyleft/lesser.txt
    00024 -------------------------------------------------------------------------*/
    00025
    00026 #ifndef _Font_H__
    00027 #define _Font_H__
    00028
    00029 #include "OgrePrerequisites.h"
    00030 #include "OgreResource.h"
    00031 #include "OgreTexture.h"
    00032 #include "OgreMaterial.h"
    00033 #include "OgreCommon.h"
    00034
    00035 namespace Ogre
    00036 {
    00038     enum FontType
    00039     {
    00041         FT_TRUETYPE = 1,
    00043         FT_IMAGE = 2
    00044     };
    00045
    00046
    00060     class _OgreExport Font : public Resource, public ManualResourceLoader
    00061     {
    00062     protected:
    00064         class _OgreExport CmdType : public ParamCommand
    00065         {
    00066         public:
    00067             String doGet(const void* target) const;
    00068             void doSet(void* target, const String& val);
    00069         };
    00071         class _OgreExport CmdSource : public ParamCommand
    00072         {
    00073         public:
    00074             String doGet(const void* target) const;
    00075             void doSet(void* target, const String& val);
    00076         };
    00078         class _OgreExport CmdSize : public ParamCommand
    00079         {
    00080         public:
    00081             String doGet(const void* target) const;
    00082             void doSet(void* target, const String& val);
    00083         };
    00085         class _OgreExport CmdResolution : public ParamCommand
    00086         {
    00087         public:
    00088             String doGet(const void* target) const;
    00089             void doSet(void* target, const String& val);
    00090         };
    00092         class _OgreExport CmdCodePoints : public ParamCommand
    00093         {
    00094         public:
    00095             String doGet(const void* target) const;
    00096             void doSet(void* target, const String& val);
    00097         };
    00098
    00099         // Command object for setting / getting parameters
    00100         static CmdType msTypeCmd;
    00101         static CmdSource msSourceCmd;
    00102         static CmdSize msSizeCmd;
    00103         static CmdResolution msResolutionCmd;
    00104         static CmdCodePoints msCodePointsCmd;
    00105
    00107         FontType mType;
    00108
    00110         String mSource;
    00111
    00113         Real mTtfSize;
    00115         uint mTtfResolution;
    00117         int mTtfMaxBearingY;
    00118
    00119
    00120     public:
    00121         typedef Ogre::uint32 CodePoint;
    00122         typedef Ogre::FloatRect UVRect;
    00124         struct GlyphInfo
    00125         {
    00126             CodePoint codePoint;
    00127             UVRect uvRect;
    00128             Real aspectRatio;
    00129
    00130             GlyphInfo(CodePoint id, const UVRect& rect, Real aspect)
    00131                 : codePoint(id), uvRect(rect), aspectRatio(aspect)
    00132             {
    00133
    00134             }
    00135         };
    00137         typedef std::pair<CodePoint, CodePoint> CodePointRange;
    00138         typedef std::vector<CodePointRange> CodePointRangeList;
    00139     protected:
    00141         typedef std::map<CodePoint, GlyphInfo> CodePointMap;
    00142         CodePointMap mCodePointMap;
    00143
    00145         MaterialPtr mpMaterial;
    00146
    00148         TexturePtr mTexture;
    00149
    00151         bool mAntialiasColour;
    00152
    00154         CodePointRangeList mCodePointRangeList;
    00155
    00157         void createTextureFromFont(void);
    00158
    00160         virtual void loadImpl();
    00162         virtual void unloadImpl();
    00164         size_t calculateSize(void) const { return 0; } // permanent resource is in the texture
    00165     public:
    00166
    00170         Font(ResourceManager* creator, const String& name, ResourceHandle handle,
    00171             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00172         virtual ~Font();
    00173
    00175         void setType(FontType ftype);
    00176
    00178         FontType getType(void) const;
    00179
    00195         void setSource(const String& source);
    00196
    00199         const String& getSource(void) const;
    00200
    00206         void setTrueTypeSize(Real ttfSize);
    00211         void setTrueTypeResolution(uint ttfResolution);
    00212
    00219         Real getTrueTypeSize(void) const;
    00224         uint getTrueTypeResolution(void) const;
    00234         int getTrueTypeMaxBearingY() const;
    00235
    00236
    00243         inline const UVRect& getGlyphTexCoords(CodePoint id) const
    00244         {
    00245             CodePointMap::const_iterator i = mCodePointMap.find(id);
    00246             if (i != mCodePointMap.end())
    00247             {
    00248                 return i->second.uvRect;
    00249             }
    00250             else
    00251             {
    00252                 static UVRect nullRect(0.0, 0.0, 0.0, 0.0);
    00253                 return nullRect;
    00254             }
    00255         }
    00256
    00264         inline void setGlyphTexCoords(CodePoint id, Real u1, Real v1, Real u2, Real v2, Real textureAspect)
    00265         {
    00266             CodePointMap::iterator i = mCodePointMap.find(id);
    00267             if (i != mCodePointMap.end())
    00268             {
    00269                 i->second.uvRect.left = u1;
    00270                 i->second.uvRect.top = v1;
    00271                 i->second.uvRect.right = u2;
    00272                 i->second.uvRect.bottom = v2;
    00273                 i->second.aspectRatio = textureAspect * (u2 - u1)  / (v2 - v1);
    00274             }
    00275             else
    00276             {
    00277                 mCodePointMap.insert(
    00278                     CodePointMap::value_type(id,
    00279                         GlyphInfo(id, UVRect(u1, v1, u2, v2),
    00280                             textureAspect * (u2 - u1)  / (v2 - v1))));
    00281             }
    00282
    00283         }
    00285         inline Real getGlyphAspectRatio(CodePoint id) const
    00286         {
    00287             CodePointMap::const_iterator i = mCodePointMap.find(id);
    00288             if (i != mCodePointMap.end())
    00289             {
    00290                 return i->second.aspectRatio;
    00291             }
    00292             else
    00293             {
    00294                 return 1.0;
    00295             }
    00296         }
    00302         inline void setGlyphAspectRatio(CodePoint id, Real ratio)
    00303         {
    00304             CodePointMap::iterator i = mCodePointMap.find(id);
    00305             if (i != mCodePointMap.end())
    00306             {
    00307                 i->second.aspectRatio = ratio;
    00308             }
    00309         }
    00310
    00314         const GlyphInfo& getGlyphInfo(CodePoint id) const;
    00315
    00324         void addCodePointRange(const CodePointRange& range)
    00325         {
    00326             mCodePointRangeList.push_back(range);
    00327         }
    00328
    00331         void clearCodePointRanges()
    00332         {
    00333             mCodePointRangeList.clear();
    00334         }
    00338         const CodePointRangeList& getCodePointRangeList() const
    00339         {
    00340             return mCodePointRangeList;
    00341         }
    00346         inline const MaterialPtr& getMaterial() const
    00347         {
    00348             return mpMaterial;
    00349         }
    00354         inline const MaterialPtr& getMaterial()
    00355         {
    00356             return mpMaterial;
    00357         }
    00369         inline void setAntialiasColour(bool enabled)
    00370         {
    00371             mAntialiasColour = enabled;
    00372         }
    00373
    00377         inline bool getAntialiasColour(void) const
    00378         {
    00379             return mAntialiasColour;
    00380         }
    00381
    00385         void loadResource(Resource* resource);
    00386     };
    00393     class _OgreExport FontPtr : public SharedPtr<Font>
    00394     {
    00395     public:
    00396         FontPtr() : SharedPtr<Font>() {}
    00397         explicit FontPtr(Font* rep) : SharedPtr<Font>(rep) {}
    00398         FontPtr(const FontPtr& r) : SharedPtr<Font>(r) {}
    00399         FontPtr(const ResourcePtr& r) : SharedPtr<Font>()
    00400         {
    00401             // lock & copy other mutex pointer
    00402             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00403             {
    00404                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00405                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00406                 pRep = static_cast<Font*>(r.getPointer());
    00407                 pUseCount = r.useCountPointer();
    00408                 if (pUseCount)
    00409                 {
    00410                     ++(*pUseCount);
    00411                 }
    00412             }
    00413         }
    00414
    00416         FontPtr& operator=(const ResourcePtr& r)
    00417         {
    00418             if (pRep == static_cast<Font*>(r.getPointer()))
    00419                 return *this;
    00420             release();
    00421             // lock & copy other mutex pointer
    00422             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00423             {
    00424                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00425                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00426                 pRep = static_cast<Font*>(r.getPointer());
    00427                 pUseCount = r.useCountPointer();
    00428                 if (pUseCount)
    00429                 {
    00430                     ++(*pUseCount);
    00431                 }
    00432             }
    00433             else
    00434             {
    00435                 // RHS must be a null pointer
    00436                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    00437                 setNull();
    00438             }
    00439             return *this;
    00440         }
    00441     };
    00442 }
    00443
    00444 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:17 2009