i18n: replace gnu unifont with droid sans font
authorSergey Sharybin <sergey.vfx@gmail.com>
Sat, 17 Sep 2011 20:50:22 +0000 (20:50 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sat, 17 Sep 2011 20:50:22 +0000 (20:50 +0000)
- Static variables can be initialized with constants only.
- Removed bunifont.ttf.c from datafiles -- it's not actually a
  data file. Unicode font loading stuff is not in blenkernel/font.c
- Allocate as much memory for unzipped data as it's needed.
  Default read chunk is 512Kb.
- Fixed regression (or just a typo) in setting utf locale.
- Default locale set to en_US:en works fine now.
- Commented put Nepali language in user preferences -- it's
  not supported by current droid font and imo it's better to
  have nice font for languages we actually have translation for
  rather than allowing to choose more languages in user preferences.

14 files changed:
release/bin/.blender/fonts/droidsans.ttf.gz [new file with mode: 0644]
release/bin/.blender/fonts/unifont.ttf.gz [deleted file]
source/blender/blenfont/intern/blf_lang.c
source/blender/blenkernel/BKE_font.h
source/blender/blenkernel/CMakeLists.txt
source/blender/blenkernel/SConscript
source/blender/blenkernel/intern/font.c
source/blender/blenlib/BLI_fileops.h
source/blender/blenlib/intern/fileops.c
source/blender/editors/datafiles/CMakeLists.txt
source/blender/editors/datafiles/bunifont.ttf.c [deleted file]
source/blender/editors/interface/interface_style.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/windowmanager/intern/wm_init_exit.c

diff --git a/release/bin/.blender/fonts/droidsans.ttf.gz b/release/bin/.blender/fonts/droidsans.ttf.gz
new file mode 100644 (file)
index 0000000..f606702
Binary files /dev/null and b/release/bin/.blender/fonts/droidsans.ttf.gz differ
diff --git a/release/bin/.blender/fonts/unifont.ttf.gz b/release/bin/.blender/fonts/unifont.ttf.gz
deleted file mode 100755 (executable)
index 8d10371..0000000
Binary files a/release/bin/.blender/fonts/unifont.ttf.gz and /dev/null differ
index 581a936ee87a0390a76ecaad58c16215a9a45a93..8f745180b8ba08ed0020c9766ca59203a50c656b 100644 (file)
@@ -92,8 +92,8 @@ static const char *locales[] = {
        "arabic", "ar_EG",
        "bulgarian", "bg_BG",
        "greek", "el_GR",
-       "korean" "ko_KR",
-       "nepali" "ne_NP",
+       "korean", "ko_KR",
+       "nepali", "ne_NP",
 };
 
 void BLF_lang_init(void)
@@ -150,10 +150,21 @@ void BLF_lang_set(const char *str)
        {
                const char *locale;
                static char default_locale[64]="\0";
-               static char *env_language = getenv("LANGUAGE");
 
-               if(default_locale[0]==0 && env_language!=NULL) /* store defaul locale */
-                       strncpy(default_locale, env_language, sizeof(default_locale));
+               if(default_locale[0]==0) {
+                       char *env_language= getenv("LANGUAGE");
+
+                       if(env_language) {
+                               char *s;
+
+                               /* store defaul locale */
+                               strncpy(default_locale, env_language, sizeof(default_locale));
+
+                               /* use first language as default */
+                               s= strchr(default_locale, ':');
+                               if(s) s[0]= 0;
+                       }
+               }
 
                if(short_locale[0])
                        locale= short_locale;
@@ -166,7 +177,7 @@ void BLF_lang_set(const char *str)
                locreturn= setlocale(LC_ALL, locale);
 
                if (locreturn == NULL) {
-                       char *short_locale_utf8= BLI_sprintfN("%s", short_locale);
+                       char *short_locale_utf8= BLI_sprintfN("%s.UTF-8", short_locale);
 
                        locreturn= setlocale(LC_ALL, short_locale_utf8);
 
index 2195b370a5fc6fa30f3692859954ace529d25e67..3f89f5e8448771b432666660cdb861d8a16c0fcf 100644 (file)
@@ -89,6 +89,10 @@ void wcs2utf8s(char *dst, const wchar_t *src);
 size_t wcsleninu8(wchar_t *src);
 size_t utf8towchar(wchar_t *w, const char *c);
 
+#ifdef INTERNATIONAL
+unsigned char *BKE_font_get_unifont(int *unifont_size);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index 9cf0a92742fc376caf6fffa9fe665213aefde476..b800c94a09c9f30a7a0a56fd19606799ca4c47ca 100644 (file)
@@ -362,6 +362,10 @@ if(WITH_GAMEENGINE)
        )
 endif()
 
+if(WITH_INTERNATIONAL)
+       add_definitions(-DINTERNATIONAL)
+endif()
+
 if(MSVC)
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
 endif()
index 56de8afc0da5ff0a2be12062627b7391050d6d6d..3935f01e46e17a348e9aeb4b8cda13b13fe00506 100644 (file)
@@ -97,6 +97,9 @@ if env['WITH_BF_GAMEENGINE']:
 else:
     sources.remove('intern' + os.sep + 'navmesh_conversion.cpp')
 
+if env['WITH_BF_INTERNATIONAL']:
+    defs.append('INTERNATIONAL')
+
 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
     incs += ' ' + env['BF_PTHREADS_INC']
 
index 6898615c7537b045cbd1eff58b979599715ee2d1..0a94b4e3fd1496cadb06dcb06da328a4f165bd17 100644 (file)
@@ -255,6 +255,29 @@ static PackedFile *get_builtin_packedfile(void)
        }
 }
 
