00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00080 #ifndef FREETYPE_H_
00081 #define FREETYPE_H_
00082
00083 #include <malloc.h>
00084 #include <map>
00085 #include <ft2build.h>
00086 #include FT_FREETYPE_H
00087
00088
00089 extern char fontface[];
00090 extern int fontsize;
00096 typedef struct fontCharData_ {
00097 u16 glyphAdvanceX;
00099 u16 textureWidth;
00100 u16 textureHeight;
00102 u16 renderOffsetY;
00104 u32* glyphDataTexture;
00105 } fontCharData;
00106
00107 #define _TEXT(t) L ## t
00108 #define UNICODE_MAX 256
00119 class FreeTypeGX {
00120
00121 private:
00122 FT_Library ftLibrary;
00123 FT_Face ftFace;
00124 FT_GlyphSlot ftSlot;
00126 u8 textureFormat;
00127 std::map<wchar_t, fontCharData> fontData;
00129 static u16 adjustTextureWidth(u16 textureWidth, u8 textureFormat);
00130 static u16 adjustTextureHeight(u16 textureHeight, u8 textureFormat);
00131
00132 void cacheFontData();
00133 void loadFontData(FT_Bitmap *bmp, fontCharData *charData);
00134
00135 void convertBufferToI4(u32* glyphData, fontCharData *charData);
00136 void convertBufferToI8(u32* glyphData, fontCharData *charData);
00137 void convertBufferToIA4(u32* glyphData, fontCharData *charData);
00138 void convertBufferToIA8(u32* glyphData, fontCharData *charData);
00139 void convertBufferToRGBA8(u32* glyphData, fontCharData *charData);
00140 void convertBufferToRGB565(u32* glyphData, fontCharData *charData);
00141 void convertBufferToRGB5A3(u32* glyphData, fontCharData *charData);
00142 void copyTextureToFramebuffer(GXTexObj *texObj, u16 texWidth, u16 texHeight, u16 screenX, u16 screenY, GXColor color);
00143
00144 public:
00145 FreeTypeGX(FT_UInt pointSize, u8 textureFormat = GX_TF_RGBA8);
00146 ~FreeTypeGX();
00147
00148 static u8 convertRGBAToIA4(u32 rgba);
00149 static u16 convertRGBAToIA8(u32 rgba);
00150 static u16 convertRGBAToRGB565(u32 rgba);
00151 static u16 convertRGBAToRGB5A3(u32 rgba);
00152
00153 u16 drawText(u16 x, u16 y, wchar_t *text, GXColor color);
00154 u16 drawText(u16 x, u16 y, wchar_t *text);
00155 u16 drawText(u16 x, u16 y, wchar_t const *text, GXColor color);
00156 u16 drawText(u16 x, u16 y, wchar_t const *text);
00157
00158 };
00159
00160 #endif