From 3c6bf6523be856399d97a72e9c9dfa51ad70a9aa Mon Sep 17 00:00:00 2001
From: dimok321 <15055714+dimok789@users.noreply.github.com>
Date: Sat, 17 Oct 2009 20:48:52 +0000
Subject: [PATCH] Optimization Changes Part 1:
*Lots of changes in the TextDrawing stuff and FreeTypeGX to speed up the drawing
*Mostly optimization work which is not completely done yet, but mainly it is.
*You might not want to update to this revision right away there still might be bugs which are needed to be fixed. This is a version for everyone to test and report bugs caused by the changes.
*Vanishing WiiMotePointer should be fixed for the Settings/GameSettings probably (though it might still occur i am not sure if i didn't forget anything, there is just too much to change :P.
---
gui.pnproj | 2 +-
source/FreeTypeGX.cpp | 987 +++++-----
source/FreeTypeGX.h | 155 +-
source/cheats/cheatmenu.cpp | 2 +-
source/homebrewboot/HomebrewBrowse.cpp | 26 +-
source/libwiigui/gui.h | 75 +-
source/libwiigui/gui_customoptionbrowser.cpp | 6 +-
source/libwiigui/gui_filebrowser.cpp | 4 +-
source/libwiigui/gui_gamebrowser.cpp | 4 +-
source/libwiigui/gui_gamecarousel.cpp | 2 +-
source/libwiigui/gui_searchbar.cpp | 4 +-
source/libwiigui/gui_text.cpp | 856 ++++----
source/main.cpp | 36 +-
source/main.h | 3 -
source/menu.cpp | 134 +-
source/prompts/DiscBrowser.cpp | 4 +-
source/prompts/ProgressWindow.cpp | 54 +-
source/prompts/PromptWindows.cpp | 79 +-
source/prompts/TitleBrowser.cpp | 4 +-
source/prompts/filebrowser.cpp | 8 +-
source/prompts/gameinfo.cpp | 68 +-
source/settings/Settings.cpp | 1828 +++++++++---------
source/settings/SettingsPrompts.cpp | 10 +-
source/usbloader/getentries.cpp | 9 +-
source/wad/wad.cpp | 4 +-
25 files changed, 2304 insertions(+), 2060 deletions(-)
diff --git a/gui.pnproj b/gui.pnproj
index 259f85ed..607c3d56 100644
--- a/gui.pnproj
+++ b/gui.pnproj
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/source/FreeTypeGX.cpp b/source/FreeTypeGX.cpp
index cbacc81e..55e0e8ff 100644
--- a/source/FreeTypeGX.cpp
+++ b/source/FreeTypeGX.cpp
@@ -20,64 +20,54 @@
* along with FreeTypeGX. If not, see .
*/
-#include
-#include
#include "FreeTypeGX.h"
-#include "settings/cfg.h"
-#include "main.h"
+FreeTypeGX *fontSystem[MAX_FONT_SIZE+1];
-/*! \struct ftgxCharData_
- *
- * Font face character glyph relevant data structure.
- */
-typedef struct ftgxCharData_ {
- int16_t renderOffsetX; /**< Texture X axis bearing offset. */
- uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */
- uint16_t glyphIndex; /**< Charachter glyph index in the font face. */
+static FT_Byte *customfontbuffer = NULL;
+static u32 cstfontfilesize = 0;
- uint16_t textureWidth; /**< Texture width in pixels/bytes. */
- uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */
+bool LoadCustomFont(const char *path)
+{
+ FILE *pfile = fopen(path, "rb");
- int16_t renderOffsetY; /**< Texture Y axis bearing offset. */
- int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
- int16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */
+ if(pfile)
+ {
+ fseek(pfile, 0, SEEK_END);
+ cstfontfilesize = ftell(pfile);
+ rewind(pfile);
- uint32_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */
-} ftgxCharData;
+ customfontbuffer = new FT_Byte[cstfontfilesize];
+ if(!customfontbuffer)
+ {
+ cstfontfilesize = 0;
+ fclose(pfile);
+ return false;
+ }
-/*! \struct ftgxDataOffset_
- *
- * Offset structure which hold both a maximum and minimum value.
- */
-typedef struct ftgxDataOffset_ {
- int16_t ascender; /**< Maximum data offset. */
- int16_t descender; /**< Minimum data offset. */
- int16_t max; /**< Maximum data offset. */
- int16_t min; /**< Minimum data offset. */
-} ftgxDataOffset;
+ fread(customfontbuffer, 1, cstfontfilesize, pfile);
+ fclose(pfile);
+ return true;
+ }
-/**
- * Default constructor for the FreeTypeGX class.
- *
- * @param textureFormat Optional format (GX_TF_*) of the texture as defined by the libogc gx.h header file. If not specified default value is GX_TF_RGBA8.
- * @param vertexIndex Optional vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file. If not specified default value is GX_VTXFMT1.
- */
-FreeTypeGX::FreeTypeGX(uint8_t textureFormat, uint8_t vertexIndex) : ftFace(NULL), ftFace_fromFile(NULL) {
- FT_Init_FreeType(&this->ftLibrary);
-
- this->textureFormat = textureFormat;
- this->setVertexFormat(vertexIndex);
- this->setCompatibilityMode(FTGX_COMPATIBILITY_NONE);
+ return false;
}
-/**
- * Default destructor for the FreeTypeGX class.
- */
-FreeTypeGX::~FreeTypeGX() {
- this->unloadFont();
- FT_Done_FreeType(this->ftLibrary);
+void ClearFontData()
+{
+ for(int i=0; i<50; i++)
+ {
+ if(fontSystem[i])
+ delete fontSystem[i];
+ fontSystem[i] = NULL;
+ }
+ if(customfontbuffer)
+ {
+ delete customfontbuffer;
+ customfontbuffer = NULL;
+ cstfontfilesize = 0;
+ }
}
/**
@@ -89,31 +79,85 @@ FreeTypeGX::~FreeTypeGX() {
* @param strChar Character string to be converted.
* @return Wide character representation of supplied character string.
*/
-wchar_t* FreeTypeGX::charToWideChar(char* strChar) {
- wchar_t *strWChar;
- try {strWChar = new wchar_t[strlen(strChar) + 1];}
- catch (...) { return 0; }
- // UTF-8
- int bt;
- bt = mbstowcs(strWChar, strChar, strlen(strChar));
- if (bt > 0) {
- strWChar[bt] = (wchar_t)'\0';
- return strWChar;
- }
- char *tempSrc = strChar;
- wchar_t *tempDest = strWChar;
- while ((*tempDest++ = *tempSrc++));
+wchar_t* charToWideChar(const char* strChar)
+{
+ wchar_t *strWChar;
+ strWChar = new wchar_t[strlen(strChar) + 1];
- return strWChar;
+ // UTF-8
+ int bt;
+ bt = mbstowcs(strWChar, strChar, strlen(strChar));
+ if(bt > 0) {
+ strWChar[bt] = (wchar_t)'\0';
+ return strWChar;
+ }
+
+ char *tempSrc = (char *)strChar;
+ wchar_t *tempDest = strWChar;
+ while((*tempDest++ = *tempSrc++));
+
+ return strWChar;
}
/**
+ * Default constructor for the FreeTypeGX class.
*
- * \overload
+ * @param textureFormat Optional format (GX_TF_*) of the texture as defined by the libogc gx.h header file. If not specified default value is GX_TF_RGBA8.
+ * @param vertexIndex Optional vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file. If not specified default value is GX_VTXFMT1.
*/
-wchar_t* FreeTypeGX::charToWideChar(const char* strChar) {
- return FreeTypeGX::charToWideChar((char*) strChar);
+FreeTypeGX::FreeTypeGX(FT_UInt pixelSize, uint8_t textureFormat, uint8_t vertexIndex)
+{
+ this->textureFormat = textureFormat;
+ this->setVertexFormat(vertexIndex);
+ this->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
+ this->ftPointSize = pixelSize;
+ this->ftKerningEnabled = FT_HAS_KERNING(ftFace);
+}
+
+/**
+ * Overload for WiiXplorer
+ */
+FreeTypeGX::FreeTypeGX(FT_UInt pixelSize, bool loadcustomfont, uint8_t* fontBuffer, FT_Long bufferSize, uint8_t textureFormat, uint8_t vertexIndex)
+{
+ this->InitFreeType(fontBuffer, bufferSize, loadcustomfont);
+ this->textureFormat = textureFormat;
+ this->setVertexFormat(vertexIndex);
+ this->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
+ this->ftPointSize = pixelSize;
+ this->ftKerningEnabled = FT_HAS_KERNING(ftFace);
+ this->ChangeFontSize(pixelSize);
+}
+
+/**
+ * Default destructor for the FreeTypeGX class.
+ */
+FreeTypeGX::~FreeTypeGX()
+{
+ FT_Done_FreeType(ftLibrary);
+ FT_Done_Face(ftFace);
+ this->unloadFont();
+}
+
+
+void FreeTypeGX::InitFreeType(uint8_t* fontBuffer, FT_Long bufferSize, bool loadcustomfont)
+{
+ FT_Init_FreeType(&ftLibrary);
+ if(customfontbuffer && cstfontfilesize > 0 && loadcustomfont)
+ FT_New_Memory_Face(ftLibrary, customfontbuffer, cstfontfilesize, 0,&ftFace);
+ else
+ FT_New_Memory_Face(ftLibrary, (FT_Byte *)fontBuffer, bufferSize, 0, &ftFace);
+ ftSlot = ftFace->glyph;
+}
+
+void FreeTypeGX::ChangeFontSize(FT_UInt pixelSize)
+{
+ FT_Set_Pixel_Sizes(ftFace, 0, pixelSize);
+}
+
+uint8_t FreeTypeGX::GetMaxCharWidth()
+{
+ return ftFace->size->metrics.max_advance >> 6;
}
/**
@@ -125,12 +169,12 @@ wchar_t* FreeTypeGX::charToWideChar(const char* strChar) {
*
* @param vertexIndex Vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file.
*/
-void FreeTypeGX::setVertexFormat(uint8_t vertexIndex) {
- this->vertexIndex = vertexIndex;
-
- GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_POS, GX_POS_XY, GX_S16, 0);
- GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
- GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
+void FreeTypeGX::setVertexFormat(uint8_t vertexIndex)
+{
+ this->vertexIndex = vertexIndex;
+ GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_POS, GX_POS_XY, GX_S16, 0);
+ GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
+ GX_SetVtxAttrFmt(this->vertexIndex, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
}
/**
@@ -143,8 +187,9 @@ void FreeTypeGX::setVertexFormat(uint8_t vertexIndex) {
*
* @param compatibilityMode Compatibility descritor (FTGX_COMPATIBILITY_*) as defined in FreeTypeGX.h
*/
-void FreeTypeGX::setCompatibilityMode(uint32_t compatibilityMode) {
- this->compatibilityMode = compatibilityMode;
+void FreeTypeGX::setCompatibilityMode(uint32_t compatibilityMode)
+{
+ this->compatibilityMode = compatibilityMode;
}
/**
@@ -153,138 +198,63 @@ void FreeTypeGX::setCompatibilityMode(uint32_t compatibilityMode) {
* This function calls the GX_SetTevOp and GX_SetVtxDesc functions with the compatibility parameters specified
* in setCompatibilityMode.
*/
-void FreeTypeGX::setDefaultMode() {
- if (this->compatibilityMode) {
- switch (this->compatibilityMode & 0x00FF) {
- case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE:
- GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
- break;
- case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_DECAL:
- GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL);
- break;
- case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_BLEND:
- GX_SetTevOp(GX_TEVSTAGE0, GX_BLEND);
- break;
- case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_REPLACE:
- GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
- break;
- case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR:
- GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
- break;
- default:
- break;
- }
+void FreeTypeGX::setDefaultMode()
+{
+ if(this->compatibilityMode)
+ {
+ switch(this->compatibilityMode & 0x00FF)
+ {
+ case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE:
+ GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
+ break;
+ case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_DECAL:
+ GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL);
+ break;
+ case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_BLEND:
+ GX_SetTevOp(GX_TEVSTAGE0, GX_BLEND);
+ break;
+ case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_REPLACE:
+ GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
+ break;
+ case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR:
+ GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
+ break;
+ default:
+ break;
+ }
- switch (this->compatibilityMode & 0xFF00) {
- case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE:
- GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
- break;
- case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_DIRECT:
- GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
- break;
- case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX8:
- GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);
- break;
- case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX16:
- GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);
- break;
- default:
- break;
- }
- }
+ switch(this->compatibilityMode & 0xFF00)
+ {
+ case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE:
+ GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
+ break;
+ case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_DIRECT:
+ GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
+ break;
+ case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX8:
+ GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);
+ break;
+ case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX16:
+ GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);
+ break;
+ default:
+ break;
+ }
+ }
}
-/**
- * Loads and processes a specified true type font buffer to a specific point size.
- *
- * This routine takes a precompiled true type font buffer and loads the necessary processed data into memory. This routine should be called before drawText will succeed.
- *
- * @param fontPath filename with path to load font from file in memory.
- * @param fontBuffer A pointer in memory to a precompiled true type font buffer.
- * @param bufferSize Size of the true type font buffer in bytes.
- * @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(char* fontPath, uint8_t* fontBuffer, FT_Long bufferSize, FT_UInt pointSize, bool cacheAll) {
- this->unloadFont();
- this->ftPointSize = pointSize;
- struct stat st;
-
- if (fontPath && (stat(fontPath, &st)==0)) {
- FILE *fontfile = fopen(fontPath, "rb");
- if (fontfile) {
- FT_Long ftFace_fromFile_Size;
-
- fseek(fontfile, 0, SEEK_END);
- ftFace_fromFile_Size = ftell(fontfile);
- fseek(fontfile, 0, SEEK_SET);
- ftFace_fromFile = (uint8_t*)malloc(ftFace_fromFile_Size);
- if (ftFace_fromFile != NULL) {
- fread(ftFace_fromFile, 1, ftFace_fromFile_Size, fontfile);
- FT_New_Memory_Face(this->ftLibrary, ftFace_fromFile, ftFace_fromFile_Size, 0, &this->ftFace);
- }
- fclose(fontfile);
- }
- }
- if (ftFace_fromFile == NULL)
- 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);
-
- this->ftSlot = this->ftFace->glyph;
- this->ftKerningEnabled = FT_HAS_KERNING(this->ftFace);
-
- if (cacheAll) {
- return this->cacheGlyphDataComplete();
- }
-
- return 0;
-}
-
-/**
- *
- * \overload
- */
-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);
-}
-
-void FreeTypeGX::unloadFont() {
- clearGlyphData();
-
- if (this->ftFace) {
- FT_Done_Face(this->ftFace);
- this->ftFace = NULL;
- }
- if (this->ftFace_fromFile) {
- free(this->ftFace_fromFile);
- this->ftFace_fromFile = NULL;
- }
-}
/**
* Clears all loaded font glyph data.
*
* This routine clears all members of the font map structure and frees all allocated memory back to the system.
*/
-void FreeTypeGX::clearGlyphData() {
- if (this->fontData.size() == 0)
- return;
-
- GX_DrawDone();
- GX_Flush();
-
- for ( std::map::iterator i = this->fontData.begin(); i != this->fontData.end(); i++) {
- free(i->second.glyphDataTexture);
- }
-
- this->fontData.clear();
-}
-
-void FreeTypeGX::changeSize(FT_UInt vPointSize, FT_UInt hPointSize/*=0*/) {
- this->clearGlyphData();
- this->ftPointSize = vPointSize;
- FT_Set_Pixel_Sizes(this->ftFace, hPointSize, this->ftPointSize);
+void FreeTypeGX::unloadFont()
+{
+ if(this->fontData.size() == 0)
+ return;
+ for(std::map::iterator i = this->fontData.begin(); i != this->fontData.end(); i++)
+ free(i->second.glyphDataTexture);
+ this->fontData.clear();
}
/**
@@ -296,26 +266,27 @@ void FreeTypeGX::changeSize(FT_UInt vPointSize, FT_UInt hPointSize/*=0*/) {
* @param textureFormat The texture format to which the data is to be converted.
* @return The correctly adjusted texture width.
*/
-uint16_t FreeTypeGX::adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat) {
- uint16_t alignment;
+uint16_t FreeTypeGX::adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat)
+{
+ uint16_t alignment;
- switch (textureFormat) {
- case GX_TF_I4: /* 8x8 Tiles - 4-bit Intensity */
- case GX_TF_I8: /* 8x4 Tiles - 8-bit Intensity */
- case GX_TF_IA4: /* 8x4 Tiles - 4-bit Intensity, , 4-bit Alpha */
- alignment = 8;
- break;
-
- case GX_TF_IA8: /* 4x4 Tiles - 8-bit Intensity, 8-bit Alpha */
- case GX_TF_RGB565: /* 4x4 Tiles - RGB565 Format */
- case GX_TF_RGB5A3: /* 4x4 Tiles - RGB5A3 Format */
- case GX_TF_RGBA8: /* 4x4 Tiles - RGBA8 Dual Cache Line Format */
- default:
- alignment = 4;
- break;
- }
- return textureWidth % alignment == 0 ? textureWidth : alignment + textureWidth - (textureWidth % alignment);
+ switch(textureFormat)
+ {
+ case GX_TF_I4: /* 8x8 Tiles - 4-bit Intensity */
+ case GX_TF_I8: /* 8x4 Tiles - 8-bit Intensity */
+ case GX_TF_IA4: /* 8x4 Tiles - 4-bit Intensity, , 4-bit Alpha */
+ alignment = 8;
+ break;
+ case GX_TF_IA8: /* 4x4 Tiles - 8-bit Intensity, 8-bit Alpha */
+ case GX_TF_RGB565: /* 4x4 Tiles - RGB565 Format */
+ case GX_TF_RGB5A3: /* 4x4 Tiles - RGB5A3 Format */
+ case GX_TF_RGBA8: /* 4x4 Tiles - RGBA8 Dual Cache Line Format */
+ default:
+ alignment = 4;
+ break;
+ }
+ return textureWidth % alignment == 0 ? textureWidth : alignment + textureWidth - (textureWidth % alignment);
}
/**
@@ -327,26 +298,27 @@ uint16_t FreeTypeGX::adjustTextureWidth(uint16_t textureWidth, uint8_t textureFo
* @param textureFormat The texture format to which the data is to be converted.
* @return The correctly adjusted texture height.
*/
-uint16_t FreeTypeGX::adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat) {
- uint16_t alignment;
+uint16_t FreeTypeGX::adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat)
+{
+ uint16_t alignment;
- switch (textureFormat) {
- case GX_TF_I4: /* 8x8 Tiles - 4-bit Intensity */
- alignment = 8;
- break;
-
- case GX_TF_I8: /* 8x4 Tiles - 8-bit Intensity */
- case GX_TF_IA4: /* 8x4 Tiles - 4-bit Intensity, , 4-bit Alpha */
- case GX_TF_IA8: /* 4x4 Tiles - 8-bit Intensity, 8-bit Alpha */
- case GX_TF_RGB565: /* 4x4 Tiles - RGB565 Format */
- case GX_TF_RGB5A3: /* 4x4 Tiles - RGB5A3 Format */
- case GX_TF_RGBA8: /* 4x4 Tiles - RGBA8 Dual Cache Line Format */
- default:
- alignment = 4;
- break;
- }
- return textureHeight % alignment == 0 ? textureHeight : alignment + textureHeight - (textureHeight % alignment);
+ switch(textureFormat)
+ {
+ case GX_TF_I4: /* 8x8 Tiles - 4-bit Intensity */
+ alignment = 8;
+ break;
+ case GX_TF_I8: /* 8x4 Tiles - 8-bit Intensity */
+ case GX_TF_IA4: /* 8x4 Tiles - 4-bit Intensity, , 4-bit Alpha */
+ case GX_TF_IA8: /* 4x4 Tiles - 8-bit Intensity, 8-bit Alpha */
+ case GX_TF_RGB565: /* 4x4 Tiles - RGB565 Format */
+ case GX_TF_RGB5A3: /* 4x4 Tiles - RGB5A3 Format */
+ case GX_TF_RGBA8: /* 4x4 Tiles - RGBA8 Dual Cache Line Format */
+ default:
+ alignment = 4;
+ break;
+ }
+ return textureHeight % alignment == 0 ? textureHeight : alignment + textureHeight - (textureHeight % alignment);
}
/**
@@ -358,38 +330,38 @@ uint16_t FreeTypeGX::adjustTextureHeight(uint16_t textureHeight, uint8_t texture
* @param charCode The requested glyph's character code.
* @return A pointer to the allocated font structure.
*/
-ftgxCharData *FreeTypeGX::cacheGlyphData(wchar_t charCode) {
- FT_UInt gIndex;
- uint16_t textureWidth = 0, textureHeight = 0;
+ftgxCharData *FreeTypeGX::cacheGlyphData(wchar_t charCode)
+{
+ FT_UInt gIndex;
+ uint16_t textureWidth = 0, textureHeight = 0;
- gIndex = FT_Get_Char_Index( this->ftFace, charCode );
- if (!FT_Load_Glyph(this->ftFace, gIndex, FT_LOAD_DEFAULT )) {
- FT_Render_Glyph( this->ftSlot, FT_RENDER_MODE_NORMAL );
+ gIndex = FT_Get_Char_Index( ftFace, charCode );
+ if (!FT_Load_Glyph(ftFace, gIndex, FT_LOAD_DEFAULT )) {
+ FT_Render_Glyph( ftSlot, FT_RENDER_MODE_NORMAL );
- if (this->ftSlot->format == FT_GLYPH_FORMAT_BITMAP) {
- FT_Bitmap *glyphBitmap = &this->ftSlot->bitmap;
+ if(ftSlot->format == FT_GLYPH_FORMAT_BITMAP) {
+ FT_Bitmap *glyphBitmap = &ftSlot->bitmap;
- textureWidth = adjustTextureWidth(glyphBitmap->width, this->textureFormat);
- textureHeight = adjustTextureHeight(glyphBitmap->rows, this->textureFormat);
+ textureWidth = adjustTextureWidth(glyphBitmap->width, this->textureFormat);
+ textureHeight = adjustTextureHeight(glyphBitmap->rows, this->textureFormat);
- this->fontData[charCode] = (ftgxCharData) {
- this->ftSlot->bitmap_left,
- this->ftSlot->advance.x >> 6,
- gIndex,
- textureWidth,
- textureHeight,
- this->ftSlot->bitmap_top,
- this->ftSlot->bitmap_top,
- glyphBitmap->rows - this->ftSlot->bitmap_top,
- NULL
- };
- this->loadGlyphData(glyphBitmap, &this->fontData[charCode]);
+ this->fontData[charCode] = (ftgxCharData){
+ ftSlot->bitmap_left,
+ ftSlot->advance.x >> 6,
+ gIndex,
+ textureWidth,
+ textureHeight,
+ ftSlot->bitmap_top,
+ ftSlot->bitmap_top,
+ glyphBitmap->rows - ftSlot->bitmap_top,
+ NULL
+ };
+ this->loadGlyphData(glyphBitmap, &this->fontData[charCode]);
- return &this->fontData[charCode];
- }
- }
-
- return NULL;
+ return &this->fontData[charCode];
+ }
+ }
+ return NULL;
}
/**
@@ -398,20 +370,18 @@ ftgxCharData *FreeTypeGX::cacheGlyphData(wchar_t charCode) {
* This routine locates each character in the configured font face and renders the glyph's bitmap.
* Each bitmap and relevant information is loaded into its own quickly addressible structure within an instance-specific map.
*/
-uint16_t FreeTypeGX::cacheGlyphDataComplete() {
- uint16_t i = 0;
- FT_UInt gIndex;
- FT_ULong charCode = FT_Get_First_Char( this->ftFace, &gIndex );
- while ( gIndex != 0 ) {
-
- if (this->cacheGlyphData(charCode) != NULL) {
- i++;
- }
-
- charCode = FT_Get_Next_Char( this->ftFace, charCode, &gIndex );
- }
-
- return i;
+uint16_t FreeTypeGX::cacheGlyphDataComplete()
+{
+ uint16_t i = 0;
+ FT_UInt gIndex;
+ FT_ULong charCode = FT_Get_First_Char( ftFace, &gIndex );
+ while ( gIndex != 0 )
+ {
+ if(this->cacheGlyphData(charCode) != NULL)
+ i++;
+ charCode = FT_Get_Next_Char( ftFace, charCode, &gIndex );
+ }
+ return i;
}
/**
@@ -423,44 +393,46 @@ uint16_t FreeTypeGX::cacheGlyphDataComplete() {
* @param bmp A pointer to the most recently rendered glyph's bitmap.
* @param charData A pointer to an allocated ftgxCharData structure whose data represent that of the last rendered glyph.
*/
-void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) {
+void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
+{
+ uint32_t *glyphData = (uint32_t *)memalign(32, charData->textureWidth * charData->textureHeight * 4);
+ memset(glyphData, 0x00, charData->textureWidth * charData->textureHeight * 4);
- uint32_t *glyphData = (uint32_t *)memalign(32, charData->textureWidth * charData->textureHeight * 4);
- memset(glyphData, 0x00, charData->textureWidth * charData->textureHeight * 4);
+ for (uint16_t imagePosY = 0; imagePosY < bmp->rows; imagePosY++)
+ {
+ for (uint16_t imagePosX = 0; imagePosX < bmp->width; imagePosX++)
+ {
+ uint32_t pixel = (uint32_t) bmp->buffer[imagePosY * bmp->width + imagePosX];
+ glyphData[imagePosY * charData->textureWidth + imagePosX] = 0x00000000 | (pixel << 24) | (pixel << 16) | (pixel << 8) | pixel;
+ }
+ }
- for (uint16_t imagePosY = 0; imagePosY < bmp->rows; imagePosY++) {
- for (uint16_t imagePosX = 0; imagePosX < bmp->width; imagePosX++) {
- uint32_t pixel = (uint32_t) bmp->buffer[imagePosY * bmp->width + imagePosX];
- glyphData[imagePosY * charData->textureWidth + imagePosX] = 0x00000000 | (pixel << 24) | (pixel << 16) | (pixel << 8) | pixel;
- }
- }
-
- switch (this->textureFormat) {
- case GX_TF_I4:
- charData->glyphDataTexture = Metaphrasis::convertBufferToI4(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_I8:
- charData->glyphDataTexture = Metaphrasis::convertBufferToI8(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_IA4:
- charData->glyphDataTexture = Metaphrasis::convertBufferToIA4(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_IA8:
- charData->glyphDataTexture = Metaphrasis::convertBufferToIA8(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_RGB565:
- charData->glyphDataTexture = Metaphrasis::convertBufferToRGB565(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_RGB5A3:
- charData->glyphDataTexture = Metaphrasis::convertBufferToRGB5A3(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_RGBA8:
- default:
- charData->glyphDataTexture = Metaphrasis::convertBufferToRGBA8(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- }
-
- free(glyphData);
+ switch(this->textureFormat)
+ {
+ case GX_TF_I4:
+ charData->glyphDataTexture = Metaphrasis::convertBufferToI4(glyphData, charData->textureWidth, charData->textureHeight);
+ break;
+ case GX_TF_I8:
+ charData->glyphDataTexture = Metaphrasis::convertBufferToI8(glyphData, charData->textureWidth, charData->textureHeight);
+ break;
+ case GX_TF_IA4:
+ charData->glyphDataTexture = Metaphrasis::convertBufferToIA4(glyphData, charData->textureWidth, charData->textureHeight);
+ break;
+ case GX_TF_IA8:
+ charData->glyphDataTexture = Metaphrasis::convertBufferToIA8(glyphData, charData->textureWidth, charData->textureHeight);
+ break;
+ case GX_TF_RGB565:
+ charData->glyphDataTexture = Metaphrasis::convertBufferToRGB565(glyphData, charData->textureWidth, charData->textureHeight);
+ break;
+ case GX_TF_RGB5A3:
+ charData->glyphDataTexture = Metaphrasis::convertBufferToRGB5A3(glyphData, charData->textureWidth, charData->textureHeight);
+ break;
+ case GX_TF_RGBA8:
+ default:
+ charData->glyphDataTexture = Metaphrasis::convertBufferToRGBA8(glyphData, charData->textureWidth, charData->textureHeight);
+ break;
+ }
+ free(glyphData);
}
/**
@@ -471,21 +443,15 @@ void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) {
* @param width Current pixel width of the string.
* @param format Positional format of the string.
*/
-int16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format) {
-
- switch (format & FTGX_JUSTIFY_MASK) {
- case FTGX_JUSTIFY_LEFT:
- return 0;
-
- default:
- case FTGX_JUSTIFY_CENTER:
- return -(width >> 1);
-
- case FTGX_JUSTIFY_RIGHT:
- return -width;
- }
-
- return 0;
+int16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format)
+{
+ if (format & FTGX_JUSTIFY_LEFT)
+ return 0;
+ else if (format & FTGX_JUSTIFY_CENTER)
+ return -(width >> 1);
+ else if (format & FTGX_JUSTIFY_RIGHT)
+ return -width;
+ return 0;
}
/**
@@ -496,32 +462,33 @@ int16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format) {
* @param offset Current pixel offset data of the string.
* @param format Positional format of the string.
*/
-int16_t FreeTypeGX::getStyleOffsetHeight(ftgxDataOffset *offset, uint16_t format) {
- switch (format & FTGX_ALIGN_MASK) {
- case FTGX_ALIGN_TOP:
- return offset->ascender;
+int16_t FreeTypeGX::getStyleOffsetHeight(ftgxDataOffset *offset, uint16_t format)
+{
+ switch(format & FTGX_ALIGN_MASK)
+ {
+ case FTGX_ALIGN_TOP:
+ return offset->ascender;
- default:
- case FTGX_ALIGN_MIDDLE:
- return (offset->ascender + offset->descender + 1) >> 1;
+ default:
+ case FTGX_ALIGN_MIDDLE:
+ return (offset->ascender + offset->descender + 1) >> 1;
- case FTGX_ALIGN_BOTTOM:
- return offset->descender;
+ case FTGX_ALIGN_BOTTOM:
+ return offset->descender;
- case FTGX_ALIGN_BASELINE:
- return 0;
+ case FTGX_ALIGN_BASELINE:
+ return 0;
- case FTGX_ALIGN_GLYPH_TOP:
- return offset->max;
+ case FTGX_ALIGN_GLYPH_TOP:
+ return offset->max;
- case FTGX_ALIGN_GLYPH_MIDDLE:
- return (offset->max + offset->min + 1) >> 1;
+ case FTGX_ALIGN_GLYPH_MIDDLE:
+ return (offset->max + offset->min + 1) >> 1;
- case FTGX_ALIGN_GLYPH_BOTTOM:
- return offset->min;
- }
-
- return 0;
+ case FTGX_ALIGN_GLYPH_BOTTOM:
+ return offset->min;
+ }
+ return 0;
}
/**
@@ -537,100 +504,82 @@ int16_t FreeTypeGX::getStyleOffsetHeight(ftgxDataOffset *offset, uint16_t format
* @param textStyle Flags which specify any styling which should be applied to the rendered string.
* @return The number of characters printed.
*/
-uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t *text, GXColor color, uint16_t textStyle) {
- uint16_t strLength = wcslen(text);
- uint16_t x_pos = x, printed = 0;
- uint16_t x_offset = 0, y_offset = 0;
- GXTexObj glyphTexture;
- FT_Vector pairDelta;
- ftgxDataOffset offset;
+uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t *text, GXColor color, uint16_t textStyle)
+{
+ if(!text)
+ return 0;
- if (textStyle & FTGX_JUSTIFY_MASK) {
- x_offset = this->getStyleOffsetWidth(this->getWidth(text), textStyle);
- }
- if (textStyle & FTGX_ALIGN_MASK) {
- y_offset = this->getStyleOffsetHeight(this->getOffset(text, &offset), textStyle);
- }
+ uint16_t strLength = wcslen(text);
+ uint16_t x_pos = x, printed = 0;
+ uint16_t x_offset = 0, y_offset = 0;
+ GXTexObj glyphTexture;
+ FT_Vector pairDelta;
+ ftgxDataOffset offset;
- for (uint16_t i = 0; i < strLength; i++) {
+ if(textStyle & FTGX_JUSTIFY_MASK)
+ {
+ x_offset = this->getStyleOffsetWidth(this->getWidth(text), textStyle);
+ }
+ if(textStyle & FTGX_ALIGN_MASK)
+ {
+ this->getOffset(text, &offset);
+ y_offset = this->getStyleOffsetHeight(&offset, textStyle);
+ }
- ftgxCharData* glyphData = NULL;
- if ( this->fontData.find(text[i]) != this->fontData.end() ) {
- glyphData = &this->fontData[text[i]];
- } else {
- glyphData = this->cacheGlyphData(text[i]);
- }
+ for (uint16_t i = 0; i < strLength; i++)
+ {
+ ftgxCharData* glyphData = NULL;
+ if( this->fontData.find(text[i]) != this->fontData.end() )
+ {
+ glyphData = &this->fontData[text[i]];
+ }
+ else
+ {
+ glyphData = this->cacheGlyphData(text[i]);
+ }
- if (glyphData != NULL) {
+ if(glyphData != NULL)
+ {
+ if(this->ftKerningEnabled && i)
+ {
+ FT_Get_Kerning( ftFace, this->fontData[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta );
+ x_pos += pairDelta.x >> 6;
+ }
- if (this->ftKerningEnabled && i) {
- FT_Get_Kerning( this->ftFace, this->fontData[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta );
- x_pos += pairDelta.x >> 6;
- }
+ GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, this->textureFormat, GX_CLAMP, GX_CLAMP, GX_FALSE);
+ this->copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos + glyphData->renderOffsetX + x_offset, y - glyphData->renderOffsetY + y_offset, color);
- GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, this->textureFormat, GX_CLAMP, GX_CLAMP, GX_FALSE);
- this->copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos + glyphData->renderOffsetX + x_offset, y - glyphData->renderOffsetY + y_offset, color);
+ x_pos += glyphData->glyphAdvanceX;
+ printed++;
+ }
+ }
- x_pos += glyphData->glyphAdvanceX;
- printed++;
- }
- }
+ if(textStyle & FTGX_STYLE_MASK)
+ {
+ this->getOffset(text, &offset);
+ this->drawTextFeature(x + x_offset, y + y_offset, this->getWidth(text), &offset, textStyle, color);
+ }
- if (textStyle & FTGX_STYLE_MASK) {
- this->drawTextFeature(x + x_offset, y + y_offset, this->getWidth(text), this->getOffset(text, &offset), textStyle, color);
- }
-
- return printed;
+ return printed;
}
/**
* \overload
*/
-uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t const *text, GXColor color, uint16_t textStyle) {
- return this->drawText(x, y, (wchar_t *)text, color, textStyle);
+uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t const *text, GXColor color, uint16_t textStyle)
+{
+ return this->drawText(x, y, (wchar_t *)text, color, textStyle);
}
-void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataOffset *offsetData, uint16_t format, GXColor color) {
- uint16_t featureHeight = this->ftPointSize >> 4 > 0 ? this->ftPointSize >> 4 : 1;
+void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataOffset *offsetData, uint16_t format, GXColor color)
+{
+ uint16_t featureHeight = this->ftPointSize >> 4 > 0 ? this->ftPointSize >> 4 : 1;
- if (format & FTGX_STYLE_UNDERLINE ) {
- switch (format & FTGX_ALIGN_MASK) {
- /*
- case FTGX_ALIGN_TOP:
- this->copyFeatureToFramebuffer(width, featureHeight, x, y + offsetData->max + 1, color);
- break;
- case FTGX_ALIGN_MIDDLE:
- this->copyFeatureToFramebuffer(width, featureHeight, x, y + ((offsetData->max - offsetData->min + 1) >> 1), color);
- break;
- case FTGX_ALIGN_BOTTOM:
- this->copyFeatureToFramebuffer(width, featureHeight, x, y - offsetData->min, color);
- break;
- */
- default:
- this->copyFeatureToFramebuffer(width, featureHeight, x, y + 1, color);
- break;
- }
- }
+ if (format & FTGX_STYLE_UNDERLINE)
+ this->copyFeatureToFramebuffer(width, featureHeight, x, y + 1, color);
- if (format & FTGX_STYLE_STRIKE ) {
- switch (format & FTGX_ALIGN_MASK) {
- /*
- case FTGX_ALIGN_TOP:
- this->copyFeatureToFramebuffer(width, featureHeight, x, y + ((offsetData->max - offsetData->min + 1) >> 1), color);
- break;
- case FTGX_ALIGN_MIDDLE:
- this->copyFeatureToFramebuffer(width, featureHeight, x, y, color);
- break;
- case FTGX_ALIGN_BOTTOM:
- this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData->max + offsetData->min) >> 1), color);
- break;
- */
- default:
-// this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData->max - offsetData->min) >> 1), color);
- this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData->max) >> 1), color);
- break;
- }
- }
+ if (format & FTGX_STYLE_STRIKE)
+ this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData->max) >> 1), color);
}
/**
@@ -642,39 +591,48 @@ void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, uint16_t width, ftgxDataO
* @param text NULL terminated string to calculate.
* @return The width of the text string in pixels.
*/
-uint16_t FreeTypeGX::getWidth(wchar_t *text) {
- uint16_t strLength = wcslen(text);
- uint16_t strWidth = 0;
- FT_Vector pairDelta;
+uint16_t FreeTypeGX::getWidth(wchar_t *text)
+{
+ if(!text)
+ return 0;
- for (uint16_t i = 0; i < strLength; i++) {
+ uint16_t strLength = wcslen(text);
+ uint16_t strWidth = 0;
+ FT_Vector pairDelta;
- ftgxCharData* glyphData = NULL;
- if ( this->fontData.find(text[i]) != this->fontData.end() ) {
- glyphData = &this->fontData[text[i]];
- } else {
- glyphData = this->cacheGlyphData(text[i]);
- }
+ for (uint16_t i = 0; i < strLength; i++)
+ {
- if (glyphData != NULL) {
- if (this->ftKerningEnabled && (i > 0)) {
- FT_Get_Kerning( this->ftFace, this->fontData[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta );
- strWidth += pairDelta.x >> 6;
- }
+ ftgxCharData* glyphData = NULL;
+ if( this->fontData.find(text[i]) != this->fontData.end() )
+ {
+ glyphData = &this->fontData[text[i]];
+ }
+ else
+ {
+ glyphData = this->cacheGlyphData(text[i]);
+ }
- strWidth += glyphData->glyphAdvanceX;
- }
- }
-
- return strWidth;
+ if(glyphData != NULL)
+ {
+ if(this->ftKerningEnabled && (i > 0))
+ {
+ FT_Get_Kerning( ftFace, this->fontData[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta );
+ strWidth += pairDelta.x >> 6;
+ }
+ strWidth += glyphData->glyphAdvanceX;
+ }
+ }
+ return strWidth;
}
/**
*
* \overload
*/
-uint16_t FreeTypeGX::getWidth(wchar_t const *text) {
- return this->getWidth((wchar_t *)text);
+uint16_t FreeTypeGX::getWidth(wchar_t const *text)
+{
+ return this->getWidth((wchar_t *)text);
}
/**
@@ -686,19 +644,20 @@ uint16_t FreeTypeGX::getWidth(wchar_t const *text) {
* @param text NULL terminated string to calculate.
* @return The height of the text string in pixels.
*/
-uint16_t FreeTypeGX::getHeight(wchar_t *text) {
- ftgxDataOffset offset;
- this->getOffset(text, &offset);
-
- return offset.max - offset.min;
+uint16_t FreeTypeGX::getHeight(wchar_t *text)
+{
+ ftgxDataOffset offset;
+ this->getOffset(text, &offset);
+ return offset.max - offset.min;
}
/**
*
* \overload
*/
-uint16_t FreeTypeGX::getHeight(wchar_t const *text) {
- return this->getHeight((wchar_t *)text);
+uint16_t FreeTypeGX::getHeight(wchar_t const *text)
+{
+ return this->getHeight((wchar_t *)text);
}
/**
@@ -711,37 +670,43 @@ uint16_t FreeTypeGX::getHeight(wchar_t const *text) {
* @param offset returns the max and min values above and below the font origin line
*
*/
-ftgxDataOffset* FreeTypeGX::getOffset(wchar_t *text, ftgxDataOffset* offset) {
- uint16_t strLength = wcslen(text);
- int16_t strMax = 0, strMin = 9999;
+void FreeTypeGX::getOffset(wchar_t *text, ftgxDataOffset* offset)
+{
+ uint16_t strLength = wcslen(text);
+ int16_t strMax = 0, strMin = 9999;
- for (uint16_t i = 0; i < strLength; i++) {
+ for (uint16_t i = 0; i < strLength; i++)
+ {
- ftgxCharData* glyphData = NULL;
- if ( this->fontData.find(text[i]) != this->fontData.end() ) {
- glyphData = &this->fontData[text[i]];
- } else {
- glyphData = this->cacheGlyphData(text[i]);
- }
+ ftgxCharData* glyphData = NULL;
+ if( this->fontData.find(text[i]) != this->fontData.end() )
+ {
+ glyphData = &this->fontData[text[i]];
+ }
+ else
+ {
+ glyphData = this->cacheGlyphData(text[i]);
+ }
- if (glyphData != NULL) {
- strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
- strMin = glyphData->renderOffsetMin < strMin ? glyphData->renderOffsetMin : strMin;
- }
- }
- offset->ascender = this->ftFace->size->metrics.ascender>>6;
- offset->descender = this->ftFace->size->metrics.descender>>6;
- offset->max = strMax;
- offset->min = strMin;
- return offset;
+ if(glyphData != NULL)
+ {
+ strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
+ strMin = glyphData->renderOffsetMin < strMin ? glyphData->renderOffsetMin : strMin;
+ }
+ }
+ offset->ascender = ftFace->size->metrics.ascender>>6;
+ offset->descender = ftFace->size->metrics.descender>>6;
+ offset->max = strMax;
+ offset->min = strMin;
}
/**
*
* \overload
*/
-ftgxDataOffset* FreeTypeGX::getOffset(wchar_t const *text, ftgxDataOffset* offset) {
- return this->getOffset(text, offset);
+void FreeTypeGX::getOffset(wchar_t const *text, ftgxDataOffset* offset)
+{
+ this->getOffset(text, offset);
}
/**
@@ -756,33 +721,34 @@ ftgxDataOffset* FreeTypeGX::getOffset(wchar_t const *text, ftgxDataOffset* offse
* @param screenY The screen Y coordinate at which to output the rendered texture.
* @param color Color to apply to the texture.
*/
-void FreeTypeGX::copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY, GXColor color) {
+void FreeTypeGX::copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY, GXColor color)
+{
+ GX_LoadTexObj(texObj, GX_TEXMAP0);
+ GX_InvalidateTexAll();
- GX_LoadTexObj(texObj, GX_TEXMAP0);
- GX_InvalidateTexAll();
+ GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
+ GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
- GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
- GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
+ GX_Begin(GX_QUADS, this->vertexIndex, 4);
+ GX_Position2s16(screenX, screenY);
+ GX_Color4u8(color.r, color.g, color.b, color.a);
+ GX_TexCoord2f32(0.0f, 0.0f);
- GX_Begin(GX_QUADS, this->vertexIndex, 4);
- GX_Position2s16(screenX, screenY);
- GX_Color4u8(color.r, color.g, color.b, color.a);
- GX_TexCoord2f32(0.0f, 0.0f);
+ GX_Position2s16(texWidth + screenX, screenY);
+ GX_Color4u8(color.r, color.g, color.b, color.a);
+ GX_TexCoord2f32(1.0f, 0.0f);
- GX_Position2s16(texWidth + screenX, screenY);
- GX_Color4u8(color.r, color.g, color.b, color.a);
- GX_TexCoord2f32(1.0f, 0.0f);
+ GX_Position2s16(texWidth + screenX, texHeight + screenY);
+ GX_Color4u8(color.r, color.g, color.b, color.a);
+ GX_TexCoord2f32(1.0f, 1.0f);
- GX_Position2s16(texWidth + screenX, texHeight + screenY);
- GX_Color4u8(color.r, color.g, color.b, color.a);
- GX_TexCoord2f32(1.0f, 1.0f);
+ GX_Position2s16(screenX, texHeight + screenY);
+ GX_Color4u8(color.r, color.g, color.b, color.a);
+ GX_TexCoord2f32(0.0f, 1.0f);
+ GX_End();
+ GX_DrawDone();
- GX_Position2s16(screenX, texHeight + screenY);
- GX_Color4u8(color.r, color.g, color.b, color.a);
- GX_TexCoord2f32(0.0f, 1.0f);
- GX_End();
-
- this->setDefaultMode();
+ this->setDefaultMode();
}
/**
@@ -796,24 +762,25 @@ void FreeTypeGX::copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 te
* @param screenY The screen Y coordinate at which to output the quad.
* @param color Color to apply to the texture.
*/
-void FreeTypeGX::copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, GXColor color) {
+void FreeTypeGX::copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, GXColor color)
+{
+ GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
+ GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
- GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
- GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
+ GX_Begin(GX_QUADS, this->vertexIndex, 4);
+ GX_Position2s16(screenX, screenY);
+ GX_Color4u8(color.r, color.g, color.b, color.a);
- GX_Begin(GX_QUADS, this->vertexIndex, 4);
- GX_Position2s16(screenX, screenY);
- GX_Color4u8(color.r, color.g, color.b, color.a);
+ GX_Position2s16(featureWidth + screenX, screenY);
+ GX_Color4u8(color.r, color.g, color.b, color.a);
- GX_Position2s16(featureWidth + screenX, screenY);
- GX_Color4u8(color.r, color.g, color.b, color.a);
+ GX_Position2s16(featureWidth + screenX, featureHeight + screenY);
+ GX_Color4u8(color.r, color.g, color.b, color.a);
- GX_Position2s16(featureWidth + screenX, featureHeight + screenY);
- GX_Color4u8(color.r, color.g, color.b, color.a);
+ GX_Position2s16(screenX, featureHeight + screenY);
+ GX_Color4u8(color.r, color.g, color.b, color.a);
+ GX_End();
+ GX_DrawDone();
- GX_Position2s16(screenX, featureHeight + screenY);
- GX_Color4u8(color.r, color.g, color.b, color.a);
- GX_End();
-
- this->setDefaultMode();
+ this->setDefaultMode();
}
diff --git a/source/FreeTypeGX.h b/source/FreeTypeGX.h
index 5d235837..49e820ad 100644
--- a/source/FreeTypeGX.h
+++ b/source/FreeTypeGX.h
@@ -156,37 +156,68 @@
#include FT_FREETYPE_H
#include FT_BITMAP_H
#include "Metaphrasis.h"
+#include "filelist.h"
#include
#include
+#include
#include