Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgfont.h

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2007-04-13 16:15:56 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/include/pgfont.h,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00033 #ifndef PG_FONT_H
00034 #define PG_FONT_H
00035 
00036 #include "paragui.h"
00037 #include "pgdatacontainer.h"
00038 #include "pgcolor.h"
00039 #include "pgrect.h"
00040 #include "pgstring.h"
00041 
00042 #include <ft2build.h>
00043 #include FT_FREETYPE_H
00044 #include FT_ERRORS_H
00045 #include FT_CACHE_H
00046 #include FT_CACHE_IMAGE_H
00047 #include FT_CACHE_SMALL_BITMAPS_H
00048 
00049 #ifdef HASH_MAP_INC
00050 #include HASH_MAP_INC
00051 #endif
00052 #include <map>
00053 
00054 class PG_FontFaceCacheItem;
00055 class PG_GlyphCacheItem;
00056 struct PG_FontDataInternal;
00057 
00063 class DECLSPEC PG_Font {
00064 public:
00065 
00067         typedef enum {
00068             NORMAL = 0x00,
00069             BOLD = 0x01,
00070             ITALIC = 0x02,
00071             UNDERLINE = 0x04
00072         } Style;
00073 
00080         PG_Font(const std::string& fontfile, int size=14, int index=0);
00081 
00082    PG_Font( const PG_Font& font );
00083 
00084    PG_Font& operator= ( const PG_Font& font );
00085    
00088         virtual ~PG_Font();
00089 
00092         int GetFontAscender();
00093 
00096         int GetFontDescender();
00097 
00102         int GetFontHeight();
00103 
00108         void SetColor(const PG_Color& c);
00109    void SetHighlightColor(const PG_Color& c);
00110 
00115         PG_Color GetColor();
00116    PG_Color GetHighlightColor();
00117 
00122         void SetAlpha(int a);
00123 
00128         int GetAlpha();
00129 
00134         void SetSize(int s);
00135 
00140         int GetSize();
00141 
00144         void SetStyle(Style s);
00145 
00148         Style GetStyle();
00149 
00156         bool SetName(const std::string& fontfile);
00157 
00162         const std::string& GetName();
00163 
00164         void SetIndex(int index);
00165 
00166         int GetIndex();
00167 
00168 private:
00169 
00170    void copy( const PG_Font& font );
00171    void unlink();
00172    
00173         DLLLOCAL PG_FontFaceCacheItem* GetFaceCache(int index=0);
00174 
00175         PG_FontDataInternal* my_internaldata;
00176 
00177         friend class PG_FontEngine;
00178 };
00179 
00180 
00186 class DECLSPEC PG_FontEngine {
00187 public:
00188 
00190         PG_FontEngine();
00191 
00193         ~PG_FontEngine();
00194 
00205         static bool RenderText(SDL_Surface *Surface, const PG_Rect& ClipRect, int BaseLineX, int BaseLineY, const PG_String& Text, PG_Font* ParamIn);
00206 
00207         static bool RenderText(SDL_Surface *Surface, const PG_Rect *ClipRect, int BaseLineX, int BaseLineY, const PG_String& Text, PG_Font* ParamIn);
00208 
00211         static bool GetTextSize(const PG_String& Text, PG_Font* ParamIn, Uint16 *Width = NULL, Uint16 *Height = NULL, int *BaselineY = NULL, int *FontLineSkip = NULL, Uint16 *FontHeight = NULL, int *Ascent = NULL, int *Descent = NULL);
00212 
00213 protected:
00214 
00217         static bool BlitFTBitmap(SDL_Surface *Surface, FT_Bitmap *Bitmap, int PosX, int PosY, PG_Font* Param, const PG_Rect *ClipRect);
00218 
00221         static void FontEngineError(FT_Error error);
00222 
00223 private:
00224 
00231         static PG_FontFaceCacheItem* LoadFontFace(const std::string& filename, FT_F26Dot6 fontsize, int index = 0);
00232 
00235         static PG_GlyphCacheItem* GetGlyph(PG_Font *Param, int glyph_index);
00236 
00237         typedef std::map<FT_F26Dot6, PG_FontFaceCacheItem*> MAP_SUBITEMS;
00238 
00239         class FONT_ITEM {
00240         public:
00241                 FONT_ITEM() : memdata(NULL) {}
00242                 ;
00243 
00244                 virtual ~FONT_ITEM();
00245 
00246                 std::string name;
00247                 PG_DataContainer* memdata;
00248                 MAP_SUBITEMS subitems;
00249         };
00250 
00251         typedef std::map<std::string, FONT_ITEM*> MAP_FONTS;
00252 
00253         static MAP_FONTS my_fontcache;
00254         static FT_Library my_library;
00255 
00256         friend class PG_Font;
00257 };
00258 
00259 #endif

Generated on Tue Jun 24 01:27:48 2008 for Advanced Strategic Command by  doxygen 1.4.2