diff options
author | Irie Shinsuke <irieshinsuke@yahoo.co.jp> | 2013-03-12 11:25:53 +0400 |
---|---|---|
committer | Irie Shinsuke <irieshinsuke@yahoo.co.jp> | 2013-03-12 11:25:53 +0400 |
commit | 5792e77239c43aea0afc21b2df96153ba31c5399 (patch) | |
tree | 47eb20f56f932f984800329781f2e75e38e7eb78 /source/blender/editors/interface | |
parent | 6669ee4784ac6591711298eb01f8e0b06793c60a (diff) |
Patch [#34373] Use i18n monospace font in Text editor and Python console
This patch allows Blender to display i18n monospace font in the text
editor and the Python interactive console. Wide characters that occupy
multiple columns such as CJK characters can be displayed correctly.
Furthermore, wrapping, selection, suggestion, cursor drawing, and
syntax highlighting should work.
Also fixes a bug [#34543]: In Text Editor false color in comment on cyrillic
To estimate how many columns each character occupies, this patch uses
wcwidth.c written by Markus Kuhn and distributed under MIT-style license:
http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
wcwidth.c is stored in extern/wcwidth and used as a static library.
This patch adds new API to blenfont, blenlib and blenkernel:
BLF_get_unifont_mono()
BLF_free_unifont_mono()
BLF_draw_mono()
BLI_wcwidth()
BLI_wcswidth()
BLI_str_utf8_char_width()
BLI_str_utf8_char_width_safe()
txt_utf8_offset_to_column()
txt_utf8_column_to_offset()
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface_style.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 3cd7499c78e..03805dd0ef8 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -330,6 +330,8 @@ void uiStyleInit(void) { uiFont *font = U.uifonts.first; uiStyle *style = U.uistyles.first; + int monofont_size = datatoc_bmonofont_ttf_size; + unsigned char *monofont_ttf = (unsigned char*)datatoc_bmonofont_ttf; /* recover from uninitialized dpi */ if (U.dpi == 0) @@ -400,15 +402,33 @@ void uiStyleInit(void) ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT); } +#ifdef WITH_INTERNATIONAL + /* use unicode font for text editor and interactive console */ + if (U.transopts & USER_DOTRANSLATE) { + monofont_ttf = BLF_get_unifont_mono(&monofont_size); + + if (!monofont_ttf) { + /* fall back if not found */ + monofont_size = datatoc_bmonofont_ttf_size; + monofont_ttf = (unsigned char*)datatoc_bmonofont_ttf; + } + } + + /* reload */ + BLF_unload("monospace"); + blf_mono_font = -1; + blf_mono_font_render = -1; +#endif + /* 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); + blf_mono_font = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); BLF_size(blf_mono_font, 12 * U.pixelsize, 72); /* second for rendering else we get threading problems */ if (blf_mono_font_render == -1) - blf_mono_font_render = BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); + blf_mono_font_render = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); BLF_size(blf_mono_font_render, 12 * U.pixelsize, 72 ); } |