ft2_font.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * ft2_font.hpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id$
00006  *
00007  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
00008  *          Olivier Teulière <ipkiss@via.ecp.fr>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef FT2_FONT_HPP
00026 #define FT2_FONT_HPP
00027 
00028 #include <ft2build.h>
00029 #include FT_FREETYPE_H
00030 #include FT_GLYPH_H
00031 #include <string>
00032 #include <map>
00033 
00034 #include "generic_font.hpp"
00035 
00036 class UString;
00037 
00038 
00039 /// Freetype2 font
00040 class FT2Font: public GenericFont
00041 {
00042     public:
00043         FT2Font( intf_thread_t *pIntf, const string &rName, int size );
00044         virtual ~FT2Font();
00045 
00046         /// Initialize the object. Returns false if it failed
00047         virtual bool init();
00048 
00049         /// Render a string on a bitmap.
00050         /// If maxWidth != -1, the text is truncated with '...'
00051         virtual GenericBitmap *drawString( const UString &rString,
00052             uint32_t color, int maxWidth = -1 ) const;
00053 
00054         /// Get the text height
00055         virtual int getSize() const { return m_height; }
00056 
00057     private:
00058         typedef struct
00059         {
00060             FT_Glyph m_glyph;
00061             FT_BBox m_size;
00062             int m_index;
00063             int m_advance;
00064         } Glyph_t;
00065         typedef map<uint32_t,Glyph_t> GlyphMap_t;
00066 
00067         /// File name
00068         const string m_name;
00069         /// Buffer to store the font
00070         void *m_buffer;
00071         /// Pixel size of the font
00072         int m_size;
00073         /// Handle to FT library
00074         FT_Library m_lib;
00075         /// Font face
00076         FT_Face m_face;
00077         /// Font metrics
00078         int m_height, m_ascender, m_descender;
00079         /// Glyph cache
00080         mutable GlyphMap_t m_glyphCache;
00081 
00082         /// Get the glyph corresponding to the given code
00083         Glyph_t &getGlyph( uint32_t code ) const;
00084 };
00085 
00086 
00087 #endif

Generated on Wed Aug 13 08:02:38 2008 for VLC by  doxygen 1.5.1