[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11207] trunk/blender/source/blender: Update to the translation code.

Kent Mein mein at cs.umn.edu
Tue Jul 10 17:10:33 CEST 2007


Revision: 11207
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11207
Author:   sirdude
Date:     2007-07-10 17:10:32 +0200 (Tue, 10 Jul 2007)

Log Message:
-----------
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

Modified Paths:
--------------
    trunk/blender/source/blender/ftfont/intern/FTF_TTFont.cpp
    trunk/blender/source/blender/makesdna/DNA_userdef_types.h
    trunk/blender/source/blender/src/filesel.c
    trunk/blender/source/blender/src/language.c

Modified: trunk/blender/source/blender/ftfont/intern/FTF_TTFont.cpp
===================================================================
--- trunk/blender/source/blender/ftfont/intern/FTF_TTFont.cpp	2007-07-10 09:45:11 UTC (rev 11206)
+++ trunk/blender/source/blender/ftfont/intern/FTF_TTFont.cpp	2007-07-10 15:10:32 UTC (rev 11207)
@@ -335,6 +335,8 @@
 	   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 @@
 		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 @@
 		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 @@
 		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);

Modified: trunk/blender/source/blender/makesdna/DNA_userdef_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_userdef_types.h	2007-07-10 09:45:11 UTC (rev 11206)
+++ trunk/blender/source/blender/makesdna/DNA_userdef_types.h	2007-07-10 15:10:32 UTC (rev 11207)
@@ -243,6 +243,7 @@
 #define USER_TR_TEXTEDIT		16
 #define USER_DOTRANSLATE		32
 #define USER_USETEXTUREFONT		64
+#define CONVERT_TO_UTF8			128
 
 /* dupflag */
 

Modified: trunk/blender/source/blender/src/filesel.c
===================================================================
--- trunk/blender/source/blender/src/filesel.c	2007-07-10 09:45:11 UTC (rev 11206)
+++ trunk/blender/source/blender/src/filesel.c	2007-07-10 15:10:32 UTC (rev 11207)
@@ -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 @@
 
 }
 
-#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 @@
 #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;
 

Modified: trunk/blender/source/blender/src/language.c
===================================================================
--- trunk/blender/source/blender/src/language.c	2007-07-10 09:45:11 UTC (rev 11206)
+++ trunk/blender/source/blender/src/language.c	2007-07-10 15:10:32 UTC (rev 11207)
@@ -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 @@
 #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
 





More information about the Bf-blender-cvs mailing list