From 88ab764854bb138ed71736c9d7e25e1dc2e3ccb0 Mon Sep 17 00:00:00 2001 From: "ardi@ist-einmalig.de" Date: Mon, 15 Jun 2009 15:29:27 +0000 Subject: [PATCH] * added custom font. its called "font.ttf" and will loaded from theme-path (issue 541) * little Bugfix --- source/FreeTypeGX.cpp | 16 ++++++++++------ source/FreeTypeGX.h | 4 ++-- source/main.cpp | 24 ++++++++++++++++++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/source/FreeTypeGX.cpp b/source/FreeTypeGX.cpp index d469fb4a..bf395b09 100644 --- a/source/FreeTypeGX.cpp +++ b/source/FreeTypeGX.cpp @@ -20,7 +20,8 @@ * along with FreeTypeGX. If not, see . */ -#include "FreeTypeGX.h" +#include +#include "FreeTypeGX.h" #include "language/CH2Unicode.h" #include "language/GB2Unicode.h" #include "language/sjis2unicode.h" @@ -77,6 +78,7 @@ FreeTypeGX::FreeTypeGX(uint8_t textureFormat, uint8_t vertexIndex) { * Default destructor for the FreeTypeGX class. */ FreeTypeGX::~FreeTypeGX() { + FT_Done_FreeType(this->ftLibrary); this->unloadFont(); } @@ -205,11 +207,13 @@ void FreeTypeGX::setDefaultMode() { * @param pointSize The desired point size this wrapper's configured font face. * @param cacheAll Optional flag to specify if all font characters should be cached when the class object is created. If specified as false the characters only become cached the first time they are used. If not specified default value is false. */ -uint16_t FreeTypeGX::loadFont(uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll) { +#include +uint16_t FreeTypeGX::loadFont(char* fontPath, uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll) { this->unloadFont(); this->ftPointSize = pointSize; - - FT_New_Memory_Face(this->ftLibrary, (FT_Byte *)fontBuffer, bufferSize, 0, &this->ftFace); + struct stat st; + if( !( fontPath && (stat(fontPath, &st)==0) && (FT_New_Face(this->ftLibrary, fontPath, 0, &this->ftFace)==0) ) ) + FT_New_Memory_Face(this->ftLibrary, (FT_Byte *)fontBuffer, bufferSize, 0, &this->ftFace); if(this->ftPointSize > 0) FT_Set_Pixel_Sizes(this->ftFace, 0, this->ftPointSize); @@ -228,8 +232,8 @@ uint16_t FreeTypeGX::loadFont(uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt p * * \overload */ -uint16_t FreeTypeGX::loadFont(const uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll) { - return this->loadFont((uint8_t *)fontBuffer, bufferSize, pointSize, cacheAll); +uint16_t FreeTypeGX::loadFont(const char* fontPath, const uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll) { + return this->loadFont((char*)fontPath, (uint8_t *)fontBuffer, bufferSize, pointSize, cacheAll); } /** diff --git a/source/FreeTypeGX.h b/source/FreeTypeGX.h index 1b86bbd6..6c2fbee2 100644 --- a/source/FreeTypeGX.h +++ b/source/FreeTypeGX.h @@ -254,8 +254,8 @@ class FreeTypeGX { void setVertexFormat(uint8_t vertexIndex); void setCompatibilityMode(uint32_t compatibilityMode); - uint16_t loadFont(uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll = false); - uint16_t loadFont(const uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll = false); + uint16_t loadFont(char* fontPath, uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll = false); + uint16_t loadFont(const char* fontPath, const uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll = false); void changeSize(FT_UInt vPointSize, FT_UInt hPointSize=0); uint16_t drawText(int16_t x, int16_t y, wchar_t *text, GXColor color = ftgxWhite, uint16_t textStyling = FTGX_NULL); diff --git a/source/main.cpp b/source/main.cpp index 7861a4ee..4dfbc564 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -78,7 +78,8 @@ main(int argc, char *argv[]) if(!bootDevice_found) { //try USB - if((stat("USB:/apps/usbloader_gx/boot.dol", NULL) == 0) || (stat("USB:/apps/usbloader_gx/boot.elf", NULL) == 0)) + struct stat st; + if((stat("USB:/apps/usbloader_gx/boot.dol", &st) == 0) || (stat("USB:/apps/usbloader_gx/boot.elf", NULL) == 0)) strcpy(bootDevice, "USB:"); } @@ -119,13 +120,28 @@ main(int argc, char *argv[]) WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); - +printf("\n\n load Font\n"); fontSystem = new FreeTypeGX(); - fontSystem->loadFont(font_ttf, font_ttf_size, 0); + char *fontPath=0; + asprintf(&fontPath, "%sfont.ttf", CFG.theme_path); +printf(" from: %s\n", fontPath); +printf(" 5\n"); +sleep(1); +printf(" 4\n"); +sleep(1); +printf(" 3\n"); +sleep(1); +printf(" 2\n"); +sleep(1); +printf(" 1\n"); +sleep(1); +printf(" 0\n"); + fontSystem->loadFont(fontPath, font_ttf, font_ttf_size, 0); fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); + free(fontPath); fontClock = new FreeTypeGX(); - fontClock->loadFont(clock_ttf, clock_ttf_size, 0); + fontClock->loadFont(NULL, clock_ttf, clock_ttf_size, 0); fontClock->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); InitGUIThreads();