00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
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
00079
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