+#ifdef INTERNATIONAL
+const char unifont_filename[]="droidsans.ttf.gz";
+static unsigned char *unifont_ttf= NULL;
+static int unifont_size= 0;
+
+unsigned char *BKE_font_get_unifont(int *unifont_size_r)
+{
+       if(unifont_ttf==NULL) {
+               char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts");
+               char unifont_path[1024];
+
+               BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_filename);
+
+               unifont_ttf= BLI_ungzip_to_mem(unifont_path, &unifont_size);
+       }
+
+       *unifont_size_r= unifont_size;
+
+       return unifont_ttf;
+}
+
+#endif
+
 void free_ttfont(void)
 {
        struct TmpFont *tf;
@@ -265,6 +288,9 @@ void free_ttfont(void)
                tf->vfont= NULL;
        }
        BLI_freelistN(&ttfdata);
+
+       if(unifont_ttf)
+               MEM_freeN(unifont_ttf);
 }
 
 struct TmpFont *vfont_find_tmpfont(VFont *vfont)
index 27b1a67b32ce780bd9cf7867db0ec0dd55d8a86b..21d28ca31853f32e99b3404fe882db83da38c89d 100644 (file)
@@ -53,7 +53,7 @@ int   BLI_exists(const char *file);
 int   BLI_copy_fileops(const char *file, const char *to);
 int   BLI_rename(const char *from, const char *to);
 int   BLI_gzip(const char *from, const char *to);
-int   BLI_ungzip_to_mem(const char *from_file, char *to_mem, const int size);
+char *BLI_ungzip_to_mem(const char *from_file, int *size_r);
 int   BLI_delete(const char *file, int dir, int recursive);
 int   BLI_move(const char *file, const char *to);
 int   BLI_touch(const char *file);
index 7c2b9f03c605acc4ab3c7ee15c65e3121f5d1d5d..6b125435b3142219f51c71cb0a481f5849ab80d3 100644 (file)
@@ -52,6 +52,8 @@
 #include <sys/param.h>
 #endif
 
+#include "MEM_guardedalloc.h"
+
 #include "BLI_blenlib.h"
 
 #include "BKE_utildefines.h"
