# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/Font.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.org                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #ifndef Font_INCLUDE_ONCE
    00033 #define Font_INCLUDE_ONCE
    00034
    00035 #include <vlCore/Object.hpp>
    00036 #include <vlCore/Vector4.hpp>
    00037 #include <vlCore/String.hpp>
    00038 #include <vlGraphics/link_config.hpp>
    00039 #include <map>
    00040
    00041 //-----------------------------------------------------------------------------
    00042 struct FT_FaceRec_;
    00043 typedef struct FT_FaceRec_*  FT_Face;
    00044 //-----------------------------------------------------------------------------
    00045 namespace vl
    00046 {
    00047   class Font;
    00048   class FontManager;
    00049   //-----------------------------------------------------------------------------
    00050   // Glyph
    00051   //-----------------------------------------------------------------------------
    00055   class Glyph: public Object
    00056   {
    00057     VL_INSTRUMENT_CLASS(vl::Glyph, Object)
    00058
    00059   private:
    00060     Glyph(const Glyph& other): Object(other)
    00061     {
    00062       VL_DEBUG_SET_OBJECT_NAME()
    00063     }
    00064     void operator=(const Glyph&){}
    00065
    00066   public:
    00067     Glyph(): mFont(NULL), mS0(0), mT0(0), mS1(0), mT1(0), mGlyphIndex(0), mTextureHandle(0), mWidth(0), mHeight(0), mLeft(0), mTop(0) {}
    00068
    00069     ~Glyph();
    00070
    00071     unsigned int textureHandle() const { return mTextureHandle; }
    00072     void setTextureHandle(unsigned int handle) { mTextureHandle = handle; }
    00073
    00074     int width() const { return mWidth; }
    00075     void setWidth(int width) { mWidth = width; }
    00076
    00077     int height() const { return mHeight; }
    00078     void setHeight(int height) { mHeight = height; }
    00079
    00080     int left() const { return mLeft; }
    00081     void setLeft(int left) { mLeft = left; }
    00082
    00083     int top() const { return mTop; }
    00084     void setTop(int top) { mTop = top; }
    00085
    00086     float s0() const { return mS0; }
    00087     void setS0(float s0) { mS0 = s0; }
    00088
    00089     float t0() const { return mT0; }
    00090     void setT0(float t0) { mT0 = t0; }
    00091
    00092     float s1() const { return mS1; }
    00093     void setS1(float s1) { mS1 = s1; }
    00094
    00095     float t1() const { return mT1; }
    00096     void setT1(float t1) { mT1 = t1; }
    00097
    00098     const fvec2& advance() const { return mAdvance; }
    00099     void setAdvance(const fvec2& advance) { mAdvance = advance; }
    00100
    00101     unsigned int glyphIndex() const { return mGlyphIndex; }
    00102     void setGlyphIndex(unsigned int glyph_index) { mGlyphIndex = glyph_index; }
    00103
    00104     const Font* font() const { return mFont; }
    00105     void setFont(Font* font) { mFont = font; }
    00106
    00107   protected:
    00108     Font* mFont;
    00109     fvec2 mAdvance;
    00110     float mS0;
    00111     float mT0;
    00112     float mS1;
    00113     float mT1;
    00114     unsigned int mGlyphIndex;
    00115     unsigned int mTextureHandle;
    00116     int mWidth;
    00117     int mHeight;
    00118     int mLeft;
    00119     int mTop;
    00120   };
    00121   //-----------------------------------------------------------------------------
    00122   // Font
    00123   //-----------------------------------------------------------------------------
    00127   class VLGRAPHICS_EXPORT Font: public Object
    00128   {
    00129     VL_INSTRUMENT_CLASS(vl::Font, Object)
    00130
    00131     friend class CoreText;
    00132     friend class Text;
    00133     friend class FontManager;
    00134
    00136     void operator=(const Font&) { VL_TRAP() } // should never get used
    00137
    00139     Font(const Font& other): Object(other) { VL_TRAP() } // should never get used
    00140
    00142     Font(FontManager* fm = NULL);
    00143
    00145     Font(FontManager* fm, const String& font_file, int size );
    00146
    00147   public:
    00149     ~Font();
    00150
    00152     bool operator<(const Font& other) const
    00153     {
    00154       if (filePath() != other.filePath())
    00155         return filePath() < other.filePath();
    00156       else
    00157         return size() < other.size();
    00158     }
    00159
    00161     const String& filePath() const { return mFilePath; }
    00162
    00164     void loadFont(const String& path);
    00165
    00167     int size() const { return mSize; }
    00168
    00170     void setSize(int size);
    00171
    00173     Glyph* glyph(int character);
    00174
    00176     void setSmooth(bool smooth);
    00177
    00179     bool smooth() const { return mSmooth; }
    00180
    00182     void releaseFreeTypeData();
    00183
    00185     void setFontManager(FontManager* fm) { mFontManager = fm; }
    00186
    00188     const FontManager* fontManager() const { return mFontManager; }
    00189
    00191     FontManager* fontManager() { return mFontManager; }
    00192
    00195     bool freeTypeLoadForceAutoHint() const { return mFreeTypeLoadForceAutoHint; }
    00196
    00199     void setFreeTypLoadForceAutoHint(bool enable) { mFreeTypeLoadForceAutoHint = enable; }
    00200
    00201   protected:
    00202     FontManager* mFontManager;
    00203     String mFilePath;
    00204     std::map< int, ref<Glyph> > mGlyphMap;
    00205     FT_Face mFT_Face;
    00206     std::vector<char> mMemoryFile;
    00207     int mSize;
    00208     float mHeight;
    00209     bool mSmooth;
    00210     bool mFreeTypeLoadForceAutoHint;
    00211   };
    00212   //-----------------------------------------------------------------------------
    00213 }
    00214
    00215 #endif

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:37.
Permission is granted to use this page to write and publish articles regarding Visualization Library.