Main Page | Class Hierarchy | Class List | File List | Class Members

aedFont.h

00001 
00002 /*
00003  * The aedFont class
00004  * This class supplies an easy-to-use interface to FreeType
00005  * Initial design by Ivan Stankovic <pokemon@fly.srk.fer.hr>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public
00018  * License along with this library; if not, write to the Free
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 #ifndef AEDFONT_H
00024 #define AEDFONT_H
00025 
00026 #include "dllmacros.h"
00027 #include "SDL.h"
00028 #include "aedColor.h"
00029 
00030 #ifdef _MSC_VER
00031 #pragma warning(disable:4800)
00032 #endif
00033 
00034 #define AED_FONT_STYLE_NORMAL        0x00
00035 #define AED_FONT_STYLE_BOLD          0x01
00036 #define AED_FONT_STYLE_ITALIC        0x02
00037 #define AED_FONT_STYLE_UNDERLINE     0x04
00038 
00039 typedef struct _TTF_Font TTF_Font;
00040 
00042 class DLLEXPORT aedFont
00043 {
00044   public:
00045     aedFont();
00046     virtual ~ aedFont();
00047 
00048     int getStyle() const;
00049     void setStyle(int style);
00050 
00051     int getHeight() const;
00052     int getAscent() const;
00053     int getDescent() const;
00054     int getLineSkip() const;
00055 
00056     bool getGlyphMetrics(Uint16 c, int *minx, int *maxx, int *miny, int *maxy,
00057                          int *advance);
00058 
00059     int getTextSize(const char *text, Uint16 * w, Uint16 * h);
00060 
00061     // These return rendered string as a surface which the caller must free
00062     SDL_Surface *renderTextSolid(const char *str, const aedColor & color);
00063     SDL_Surface *renderTextShaded(const char *str, const aedColor & fg,
00064                                   const aedColor & bg);
00065     SDL_Surface *renderTextBlended(const char *str, const aedColor & color);
00066 
00067     // These are just for convenience, render directly to the given surface
00068     void renderTextSolid(SDL_Surface * s, int x, int y, const char *str,
00069                          const aedColor & color);
00070     void renderTextShaded(SDL_Surface * s, int x, int y, const char *str,
00071                           const aedColor & fg, const aedColor & bg);
00072     void renderTextBlended(SDL_Surface * s, int x, int y, const char *str,
00073                            const aedColor & color);
00074 
00075   private:
00076       TTF_Font * data;
00077 
00078     // This isn't the best design, but it does what we need:
00079     // allow only aedApp to open and close fonts
00080     friend class aedApp;
00081     bool openFont(const char *file, int pointsize);
00082     bool openFont(unsigned char *data, unsigned long int datasize,
00083                   int pointsize);
00084     void closeFont();
00085 
00086   public:
00087     static Uint16 getUnicode(const char *utf8, int *advance)
00088     {
00089         int i = 0;
00090         Uint16 ch;
00091 
00092           ch = ((const unsigned char *) utf8)[i];
00093         if(ch >= 0xF0)
00094         {
00095             ch = (Uint16) (utf8[i] & 0x07) << 18;
00096             ch |= (Uint16) (utf8[++i] & 0x3F) << 12;
00097             ch |= (Uint16) (utf8[++i] & 0x3F) << 6;
00098             ch |= (Uint16) (utf8[++i] & 0x3F);
00099         }
00100         else if(ch >= 0xE0)
00101         {
00102             ch = (Uint16) (utf8[i] & 0x3F) << 12;
00103             ch |= (Uint16) (utf8[++i] & 0x3F) << 6;
00104             ch |= (Uint16) (utf8[++i] & 0x3F);
00105         }
00106         else if(ch >= 0xC0)
00107         {
00108             ch = (Uint16) (utf8[i] & 0x3F) << 6;
00109             ch |= (Uint16) (utf8[++i] & 0x3F);
00110         }
00111         *advance = (i + 1);
00112         return ch;
00113     }
00114 };
00115 
00116 #endif /* AEDFONT_H */

Generated on Mon Mar 1 19:56:18 2004 for aedGUI by doxygen 1.3.6