# 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-2005 The OGRE Team
    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
    00034 namespace Ogre
    00035 {
    00036     // Define the number of glyphs allowed
    00037     // We ignore 0-31 since these are control characters
    00038 #if OGRE_WCHAR_T_STRINGS
    00039     // Allow wide chars
    00040     #define OGRE_NUM_GLYPHS (1024 - 32)
    00041 #else
    00042     // Allow 8-bit ASCII
    00043     // (we don't want to offend people with charcodes 127-256 in their name eh cearny? ;)
    00044     // Only chars 33+ are any use though
    00045     #define OGRE_NUM_GLYPHS (256 - 32)
    00046 #endif
    00047
    00048     // How to look up chars
    00049     #define OGRE_GLYPH_INDEX(c) c - 33
    00050
    00052     enum FontType
    00053     {
    00055         FT_TRUETYPE = 1,
    00057         FT_IMAGE = 2
    00058     };
    00059
    00060
    00074     class _OgreExport Font : public Resource, public ManualResourceLoader
    00075     {
    00076     protected:
    00078         class _OgreExport CmdType : public ParamCommand
    00079         {
    00080         public:
    00081             String doGet(const void* target) const;
    00082             void doSet(void* target, const String& val);
    00083         };
    00085         class _OgreExport CmdSource : public ParamCommand
    00086         {
    00087         public:
    00088             String doGet(const void* target) const;
    00089             void doSet(void* target, const String& val);
    00090         };
    00092         class _OgreExport CmdSize : public ParamCommand
    00093         {
    00094         public:
    00095             String doGet(const void* target) const;
    00096             void doSet(void* target, const String& val);
    00097         };
    00099         class _OgreExport CmdResolution : public ParamCommand
    00100         {
    00101         public:
    00102             String doGet(const void* target) const;
    00103             void doSet(void* target, const String& val);
    00104         };
    00105
    00106         // Command object for setting / getting parameters
    00107         static CmdType msTypeCmd;
    00108         static CmdSource msSourceCmd;
    00109         static CmdSize msSizeCmd;
    00110         static CmdResolution msResolutionCmd;
    00111
    00113         FontType mType;
    00114
    00116         String mSource;
    00117
    00119         Real mTtfSize;
    00121         uint mTtfResolution;
    00122
    00123
    00125         Real mTexCoords_u1[OGRE_NUM_GLYPHS];
    00127         Real mTexCoords_u2[OGRE_NUM_GLYPHS];
    00129         Real mTexCoords_v1[OGRE_NUM_GLYPHS];
    00131         Real mTexCoords_v2[OGRE_NUM_GLYPHS];
    00132
    00134         Real mAspectRatio[OGRE_NUM_GLYPHS];
    00135
    00137         MaterialPtr mpMaterial;
    00138
    00140         TexturePtr mTexture;
    00141
    00143         bool mAntialiasColour;
    00144
    00146         void createTextureFromFont(void);
    00147
    00149         virtual void loadImpl();
    00151         virtual void unloadImpl();
    00153         size_t calculateSize(void) const { return 0; } // permanent resource is in the texture
    00154     public:
    00155
    00159         Font(ResourceManager* creator, const String& name, ResourceHandle handle,
    00160             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00161         virtual ~Font();
    00162
    00164         void setType(FontType ftype);
    00165
    00167         FontType getType(void) const;
    00168
    00182         void setSource(const String& source);
    00183
    00186         const String& getSource(void) const;
    00187
    00193         void setTrueTypeSize(Real ttfSize);
    00198         void setTrueTypeResolution(uint ttfResolution);
    00199
    00206         Real getTrueTypeSize(void) const;
    00211         uint getTrueTypeResolution(void) const;
    00212
    00215         std::pair< uint, uint > StrBBox( const String & text, Real char_height, RenderWindow & window  );
    00216
    00217
    00223         inline void getGlyphTexCoords(OgreChar id, Real& u1, Real& v1, Real& u2, Real& v2 ) const
    00224         {
    00225             unsigned OgreChar idx = OGRE_GLYPH_INDEX(id);
    00226             u1 = mTexCoords_u1[ idx ];
    00227             v1 = mTexCoords_v1[ idx ];
    00228             u2 = mTexCoords_u2[ idx ];
    00229             v2 = mTexCoords_v2[ idx ];
    00230         }
    00231
    00238         inline void setGlyphTexCoords( OgreChar id, Real u1, Real v1, Real u2, Real v2 )
    00239         {
    00240             unsigned OgreChar idx = OGRE_GLYPH_INDEX(id);
    00241             mTexCoords_u1[ idx ] = u1;
    00242             mTexCoords_v1[ idx ] = v1;
    00243             mTexCoords_u2[ idx ] = u2;
    00244             mTexCoords_v2[ idx ] = v2;
    00245             mAspectRatio[ idx ] = ( u2 - u1 ) / ( v2 - v1 );
    00246         }
    00248         inline Real getGlyphAspectRatio( OgreChar id ) const
    00249         {
    00250             unsigned OgreChar idx = OGRE_GLYPH_INDEX(id);
    00251             return mAspectRatio[ idx ];
    00252         }
    00258         inline void setGlyphAspectRatio( OgreChar id, Real ratio )
    00259         {
    00260             unsigned OgreChar idx = OGRE_GLYPH_INDEX(id);
    00261             mAspectRatio[ idx ] = ratio;
    00262         }
    00267         inline const MaterialPtr& getMaterial() const
    00268         {
    00269             return mpMaterial;
    00270         }
    00275         inline const MaterialPtr& getMaterial()
    00276         {
    00277             return mpMaterial;
    00278         }
    00290         inline void setAntialiasColour(bool enabled)
    00291         {
    00292             mAntialiasColour = enabled;
    00293         }
    00294
    00298         inline bool getAntialiasColour(void) const
    00299         {
    00300             return mAntialiasColour;
    00301         }
    00302
    00306         void loadResource(Resource* resource);
    00307     };
    00314     class _OgreExport FontPtr : public SharedPtr<Font>
    00315     {
    00316     public:
    00317         FontPtr() : SharedPtr<Font>() {}
    00318         explicit FontPtr(Font* rep) : SharedPtr<Font>(rep) {}
    00319         FontPtr(const FontPtr& r) : SharedPtr<Font>(r) {}
    00320         FontPtr(const ResourcePtr& r) : SharedPtr<Font>()
    00321         {
    00322             // lock & copy other mutex pointer
    00323             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00324             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00325             pRep = static_cast<Font*>(r.getPointer());
    00326             pUseCount = r.useCountPointer();
    00327             if (pUseCount)
    00328             {
    00329                 ++(*pUseCount);
    00330             }
    00331         }
    00332
    00334         FontPtr& operator=(const ResourcePtr& r)
    00335         {
    00336             if (pRep == static_cast<Font*>(r.getPointer()))
    00337                 return *this;
    00338             release();
    00339             // lock & copy other mutex pointer
    00340             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00341             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00342             pRep = static_cast<Font*>(r.getPointer());
    00343             pUseCount = r.useCountPointer();
    00344             if (pUseCount)
    00345             {
    00346                 ++(*pUseCount);
    00347             }
    00348             return *this;
    00349         }
    00350     };
    00351 }
    00352
    00353 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:44 2006