diff options
author | Xiao Xiangquan <xiaoxiangquan@gmail.com> | 2011-06-02 15:22:22 +0400 |
---|---|---|
committer | Xiao Xiangquan <xiaoxiangquan@gmail.com> | 2011-06-02 15:22:22 +0400 |
commit | a40e1302ae68ff4a5ce3078bdacb43653ba5e1af (patch) | |
tree | e48fd29988ec9e7fd2a9df320219ccc97c30f5ec /source/blender/editors | |
parent | b0cc5b9d4c47625864272654197c4c6ff3f50976 (diff) |
Almost complete the i18n system, including:
Copy unifont..ttf.gz from source tree to target datafile path( now ONLY works with cmake );
Set the locale the same with system's setting;
If need unicode font, unzip and load unifont when init ui styles;
Apply gettext() to labels in space_info.py, who are the main menu items.
Each of these should have been commit one by one. As they work well according to my tests, so I just lazily send a long list.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/datafiles/CMakeLists.txt | 7 | ||||
-rwxr-xr-x | source/blender/editors/datafiles/bunifont.ttf.c | 40 | ||||
-rw-r--r-- | source/blender/editors/include/ED_datafiles.h | 3 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_style.c | 57 |
4 files changed, 95 insertions, 12 deletions
diff --git a/source/blender/editors/datafiles/CMakeLists.txt b/source/blender/editors/datafiles/CMakeLists.txt index a359b0ef6f5..b0c74ca12fc 100644 --- a/source/blender/editors/datafiles/CMakeLists.txt +++ b/source/blender/editors/datafiles/CMakeLists.txt @@ -19,8 +19,10 @@ # # ***** END GPL LICENSE BLOCK ***** -set(INC "") - +set(INC + ../../blenlib + ../../../../intern/guardedalloc +) set(SRC Bfont.c add.png.c @@ -29,6 +31,7 @@ set(SRC blob.png.c blur.png.c bmonofont.ttf.c + bunifont.ttf.c clay.png.c clone.png.c crease.png.c diff --git a/source/blender/editors/datafiles/bunifont.ttf.c b/source/blender/editors/datafiles/bunifont.ttf.c new file mode 100755 index 00000000000..dd2acb0cb52 --- /dev/null +++ b/source/blender/editors/datafiles/bunifont.ttf.c @@ -0,0 +1,40 @@ +/** \file blender/editors/datafiles/bunifont.ttf.c + * \ingroup eddatafiles + */ +/* DataToC output of file <bfont_ttf> */ + +#include <zlib.h> +#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 = 16336376; +static char* datatoc_bunifont_ttf = 0; + +static char unifont_path[1024]; +static char unifont_filename[]="unifont-5.1.20080907.ttf.zip"; + +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 ); +} diff --git a/source/blender/editors/include/ED_datafiles.h b/source/blender/editors/include/ED_datafiles.h index ee29df3fffb..6831f80092c 100644 --- a/source/blender/editors/include/ED_datafiles.h +++ b/source/blender/editors/include/ED_datafiles.h @@ -56,6 +56,9 @@ extern char datatoc_bfont_ttf[]; extern int datatoc_bmonofont_ttf_size; extern char datatoc_bmonofont_ttf[]; +extern int datatoc_bunifont_ttf_size; +extern char* get_datatoc_bunifont_ttf(); + /* Brush icon datafiles */ /* TODO: this could be simplified by putting all the brush icons in one file */ diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 2e4106b3c04..9ebf7c9cd4f 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -76,7 +76,7 @@ /* ********************************************** */ -static uiStyle *ui_style_new(ListBase *styles, const char *name) +static uiStyle *ui_style_new(ListBase *styles, const char *name, short fontid) { uiStyle *style= MEM_callocN(sizeof(uiStyle), "new style"); @@ -85,7 +85,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->panelzoom= 1.0; - style->paneltitle.uifont_id= UIFONT_DEFAULT; + style->paneltitle.uifont_id= fontid; style->paneltitle.points= 12; style->paneltitle.kerning= 1; style->paneltitle.shadow= 1; @@ -94,7 +94,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->paneltitle.shadowalpha= 0.15f; style->paneltitle.shadowcolor= 1.0f; - style->grouplabel.uifont_id= UIFONT_DEFAULT; + style->grouplabel.uifont_id= fontid; style->grouplabel.points= 12; style->grouplabel.kerning= 1; style->grouplabel.shadow= 3; @@ -102,7 +102,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->grouplabel.shady= -1; style->grouplabel.shadowalpha= 0.25f; - style->widgetlabel.uifont_id= UIFONT_DEFAULT; + style->widgetlabel.uifont_id= fontid; style->widgetlabel.points= 11; style->widgetlabel.kerning= 1; style->widgetlabel.shadow= 3; @@ -111,7 +111,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->widgetlabel.shadowalpha= 0.15f; style->widgetlabel.shadowcolor= 1.0f; - style->widget.uifont_id= UIFONT_DEFAULT; + style->widget.uifont_id= fontid; style->widget.points= 11; style->widget.kerning= 1; style->widget.shadowalpha= 0.25f; @@ -295,6 +295,7 @@ void uiStyleInit(void) { uiFont *font= U.uifonts.first; uiStyle *style= U.uistyles.first; + char *lang_set= BLF_lang_get(); /* recover from uninitialized dpi */ if(U.dpi == 0) @@ -335,11 +336,7 @@ void uiStyleInit(void) BLF_size(font->blf_id, 14, U.dpi); } } - - if(style==NULL) { - ui_style_new(&U.uistyles, "Default Style"); - } - + // XXX, this should be moved into a style, but for now best only load the monospaced font once. if (blf_mono_font == -1) blf_mono_font= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); @@ -351,6 +348,46 @@ void uiStyleInit(void) blf_mono_font_render= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); BLF_size(blf_mono_font_render, 12, 72); + + /* XXX Maybe it's bad to do this */ + if(style==NULL) { + if( strcmp(lang_set,"hr.UTF-8")==0 + || strcmp(lang_set,"ar.UTF-8")==0 + || strcmp(lang_set,"bg.UTF-8")==0 + || strcmp(lang_set,"ca.UTF-8")==0 + || strcmp(lang_set,"cs.UTF-8")==0 + || strcmp(lang_set,"de.UTF-8")==0 + || strcmp(lang_set,"el.UTF-8")==0 + || strcmp(lang_set,"es.UTF-8")==0 + || strcmp(lang_set,"fi.UTF-8")==0 + || strcmp(lang_set,"fr.UTF-8")==0 + || strcmp(lang_set,"it.UTF-8")==0 + || strcmp(lang_set,"ja.UTF-8")==0 + || strcmp(lang_set,"ko.UTF-8")==0 + || strcmp(lang_set,"pl.UTF-8")==0 + || strcmp(lang_set,"ro.UTF-8")==0 + || strcmp(lang_set,"ru.UTF-8")==0 + || strcmp(lang_set,"sr.UTF-8")==0 + || strcmp(lang_set,"sv.UTF-8")==0 + || strcmp(lang_set,"uk.UTF-8")==0 + || strcmp(lang_set,"zh_CN.UTF-8")==0 + ) + { + // load unifont only when need. It takes 15MB memories + // get_datatoc_bunifont_ttf() may return null, BLF_load_mem_unique() will handle it + if( blf_unifont == -1 ) + blf_unifont= BLF_load_mem_unique("unifont", (unsigned char *)get_datatoc_bunifont_ttf(), datatoc_bunifont_ttf_size); + if( blf_unifont != -1 ) + { + BLF_size(blf_unifont, 12, 72); + ui_style_new(&U.uistyles, "Unifont Style", blf_unifont ); + } + else + ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT ); + } + else + ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT ); + } } void uiStyleFontSet(uiFontStyle *fs) |