00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00134 #ifndef FREETYPEGX_H_
00135 #define FREETYPEGX_H_
00136
00137 #include <gccore.h>
00138 #include <ft2build.h>
00139 #include FT_FREETYPE_H
00140 #include <Metaphrasis.h>
00141
00142 #include <malloc.h>
00143 #include <string.h>
00144 #include <map>
00145
00146
00147 extern char fontface[];
00148 extern int fontsize;
00154 typedef struct fontCharData_ {
00155 uint16_t glyphAdvanceX;
00157 uint16_t textureWidth;
00158 uint16_t textureHeight;
00160 uint16_t renderOffsetY;
00161 uint16_t renderOffsetMax;
00162 uint16_t renderOffsetMin;
00164 uint32_t* glyphDataTexture;
00165 } fontCharData;
00166
00167 #define _TEXT(t) L ## t
00178 class FreeTypeGX {
00179
00180 private:
00181 FT_Library ftLibrary;
00182 FT_Face ftFace;
00183 FT_GlyphSlot ftSlot;
00185 uint8_t textureFormat;
00186 uint8_t positionFormat;
00187 std::map<wchar_t, fontCharData> fontData;
00189 static uint16_t adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat);
00190 static uint16_t adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat);
00191
00192 void clearFontData();
00193 uint16_t cacheAllGlyphData();
00194 fontCharData *cacheGlyphData(wchar_t charCode);
00195 void loadGlyphData(FT_Bitmap *bmp, fontCharData *charData);
00196 void copyTextureToFramebuffer(GXTexObj *texObj, uint16_t texWidth, uint16_t texHeight, uint16_t screenX, uint16_t screenY, GXColor color);
00197
00198 public:
00199 FreeTypeGX(uint8_t textureFormat = GX_TF_RGBA8, uint8_t positionFormat = GX_POS_XYZ);
00200 ~FreeTypeGX();
00201
00202 uint16_t loadFont(uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll = false);
00203 uint16_t loadFont(const uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll = false);
00204
00205 uint16_t drawText(uint16_t x, uint16_t y, wchar_t *text, GXColor color);
00206 uint16_t drawText(uint16_t x, uint16_t y, wchar_t *text);
00207 uint16_t drawText(uint16_t x, uint16_t y, wchar_t const *text, GXColor color);
00208 uint16_t drawText(uint16_t x, uint16_t y, wchar_t const *text);
00209
00210 uint16_t getWidth(wchar_t *text);
00211 uint16_t getWidth(wchar_t const *text);
00212 uint16_t getHeight(wchar_t *text);
00213 uint16_t getHeight(wchar_t const *text);
00214 };
00215
00216 #endif