From ae0124157f012aeda994534c21aebda1bae054cd Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 21 Sep 2011 15:15:30 +0000 Subject: Translation: reload font on enabling/disabling use international fonts. --- source/blender/editors/include/UI_interface.h | 1 + source/blender/editors/interface/interface.c | 5 ++++ source/blender/editors/interface/interface_style.c | 29 ++++++++++++++++------ .../editors/interface/interface_templates.c | 2 +- source/blender/editors/space_node/drawnode.c | 4 +-- source/blender/makesrna/intern/rna_userdef.c | 4 +++ source/blenderplayer/bad_level_call_stubs/stubs.c | 1 + 7 files changed, 36 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 06b44e36b69..f5abebbebd5 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -610,6 +610,7 @@ void UI_remove_popup_handlers(struct ListBase *handlers, uiPopupBlockHandle *pop void UI_init(void); void UI_init_userdef(void); +void UI_reinit_font(void); void UI_exit(void); /* Layout diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 2ff77d255c6..7dac8c6351a 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -3552,6 +3552,11 @@ void UI_init_userdef(void) uiStyleInit(); } +void UI_reinit_font() +{ + uiStyleInit(); +} + void UI_exit(void) { ui_resources_free(); diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 5ea20b33b3a..3a9879384a3 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -323,13 +323,28 @@ void uiStyleInit(void) if(font->uifont_id==UIFONT_DEFAULT) { #ifdef INTERNATIONAL - int unifont_size; - unsigned char *unifont_ttf= BLF_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); + int font_size= datatoc_bfont_ttf_size; + unsigned char *font_ttf= (unsigned char*)datatoc_bfont_ttf; + static int last_font_size = 0; + + /* use unicode font for translation */ + if(U.transopts & USER_DOTRANSLATE) { + font_ttf= BLF_get_unifont(&font_size); + + if(!font_ttf) { + /* fall back if not found */ + font_size= datatoc_bfont_ttf_size; + font_ttf= (unsigned char*)datatoc_bfont_ttf; + } + } + + /* relload only if needed */ + if(last_font_size != font_size) { + BLF_unload("default"); + last_font_size = font_size; + } + + font->blf_id= BLF_load_mem("default", font_ttf, font_size); #else font->blf_id= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size); #endif diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index af515bf8061..bec9e6a7664 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2488,7 +2488,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C) uiLayout *ui_abs; uiBlock *block; uiBut *but; - uiStyle *style= U.uistyles.first; + uiStyle *style= UI_GetStyle(); int width; int icon=0; diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index f34cef4d2aa..970eccb8be3 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -129,7 +129,7 @@ static uiBlock *socket_component_menu(bContext *C, ARegion *ar, void *args_v) block= uiBeginBlock(C, ar, "socket menu", UI_EMBOSS); uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN); - layout= uiLayoutColumn(uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, args->x, args->y+2, args->width, NODE_DY, U.uistyles.first), 0); + layout= uiLayoutColumn(uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, args->x, args->y+2, args->width, NODE_DY, UI_GetStyle()), 0); uiItemR(layout, &args->ptr, "default_value", UI_ITEM_R_EXPAND, "", ICON_NONE); @@ -788,7 +788,7 @@ static void node_draw_group(const bContext *C, ARegion *ar, SpaceNode *snode, bN UI_ThemeColor(TH_TEXT_HI); layout = uiBlockLayout(gnode->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, (short)(rect.xmin+15), (short)(rect.ymax+group_header), - MIN2((int)(rect.xmax - rect.xmin-18.0f), node_group_frame+20), group_header, U.uistyles.first); + MIN2((int)(rect.xmax - rect.xmin-18.0f), node_group_frame+20), group_header, UI_GetStyle()); RNA_pointer_create(&ntree->id, &RNA_Node, gnode, &ptr); uiTemplateIDBrowse(layout, (bContext*)C, &ptr, "node_tree", NULL, NULL, NULL); uiBlockLayoutResolve(gnode->block, NULL, NULL); diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index b9a53acd6f4..44d645f970f 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -65,6 +65,8 @@ #include "MEM_guardedalloc.h" #include "MEM_CacheLimiterC-Api.h" +#include "UI_interface.h" + static void rna_userdef_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr)) { WM_main_add_notifier(NC_WINDOW, NULL); @@ -79,7 +81,9 @@ static void rna_userdef_dpi_update(Main *bmain, Scene *scene, PointerRNA *ptr) static void rna_userdef_language_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr)) { + BLF_cache_clear(); BLF_lang_set(NULL); + UI_reinit_font(); } static void rna_userdef_show_manipulator_update(Main *bmain, Scene *scene, PointerRNA *ptr) diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c index a75668280cd..c3d389932d1 100644 --- a/source/blenderplayer/bad_level_call_stubs/stubs.c +++ b/source/blenderplayer/bad_level_call_stubs/stubs.c @@ -340,6 +340,7 @@ void uiItemS(struct uiLayout *layout){} void uiItemFullR(struct uiLayout *layout, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int value, int flag, char *name, int icon){} void uiLayoutSetContextPointer(struct uiLayout *layout, char *name, struct PointerRNA *ptr){} char *uiLayoutIntrospect(struct uiLayout *layout){return (char *)NULL;} +void UI_reinit_font() {} /* rna template */ void uiTemplateAnyID(struct uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname, char *text){} -- cgit v1.2.3