2010-09-17 17:15:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2010
|
|
|
|
* by Dimok
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* for WiiXplorer 2010
|
|
|
|
***************************************************************************/
|
|
|
|
#include "FreeTypeGX.h"
|
|
|
|
#include "filelist.h"
|
|
|
|
|
|
|
|
FreeTypeGX * fontSystem = NULL;
|
2010-09-24 02:48:03 +02:00
|
|
|
static FT_Byte * MainFont = (FT_Byte *) font_ttf;
|
2010-09-17 17:15:21 +02:00
|
|
|
static u32 MainFontSize = font_ttf_size;
|
|
|
|
|
|
|
|
void ClearFontData()
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (fontSystem) delete fontSystem;
|
2010-09-17 17:15:21 +02:00
|
|
|
fontSystem = NULL;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (MainFont != (FT_Byte *) font_ttf)
|
2010-09-17 17:15:21 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (MainFont != NULL) delete[] MainFont;
|
|
|
|
MainFont = (FT_Byte *) font_ttf;
|
2010-09-17 17:15:21 +02:00
|
|
|
MainFontSize = font_ttf_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
bool SetupDefaultFont(const char *path)
|
2010-09-17 17:15:21 +02:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
FILE *pfile = NULL;
|
|
|
|
|
|
|
|
ClearFontData();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (path) pfile = fopen(path, "rb");
|
2010-09-17 17:15:21 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (pfile)
|
2010-09-17 17:15:21 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
fseek(pfile, 0, SEEK_END);
|
|
|
|
MainFontSize = ftell(pfile);
|
|
|
|
rewind(pfile);
|
2010-09-17 17:15:21 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
MainFont = new (std::nothrow) FT_Byte[MainFontSize];
|
|
|
|
if (!MainFont)
|
2010-09-17 17:15:21 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
MainFont = (FT_Byte *) font_ttf;
|
2010-09-17 17:15:21 +02:00
|
|
|
MainFontSize = font_ttf_size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
fread(MainFont, 1, MainFontSize, pfile);
|
2010-09-17 17:15:21 +02:00
|
|
|
result = true;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
fclose(pfile);
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
fontSystem = new FreeTypeGX(MainFont, MainFontSize);
|
2010-09-17 17:15:21 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|