i18n: replace gnu unifont with droid sans font
- 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.
This commit is contained in:
BIN
release/bin/.blender/fonts/droidsans.ttf.gz
Normal file
BIN
release/bin/.blender/fonts/droidsans.ttf.gz
Normal file
Binary file not shown.
Binary file not shown.
@@ -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);
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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()
|
||||
|
@@ -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']
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
return readsize;
|
||||
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 mem;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -32,7 +32,6 @@ set(INC_SYS
|
||||
set(SRC
|
||||
Bfont.c
|
||||
bfont.ttf.c
|
||||
bunifont.ttf.c
|
||||
)
|
||||
|
||||
if(WITH_BLENDER)
|
||||
|
@@ -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 );
|
||||
}
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user