mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-21 22:42:20 +00:00
Add more characters to ttf demo
This commit is contained in:
parent
7c9523b27e
commit
d758a9fdbe
3 changed files with 22 additions and 19 deletions
|
@ -1,5 +1,5 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
Copyright (c) 2009-2017 The GRRLIB Team
|
||||
Copyright (c) 2009-2019 The GRRLIB Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -37,7 +37,7 @@ static void DrawBitmap(FT_Bitmap *bitmap, int offset, int top, const u8 cR, cons
|
|||
* @return int 0=OK; -1=Failed
|
||||
*/
|
||||
int GRRLIB_InitTTF () {
|
||||
if (FT_Init_FreeType(&ftLibrary)) {
|
||||
if (FT_Init_FreeType(&ftLibrary) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -59,13 +59,13 @@ void GRRLIB_ExitTTF (void) {
|
|||
*/
|
||||
GRRLIB_ttfFont* GRRLIB_LoadTTF (const u8* file_base, s32 file_size) {
|
||||
FT_Face Face;
|
||||
if (FT_New_Memory_Face(ftLibrary, file_base, file_size, 0, &Face)) {
|
||||
if (FT_New_Memory_Face(ftLibrary, file_base, file_size, 0, &Face) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
GRRLIB_ttfFont* myFont = (GRRLIB_ttfFont*)malloc(sizeof(GRRLIB_ttfFont));
|
||||
myFont->kerning = FT_HAS_KERNING(Face);
|
||||
/*
|
||||
if (FT_Set_Pixel_Sizes(Face, 0, fontSize)) {
|
||||
if (FT_Set_Pixel_Sizes(Face, 0, fontSize) != 0) {
|
||||
FT_Set_Pixel_Sizes(Face, 0, 12);
|
||||
}
|
||||
*/
|
||||
|
@ -135,7 +135,7 @@ void GRRLIB_PrintfTTFW(int x, int y, GRRLIB_ttfFont *myFont, const wchar_t *utf3
|
|||
FT_UInt previousGlyph = 0;
|
||||
u8 cR = R(color), cG = G(color), cB = B(color);
|
||||
|
||||
if (FT_Set_Pixel_Sizes(Face, 0, fontSize)) {
|
||||
if (FT_Set_Pixel_Sizes(Face, 0, fontSize) != 0) {
|
||||
FT_Set_Pixel_Sizes(Face, 0, 12);
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ void GRRLIB_PrintfTTFW(int x, int y, GRRLIB_ttfFont *myFont, const wchar_t *utf3
|
|||
FT_Get_Kerning(myFont->face, previousGlyph, glyphIndex, FT_KERNING_DEFAULT, &delta);
|
||||
penX += delta.x >> 6;
|
||||
}
|
||||
if (FT_Load_Glyph(myFont->face, glyphIndex, FT_LOAD_RENDER)) {
|
||||
if (FT_Load_Glyph(myFont->face, glyphIndex, FT_LOAD_RENDER) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -194,11 +194,11 @@ static void DrawBitmap(FT_Bitmap *bitmap, int offset, int top, const u8 cR, cons
|
|||
* @param fontSize The size of the font.
|
||||
* @return The width of a text in pixel.
|
||||
*/
|
||||
unsigned int GRRLIB_WidthTTF(GRRLIB_ttfFont *myFont, const char *string, unsigned int fontSize) {
|
||||
u32 GRRLIB_WidthTTF(GRRLIB_ttfFont *myFont, const char *string, unsigned int fontSize) {
|
||||
if (myFont == NULL || string == NULL) {
|
||||
return 0;
|
||||
}
|
||||
unsigned int penX;
|
||||
u32 penX;
|
||||
size_t length = strlen(string) + 1;
|
||||
wchar_t *utf32 = (wchar_t*)malloc(length * sizeof(wchar_t));
|
||||
length = mbstowcs(utf32, string, length);
|
||||
|
@ -218,17 +218,17 @@ unsigned int GRRLIB_WidthTTF(GRRLIB_ttfFont *myFont, const char *string, unsigne
|
|||
* @param fontSize The size of the font.
|
||||
* @return The width of a text in pixel.
|
||||
*/
|
||||
unsigned int GRRLIB_WidthTTFW(GRRLIB_ttfFont *myFont, const wchar_t *utf32, unsigned int fontSize) {
|
||||
u32 GRRLIB_WidthTTFW(GRRLIB_ttfFont *myFont, const wchar_t *utf32, unsigned int fontSize) {
|
||||
if (myFont == NULL || utf32 == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FT_Face Face = (FT_Face)myFont->face;
|
||||
unsigned int penX = 0;
|
||||
u32 penX = 0;
|
||||
FT_UInt glyphIndex;
|
||||
FT_UInt previousGlyph = 0;
|
||||
|
||||
if (FT_Set_Pixel_Sizes(myFont->face, 0, fontSize)) {
|
||||
if (FT_Set_Pixel_Sizes(myFont->face, 0, fontSize) != 0) {
|
||||
FT_Set_Pixel_Sizes(myFont->face, 0, 12);
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ unsigned int GRRLIB_WidthTTFW(GRRLIB_ttfFont *myFont, const wchar_t *utf32, unsi
|
|||
FT_Get_Kerning(Face, previousGlyph, glyphIndex, FT_KERNING_DEFAULT, &delta);
|
||||
penX += delta.x >> 6;
|
||||
}
|
||||
if (FT_Load_Glyph(Face, glyphIndex, FT_LOAD_RENDER)) {
|
||||
if (FT_Load_Glyph(Face, glyphIndex, FT_LOAD_RENDER) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,8 +177,8 @@ GRRLIB_ttfFont* GRRLIB_LoadTTF(const u8* file_base, s32 file_size);
|
|||
void GRRLIB_FreeTTF(GRRLIB_ttfFont *myFont);
|
||||
void GRRLIB_PrintfTTF(int x, int y, GRRLIB_ttfFont *myFont, const char *string, unsigned int fontSize, const u32 color);
|
||||
void GRRLIB_PrintfTTFW(int x, int y, GRRLIB_ttfFont *myFont, const wchar_t *string, unsigned int fontSize, const u32 color);
|
||||
unsigned int GRRLIB_WidthTTF(GRRLIB_ttfFont *myFont, const char *, unsigned int);
|
||||
unsigned int GRRLIB_WidthTTFW(GRRLIB_ttfFont *myFont, const wchar_t *, unsigned int);
|
||||
u32 GRRLIB_WidthTTF(GRRLIB_ttfFont *myFont, const char *, unsigned int);
|
||||
u32 GRRLIB_WidthTTFW(GRRLIB_ttfFont *myFont, const wchar_t *, unsigned int);
|
||||
|
||||
#endif // __GRRLIB_FNLIB_H__
|
||||
/** @} */ // end of group
|
||||
|
|
|
@ -15,7 +15,6 @@ static u8 CalculateFrameRate();
|
|||
static bool ScreenShot();
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char FPS[255] = "";
|
||||
bool ShowFPS = false;
|
||||
|
||||
// Initialise the Graphics & Video subsystem
|
||||
|
@ -31,11 +30,14 @@ int main(int argc, char **argv) {
|
|||
|
||||
// Fill a table with characters
|
||||
u32 i, n = 0;
|
||||
wchar_t charTable[450];
|
||||
wchar_t charTable[460];
|
||||
for(i=33; i<=126; i++) { // 0 to 93
|
||||
charTable[n++] = i;
|
||||
}
|
||||
for(i=161; i<=516; i++) { // 94 to 449
|
||||
for(i=161; i<=518; i++) { // 94 to 451
|
||||
charTable[n++] = i;
|
||||
}
|
||||
for(i=9824; i<=9831; i++) { // 452 to 459
|
||||
charTable[n++] = i;
|
||||
}
|
||||
|
||||
|
@ -54,7 +56,7 @@ int main(int argc, char **argv) {
|
|||
// Loop forever
|
||||
while(1) {
|
||||
GRRLIB_DrawImg(0, 0, CopiedImg, 0, 1, 1, 0xFFFFFFFF);
|
||||
Letter[0] = charTable[rand() % 449];
|
||||
Letter[0] = charTable[rand() % 459];
|
||||
GRRLIB_PrintfTTFW(rand() % rmode->fbWidth - 50,
|
||||
rand() % rmode->efbHeight - 50,
|
||||
myFont,
|
||||
|
@ -63,7 +65,8 @@ int main(int argc, char **argv) {
|
|||
((rand() % 0xFFFFFF) << 8) | 0xFF);
|
||||
GRRLIB_Screen2Texture(0, 0, CopiedImg, false);
|
||||
|
||||
if(ShowFPS) {
|
||||
if(ShowFPS == true) {
|
||||
char FPS[255];
|
||||
sprintf(FPS, "Current FPS: %d", CalculateFrameRate());
|
||||
GRRLIB_PrintfTTF(500+1, 25+1, myFont, FPS, 12, 0x000000FF);
|
||||
GRRLIB_PrintfTTF(500, 25, myFont, FPS, 12, 0xFFFFFFFF);
|
||||
|
|
Loading…
Reference in a new issue