00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00097 #ifndef FREETYPEGX_H_
00098 #define FREETYPEGX_H_
00099
00100 #include <gccore.h>
00101 #include <ft2build.h>
00102 #include FT_FREETYPE_H
00103 #include <Metaphrasis.h>
00104
00105 #include <malloc.h>
00106 #include <string.h>
00107 #include <map>
00108
00109
00110 extern char fontface[];
00111 extern int fontsize;
00117 typedef struct fontCharData_ {
00118 uint16_t glyphAdvanceX;
00120 uint16_t textureWidth;
00121 uint16_t textureHeight;
00123 uint16_t renderOffsetY;
00124 uint16_t renderOffsetMax;
00125 uint16_t renderOffsetMin;
00127 uint32_t* glyphDataTexture;
00128 } fontCharData;
00129
00130 #define _TEXT(t) L ## t
00141 class FreeTypeGX {
00142
00143 private:
00144 FT_Library ftLibrary;
00145 FT_Face ftFace;
00146 FT_GlyphSlot ftSlot;
00148 uint8_t textureFormat;
00149 std::map<wchar_t, fontCharData> fontData;
00151 static uint16_t adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat);
00152 static uint16_t adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat);
00153
00154 uint16_t cacheAllGlyphData();
00155 fontCharData *cacheGlyphData(wchar_t charCode);
00156 void loadGlyphData(FT_Bitmap *bmp, fontCharData *charData);
00157 void copyTextureToFramebuffer(GXTexObj *texObj, uint16_t texWidth, uint16_t texHeight, uint16_t screenX, uint16_t screenY, GXColor color);
00158
00159 public:
00160 FreeTypeGX(FT_UInt pointSize, uint8_t textureFormat = GX_TF_RGBA8, bool cacheAll = false);
00161 ~FreeTypeGX();
00162
00163 uint16_t drawText(uint16_t x, uint16_t y, wchar_t *text, GXColor color);
00164 uint16_t drawText(uint16_t x, uint16_t y, wchar_t *text);
00165 uint16_t drawText(uint16_t x, uint16_t y, wchar_t const *text, GXColor color);
00166 uint16_t drawText(uint16_t x, uint16_t y, wchar_t const *text);
00167
00168 uint16_t getWidth(wchar_t *text);
00169 uint16_t getWidth(wchar_t const *text);
00170 uint16_t getHeight(wchar_t *text);
00171 uint16_t getHeight(wchar_t const *text);
00172 };
00173
00174 #endif