Update to the translation code. Patch provided by dripstone.
Basically move stuff out of filesel.c and into language.c and changes when exactly it does the conversion. It was doing it when not needed for some machines. It probably still needs work but its slowly getting better. I also removed some commented out code. Kent
This commit is contained in:
@@ -335,6 +335,8 @@ float FTF_TTFont::DrawString(char* str, unsigned int flag)
|
||||
removes special characters completely. So, for now we just skip that then. (ton) */
|
||||
if (FTF_USE_GETTEXT & flag)
|
||||
utf8towchar(wstr, gettext(str));
|
||||
else if (FTF_INPUT_UTF8 & flag)
|
||||
utf8towchar(wstr, str);
|
||||
|
||||
glGetFloatv(GL_CURRENT_COLOR, color);
|
||||
|
||||
@@ -344,7 +346,7 @@ float FTF_TTFont::DrawString(char* str, unsigned int flag)
|
||||
glPixelTransferf(GL_GREEN_SCALE, color[1]);
|
||||
glPixelTransferf(GL_BLUE_SCALE, color[2]);
|
||||
|
||||
if (FTF_USE_GETTEXT & flag)
|
||||
if ((FTF_USE_GETTEXT | FTF_INPUT_UTF8) & flag)
|
||||
font->Render(wstr);
|
||||
else
|
||||
font->Render(str);
|
||||
@@ -362,7 +364,7 @@ float FTF_TTFont::DrawString(char* str, unsigned int flag)
|
||||
glTranslatef(pen_x, pen_y, 0.0);
|
||||
glScalef(fsize, fsize, 1.0);
|
||||
|
||||
if (FTF_USE_GETTEXT & flag)
|
||||
if ((FTF_USE_GETTEXT | FTF_INPUT_UTF8) & flag)
|
||||
font->Render(wstr);
|
||||
else
|
||||
font->Render(str);
|
||||
@@ -373,7 +375,7 @@ float FTF_TTFont::DrawString(char* str, unsigned int flag)
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
if (FTF_USE_GETTEXT & flag)
|
||||
if ((FTF_USE_GETTEXT | FTF_INPUT_UTF8) & flag)
|
||||
return font->Advance(wstr);
|
||||
else
|
||||
return font->Advance(str);
|
||||
|
||||
@@ -243,6 +243,7 @@ extern UserDef U; /* from usiblender.c !!!! */
|
||||
#define USER_TR_TEXTEDIT 16
|
||||
#define USER_DOTRANSLATE 32
|
||||
#define USER_USETEXTUREFONT 64
|
||||
#define CONVERT_TO_UTF8 128
|
||||
|
||||
/* dupflag */
|
||||
|
||||
|
||||
@@ -111,10 +111,6 @@
|
||||
|
||||
#include "BIF_fsmenu.h" /* include ourselves */
|
||||
|
||||
#if defined WITH_ICONV
|
||||
#include "iconv.h"
|
||||
#endif
|
||||
|
||||
#if defined WIN32 || defined __BeOS
|
||||
int fnmatch(const char *pattern, const char *string, int flags)
|
||||
{
|
||||
@@ -902,32 +898,6 @@ static void linerect(int id, int x, int y)
|
||||
|
||||
}
|
||||
|
||||
#ifdef WITH_ICONV
|
||||
static void string_to_utf8(char *original, char *utf_8, char *code)
|
||||
{
|
||||
size_t inbytesleft=strlen(original);
|
||||
size_t outbytesleft=512;
|
||||
size_t rv=0;
|
||||
iconv_t cd;
|
||||
|
||||
cd=iconv_open("UTF-8", code);
|
||||
|
||||
if (cd == (iconv_t)(-1)) {
|
||||
printf("iconv_open Error");
|
||||
*utf_8='\0';
|
||||
return ;
|
||||
}
|
||||
rv=iconv(cd, &original, &inbytesleft, &utf_8, &outbytesleft);
|
||||
if (rv == (size_t) -1) {
|
||||
printf("iconv Error\n");
|
||||
return ;
|
||||
}
|
||||
*utf_8 = '\0';
|
||||
iconv_close(cd);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void print_line(SpaceFile *sfile, struct direntry *files, int x, int y)
|
||||
{
|
||||
int boxcol=0;
|
||||
@@ -978,25 +948,24 @@ static void print_line(SpaceFile *sfile, struct direntry *files, int x, int y)
|
||||
#ifdef WITH_ICONV
|
||||
{
|
||||
struct LANGMenuEntry *lme;
|
||||
char utf_8[512];
|
||||
lme = find_language(U.language);
|
||||
|
||||
lme = find_language(U.language);
|
||||
|
||||
if (!strcmp(lme->code, "ja_JP")) { /* japanese */
|
||||
string_to_utf8(files->relname, utf_8, "Shift_JIS");
|
||||
BIF_RasterPos((float)x, (float)y); /* texture fonts */
|
||||
BIF_DrawString(G.font, utf_8, (U.transopts & USER_TR_MENUS));
|
||||
} else if (!strcmp(lme->code, "zh_CN")) { /* chinese */
|
||||
string_to_utf8(files->relname, utf_8, "gb2312");
|
||||
BIF_RasterPos((float)x, (float)y); /* texture fonts */
|
||||
BIF_DrawString(G.font, utf_8, (U.transopts & USER_TR_MENUS));
|
||||
if (!strcmp(lme->code, "ja_JP") ||
|
||||
!strcmp(lme->code, "zh_CN"))
|
||||
{
|
||||
BIF_RasterPos((float)x, (float)y);
|
||||
#ifdef WIN32
|
||||
BIF_DrawString(G.font, files->relname, ((U.transopts & USER_TR_MENUS) | CONVERT_TO_UTF8));
|
||||
#else
|
||||
BIF_DrawString(G.font, files->relname, (U.transopts & USER_TR_MENUS));
|
||||
#endif
|
||||
} else {
|
||||
BMF_DrawString(G.font, files->relname);
|
||||
}
|
||||
}
|
||||
#else
|
||||
BMF_DrawString(G.font, files->relname);
|
||||
#endif
|
||||
#endif /* WITH_ICONV */
|
||||
|
||||
x += sfile->maxnamelen + 100;
|
||||
|
||||
|
||||
@@ -52,6 +52,33 @@
|
||||
|
||||
#include "BMF_Api.h"
|
||||
|
||||
#ifdef WITH_ICONV
|
||||
#include "iconv.h"
|
||||
|
||||
void string_to_utf8(char *original, char *utf_8, char *code)
|
||||
{
|
||||
size_t inbytesleft=strlen(original);
|
||||
size_t outbytesleft=512;
|
||||
size_t rv=0;
|
||||
iconv_t cd;
|
||||
|
||||
cd=iconv_open("UTF-8", code);
|
||||
|
||||
if (cd == (iconv_t)(-1)) {
|
||||
printf("iconv_open Error");
|
||||
*utf_8='\0';
|
||||
return ;
|
||||
}
|
||||
rv=iconv(cd, &original, &inbytesleft, &utf_8, &outbytesleft);
|
||||
if (rv == (size_t) -1) {
|
||||
printf("iconv Error\n");
|
||||
return ;
|
||||
}
|
||||
*utf_8 = '\0';
|
||||
iconv_close(cd);
|
||||
}
|
||||
#endif // WITH_ICONV
|
||||
|
||||
#ifdef INTERNATIONAL
|
||||
#include "FTF_Api.h"
|
||||
|
||||
@@ -92,23 +119,31 @@ int BIF_DrawString(BMF_Font* font, char *str, int translate)
|
||||
#ifdef INTERNATIONAL
|
||||
if(G.ui_international == TRUE) {
|
||||
if(translate)
|
||||
return FTF_DrawString(str, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
|
||||
{
|
||||
#ifdef WITH_ICONV
|
||||
if(translate & CONVERT_TO_UTF8) {
|
||||
char utf_8[512];
|
||||
|
||||
struct LANGMenuEntry *lme;
|
||||
lme = find_language(U.language);
|
||||
|
||||
if (!strcmp(lme->code, "ja_JP"))
|
||||
string_to_utf8(str, utf_8, "Shift_JIS"); /* Japanese */
|
||||
else if (!strcmp(lme->code, "zh_CN"))
|
||||
string_to_utf8(str, utf_8, "GB2312"); /* Chinese */
|
||||
|
||||
return FTF_DrawString(utf_8, FTF_INPUT_UTF8);
|
||||
}
|
||||
else
|
||||
#endif // WITH_ICONV
|
||||
return FTF_DrawString(str, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
|
||||
}
|
||||
else
|
||||
return FTF_DrawString(str, FTF_NO_TRANSCONV | FTF_INPUT_UTF8);
|
||||
} else {
|
||||
return BMF_DrawString(font, str);
|
||||
/*
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_BLEND);
|
||||
BMF_GetFontTexture(font);??
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
BMF_DrawStringTexture(font, str, pen_x, pen_y, 0.0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_BLEND);
|
||||
return 0;
|
||||
*/
|
||||
}
|
||||
#else
|
||||
#else // INTERNATIONAL
|
||||
return BMF_DrawString(font, str);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user