@@ -107,18 +109,39 @@ int BLI_gzip(const char *from, const char *to) {
 /* gzip the file in from_file and write it to memery to_mem, at most size bytes.
    return the unziped size
   */
-int BLI_ungzip_to_mem(const char *from_file, char *to_mem, const int size)
+char *BLI_ungzip_to_mem(const char *from_file, int *size_r)
 {
        gzFile gzfile;
-       int readsize;
+       int readsize, size, alloc_size=0;
+       char *mem= NULL;
+       const int chunk_size= 512*1024;
+
+       size= 0;
 
        gzfile = gzopen( from_file, "rb" );
-       readsize = gzread( gzfile, to_mem, size);
 
-       if (readsize < 0)
-        readsize = EOF;
+       for(;;) {
+               if(mem==NULL) {
+                       mem= MEM_callocN(chunk_size, "BLI_ungzip_to_mem");
+                       alloc_size= chunk_size;
+               } else {
+                       mem= MEM_reallocN(mem, size+chunk_size);
+                       alloc_size+= chunk_size;
+               }
+
+               readsize= gzread(gzfile, mem+size, chunk_size);
+               if(readsize>0) {
+                       size+= readsize;
+               }
+               else break;
+       }
+
+       if(mem && alloc_size!=size)
+               mem= MEM_reallocN(mem, size);
+
+       *size_r= size;
 
-       return readsize;
+       return mem;
 }
 
 
index fc85dcf5fa85b3cf04e58c83a89fa1a51d2646d8..a31b3c3b2bde4fab4456e89c0cb2c065395d8049 100644 (file)
@@ -32,7 +32,6 @@ set(INC_SYS
 set(SRC
        Bfont.c
        bfont.ttf.c
-       bunifont.ttf.c
 )
 
 if(WITH_BLENDER)
diff --git a/source/blender/editors/datafiles/bunifont.ttf.c b/source/blender/editors/datafiles/bunifont.ttf.c
deleted file mode 100755 (executable)
index 7af8084..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/** \file blender/editors/datafiles/bunifont.ttf.c
- *  \ingroup eddatafiles
- */
-/* DataToC output of file <bfont_ttf> */
-
-#include <stdio.h>
-#include "BLI_path_util.h"
-#include "BLI_string.h"
-#include "BLI_fileops.h"
-#include "BLI_memarena.h"
-#include "MEM_guardedalloc.h"
-
-const int datatoc_bunifont_ttf_size = 16179552;
-static char* datatoc_bunifont_ttf = 0;
-
-static char unifont_path[1024];
-const char unifont_filename[]="unifont.ttf.gz";
-
-char *get_datatoc_bunifont_ttf(void)
-{
-    if( datatoc_bunifont_ttf==NULL )
-    {
-        char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts");
-        BLI_snprintf( unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_filename );
-
-        if( BLI_exists(unifont_path) )
-        {
-                       datatoc_bunifont_ttf = (char*)MEM_mallocN( datatoc_bunifont_ttf_size, "get_datatoc_bunifont_ttf" );
-                       BLI_ungzip_to_mem( unifont_path, datatoc_bunifont_ttf, datatoc_bunifont_ttf_size );
-        }
-    }
-    return datatoc_bunifont_ttf;
-}
-
-void free_datatoc_bunifont_ttf(void)
-{
-       if( datatoc_bunifont_ttf!=NULL )
-               MEM_freeN( datatoc_bunifont_ttf );
-}
index af3d1c2d5e6e6aa4db5afe6566678b0f92fd39f4..d242da8e480bfcb267c4c63652822f4297221cb3 100644 (file)
@@ -44,6 +44,7 @@
 #include "BLI_string.h"
 
 #include "BKE_global.h"
+#include "BKE_font.h"
 
 
 #include "BLF_api.h"
@@ -321,7 +322,17 @@ void uiStyleInit(void)
        for(font= U.uifonts.first; font; font= font->next) {
                
                if(font->uifont_id==UIFONT_DEFAULT) {
-                       font->blf_id= BLF_load_mem_unique("default", (unsigned char *)get_datatoc_bunifont_ttf(), datatoc_bunifont_ttf_size);
+#ifdef INTERNATIONAL
+                       int unifont_size;
+                       unsigned char *unifont_ttf= BKE_font_get_unifont(&unifont_size);
+
+                       if(unifont_ttf)
+                               font->blf_id= BLF_load_mem_unique("default", unifont_ttf, unifont_size);
+                       else
+                               font->blf_id= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size);
+#else
+                       font->blf_id= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size);
+#endif
                }               
                else {
                        font->blf_id= BLF_load(font->filename);
index 533895fedaaf1aeab327aaba16d8b84f0b85bacb..5f2c3b494f7beb2e04f4f820770b148f01403a32 100644 (file)
@@ -2497,7 +2497,7 @@ static void rna_def_userdef_system(BlenderRNA *brna)
                {22, "BULGARIAN", 0, N_("Bulgarian (Български)"), "bg_BG"},
                {23, "GREEK", 0, N_("Greek (Ελληνικά)"), "el_GR"},
                {24, "KOREAN", 0, N_("Korean (한국 언어)"), "ko_KR"},
-               {25, "Nepali", 0, N_("Nepali (नेपाली)"), "ne_NP"},
+               /*{25, "Nepali", 0, N_("Nepali (नेपाली)"), "ne_NP"},*/
                {0, NULL, 0, NULL, NULL}};
 
        srna= RNA_def_struct(brna, "UserPreferencesSystem", NULL);
index 2bfeb104d2af775ec2af6515e17ea350a9698b63..510b3403c05e2bb08575dcb5e0e5524a2edd35a7 100644 (file)
@@ -342,7 +342,6 @@ extern void free_anim_copybuf(void);
 extern void free_anim_drivers_copybuf(void); 
 extern void free_fmodifiers_copybuf(void); 
 extern void free_posebuf(void); 
-extern void free_datatoc_bunifont_ttf(void);
 
 /* called in creator.c even... tsk, split this! */
 void WM_exit(bContext *C)
@@ -381,7 +380,6 @@ void WM_exit(bContext *C)
        BIF_freeTemplates(C);
        
        free_ttfont(); /* bke_font.h */
-       free_datatoc_bunifont_ttf(); /* bunifont.ttf.c */
        free_openrecent();
        
        BKE_freecubetable();