From f44b54d2a7866033025bd4e99992a72e3a27c428 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 5 Mar 2013 03:17:46 +0000 Subject: patch [#34103] from Lawrence D'Oliveiro (ldo) More use of bool type, necessitating adding inclusion of BLI_utildefines.h, or moving it up in the inclusion order if it was already included, in various places - storage.c: make some variables only used in bli_builddir local to that - storage.c: BLI_file_descriptor_size should allow 0 as a valid file descriptor - path_util.c: make pointers to non-reentrant storage returned from folder routines const, necessitating making variables holding these returned pointers const elsewhere as well - path_util.c: BLI_string_to_utf8 closes iconv context in case of conversion error - blf_lang.c: fill_locales routine now has its own "languages" local variable to construct paths (was stealing internal storage belonging to BLI_get_folder before) --- source/blender/blenfont/intern/blf_dir.c | 1 + source/blender/blenfont/intern/blf_lang.c | 9 +++++---- source/blender/blenfont/intern/blf_translation.c | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index b6a98faa48c..116a55c0579 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -41,6 +41,7 @@ #include "DNA_vec_types.h" +#include "BLI_utildefines.h" #include "BLI_fileops.h" #include "BLI_listbase.h" #include "BLI_path_util.h" diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index 73294f1aed6..d1c037b0358 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -78,15 +78,16 @@ static void free_locales(void) static void fill_locales(void) { - char *languages_path = BLI_get_folder(BLENDER_DATAFILES, "locale"); + const char * const languages_path = BLI_get_folder(BLENDER_DATAFILES, "locale"); + char languages[FILE_MAX]; LinkNode *lines = NULL, *line; char *str; int idx = 0; free_locales(); - BLI_join_dirfile(languages_path, FILE_MAX, languages_path, "languages"); - line = lines = BLI_file_read_as_lines(languages_path); + BLI_join_dirfile(languages, FILE_MAX, languages_path, "languages"); + line = lines = BLI_file_read_as_lines(languages); /* This whole "parsing" code is a bit weak, in that it expects strictly formated input file... * Should not be a problem, though, as this file is script-generated! */ @@ -185,7 +186,7 @@ EnumPropertyItem *BLF_RNA_lang_enum_properties(void) void BLF_lang_init(void) { #ifdef WITH_INTERNATIONAL - char *messagepath = BLI_get_folder(BLENDER_DATAFILES, "locale"); + const char * const messagepath = BLI_get_folder(BLENDER_DATAFILES, "locale"); if (messagepath) { bl_locale_init(messagepath, TEXT_DOMAIN_NAME); diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c index b5b72b68677..750f310fade 100644 --- a/source/blender/blenfont/intern/blf_translation.c +++ b/source/blender/blenfont/intern/blf_translation.c @@ -56,7 +56,7 @@ unsigned char *BLF_get_unifont(int *unifont_size_r) { #ifdef WITH_INTERNATIONAL if (unifont_ttf == NULL) { - char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts"); + const char * const fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts"); if (fontpath) { char unifont_path[1024]; -- cgit v1.2.3 From 589a73a43fd6d5f3e0e693117d91d150ca67de11 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 8 Mar 2013 15:34:23 +0000 Subject: Fix to BLF_pgettext, which was returning "" when passed NULL msgid... Never noticed any problem, but it looks it could produce strange UI issues (like deactivated buttons), and it was not consistent anyway! Thanks to S. Lockal for spotting the issue and providing a patch. --- source/blender/blenfont/intern/blf_translation.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c index 750f310fade..f7ad5c07d50 100644 --- a/source/blender/blenfont/intern/blf_translation.c +++ b/source/blender/blenfont/intern/blf_translation.c @@ -90,9 +90,9 @@ void BLF_free_unifont(void) const char *BLF_pgettext(const char *msgctxt, const char *msgid) { #ifdef WITH_INTERNATIONAL - if (msgid && msgid[0]) { - const char *ret; + const char *ret = msgid; + if (msgid && msgid[0]) { /*if (msgctxt && !strcmp(msgctxt, BLF_I18NCONTEXT_DEFAULT_BPY_INTERN)) { */ if (msgctxt && msgctxt[0] == BLF_I18NCONTEXT_DEFAULT_BPY[0]) { /* BLF_I18NCONTEXT_DEFAULT_BPY context is reserved and considered the same as default NULL one. */ @@ -105,10 +105,9 @@ const char *BLF_pgettext(const char *msgctxt, const char *msgid) if (ret == msgid) { ret = BPY_app_translations_py_pgettext(msgctxt, msgid); } - - return ret; } - return ""; + + return ret; #else (void)msgctxt; return msgid; -- cgit v1.2.3 From 5792e77239c43aea0afc21b2df96153ba31c5399 Mon Sep 17 00:00:00 2001 From: Irie Shinsuke Date: Tue, 12 Mar 2013 07:25:53 +0000 Subject: 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() --- source/blender/blenfont/BLF_api.h | 1 + source/blender/blenfont/BLF_translation.h | 2 ++ source/blender/blenfont/intern/blf.c | 15 ++++++++++ source/blender/blenfont/intern/blf_font.c | 34 +++++++++++++++++++++ source/blender/blenfont/intern/blf_internal.h | 1 + source/blender/blenfont/intern/blf_translation.c | 38 ++++++++++++++++++++++++ 6 files changed, 91 insertions(+) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 0ca97975d87..fd8bd196717 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -77,6 +77,7 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l /* Draw the string using the current font. */ void BLF_draw(int fontid, const char *str, size_t len); void BLF_draw_ascii(int fontid, const char *str, size_t len); +int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth); /* This function return the bounding box of the string * and are not multiplied by the aspect. diff --git a/source/blender/blenfont/BLF_translation.h b/source/blender/blenfont/BLF_translation.h index cbfc7c28d8d..2f40cc3f571 100644 --- a/source/blender/blenfont/BLF_translation.h +++ b/source/blender/blenfont/BLF_translation.h @@ -68,6 +68,8 @@ struct EnumPropertyItem *BLF_RNA_lang_enum_properties(void); unsigned char *BLF_get_unifont(int *unifont_size); void BLF_free_unifont(void); +unsigned char *BLF_get_unifont_mono(int *unifont_size); +void BLF_free_unifont_mono(void); const char *BLF_pgettext(const char *msgctxt, const char *msgid); diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 061e8e28607..e7e277b7b34 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -576,6 +576,21 @@ void BLF_draw_ascii(int fontid, const char *str, size_t len) } } +int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth) +{ + FontBLF *font = blf_get(fontid); + GLint mode, param; + int columns = 0; + + if (font && font->glyph_cache) { + blf_draw__start(font, &mode, ¶m); + columns = blf_font_draw_mono(font, str, len, cwidth); + blf_draw__end(mode, param); + } + + return columns; +} + void BLF_boundbox(int fontid, const char *str, rctf *box) { FontBLF *font = blf_get(fontid); diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 1900efa2dbc..f2c36475870 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -219,6 +219,40 @@ void blf_font_draw_ascii(FontBLF *font, const char *str, size_t len) } } +/* use fixed column width, but an utf8 character may occupy multiple columns */ +int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth) +{ + unsigned int c; + GlyphBLF *g; + int col, columns = 0; + int pen_x = 0, pen_y = 0; + size_t i = 0; + GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table; + + blf_font_ensure_ascii_table(font); + + while ((i < len) && str[i]) { + BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); + + if (c == BLI_UTF8_ERR) + break; + if (g == NULL) + continue; + + /* do not return this loop if clipped, we want every character tested */ + blf_glyph_render(font, g, (float)pen_x, (float)pen_y); + + col = BLI_wcwidth((wchar_t)c); + if (col < 0) + col = 1; + + columns += col; + pen_x += cwidth * col; + } + + return columns; +} + /* Sanity checks are done by BLF_draw_buffer() */ void blf_font_buffer(FontBLF *font, const char *str) { diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 65a54783978..b1301be46fd 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -53,6 +53,7 @@ void blf_font_attach_from_mem(struct FontBLF *font, const unsigned char *mem, in void blf_font_size(struct FontBLF *font, int size, int dpi); void blf_font_draw(struct FontBLF *font, const char *str, size_t len); void blf_font_draw_ascii(struct FontBLF *font, const char *str, size_t len); +int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t len, int cwidth); void blf_font_buffer(struct FontBLF *font, const char *str); void blf_font_boundbox(struct FontBLF *font, const char *str, struct rctf *box); void blf_font_width_and_height(struct FontBLF *font, const char *str, float *width, float *height); diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c index f7ad5c07d50..3284225c457 100644 --- a/source/blender/blenfont/intern/blf_translation.c +++ b/source/blender/blenfont/intern/blf_translation.c @@ -50,6 +50,9 @@ static const char unifont_filename[] = "droidsans.ttf.gz"; static unsigned char *unifont_ttf = NULL; static int unifont_size = 0; +static const char unifont_mono_filename[] = "bmonofont-i18n.ttf.gz"; +static unsigned char *unifont_mono_ttf = NULL; +static int unifont_mono_size = 0; #endif /* WITH_INTERNATIONAL */ unsigned char *BLF_get_unifont(int *unifont_size_r) @@ -87,6 +90,41 @@ void BLF_free_unifont(void) #endif } +unsigned char *BLF_get_unifont_mono(int *unifont_size_r) +{ +#ifdef WITH_INTERNATIONAL + if(unifont_mono_ttf == NULL) { + char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts"); + if (fontpath) { + char unifont_path[1024]; + + BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_mono_filename); + + unifont_mono_ttf = (unsigned char*)BLI_file_ungzip_to_mem(unifont_path, &unifont_mono_size); + } + else { + printf("%s: 'fonts' data path not found for international monospace font, continuing\n", __func__); + } + } + + *unifont_size_r = unifont_mono_size; + + return unifont_mono_ttf; +#else + (void)unifont_size_r; + return NULL; +#endif +} + +void BLF_free_unifont_mono(void) +{ +#ifdef WITH_INTERNATIONAL + if(unifont_mono_ttf) + MEM_freeN(unifont_mono_ttf); +#else +#endif +} + const char *BLF_pgettext(const char *msgctxt, const char *msgid) { #ifdef WITH_INTERNATIONAL -- cgit v1.2.3 From e84153a91ccd05548fb718eb612dc6155b3873c9 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 12 Mar 2013 08:24:36 +0000 Subject: Fix compilation error after recent changes to strict gcc flags Dudes, please try building blender with all default features before doing such a commits. It helps just a lot when bisecting issues later. Also solved const qualifier discard happens in recent monofont commit. --- source/blender/blenfont/intern/blf_translation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c index 3284225c457..236ea89a584 100644 --- a/source/blender/blenfont/intern/blf_translation.c +++ b/source/blender/blenfont/intern/blf_translation.c @@ -94,7 +94,7 @@ unsigned char *BLF_get_unifont_mono(int *unifont_size_r) { #ifdef WITH_INTERNATIONAL if(unifont_mono_ttf == NULL) { - char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts"); + const char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts"); if (fontpath) { char unifont_path[1024]; -- cgit v1.2.3 From 153b63e0fde21730cd54f16a501c18c793256ae2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 12 Mar 2013 21:46:33 +0000 Subject: style cleanup --- source/blender/blenfont/intern/blf_translation.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c index 236ea89a584..2483c59d3ec 100644 --- a/source/blender/blenfont/intern/blf_translation.c +++ b/source/blender/blenfont/intern/blf_translation.c @@ -93,14 +93,14 @@ void BLF_free_unifont(void) unsigned char *BLF_get_unifont_mono(int *unifont_size_r) { #ifdef WITH_INTERNATIONAL - if(unifont_mono_ttf == NULL) { + if (unifont_mono_ttf == NULL) { const char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts"); if (fontpath) { char unifont_path[1024]; BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_mono_filename); - unifont_mono_ttf = (unsigned char*)BLI_file_ungzip_to_mem(unifont_path, &unifont_mono_size); + unifont_mono_ttf = (unsigned char *)BLI_file_ungzip_to_mem(unifont_path, &unifont_mono_size); } else { printf("%s: 'fonts' data path not found for international monospace font, continuing\n", __func__); @@ -119,7 +119,7 @@ unsigned char *BLF_get_unifont_mono(int *unifont_size_r) void BLF_free_unifont_mono(void) { #ifdef WITH_INTERNATIONAL - if(unifont_mono_ttf) + if (unifont_mono_ttf) MEM_freeN(unifont_mono_ttf); #else #endif -- cgit v1.2.3 From 284e59d608a90589956780fe1dd81ecc2ba11362 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 15 Mar 2013 14:32:29 +0000 Subject: Add the possibility to define the translation context for py rna classes (operators, panels and menus). Thanks to Campell and Brecht for the reviews! --- source/blender/blenfont/BLF_translation.h | 2 ++ source/blender/blenfont/intern/blf_translation.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/BLF_translation.h b/source/blender/blenfont/BLF_translation.h index 2f40cc3f571..db449995b8f 100644 --- a/source/blender/blenfont/BLF_translation.h +++ b/source/blender/blenfont/BLF_translation.h @@ -110,12 +110,14 @@ const char *BLF_translate_do_tooltip(const char *msgctxt, const char *msgid); * All i18n contexts must be defined here. * This is a nice way to be sure not to use a context twice for different * things, and limit the number of existing contexts! + * WARNING! Contexts should not be longer than BKE_ST_MAXNAME - 1! */ /* Default, void context. * WARNING! The "" context is not the same as no (NULL) context at mo/boost::locale level! * NOTE: We translate BLF_I18NCONTEXT_DEFAULT as BLF_I18NCONTEXT_DEFAULT_BPY in Python, as we can't use "natural" * None value in rna string properties... :/ + * The void string "" is also interpreted as BLF_I18NCONTEXT_DEFAULT. * For perf reason, we only use the first char to detect this context, so other contexts should never start * with the same char! */ diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c index 2483c59d3ec..4e9408c512a 100644 --- a/source/blender/blenfont/intern/blf_translation.c +++ b/source/blender/blenfont/intern/blf_translation.c @@ -132,7 +132,7 @@ const char *BLF_pgettext(const char *msgctxt, const char *msgid) if (msgid && msgid[0]) { /*if (msgctxt && !strcmp(msgctxt, BLF_I18NCONTEXT_DEFAULT_BPY_INTERN)) { */ - if (msgctxt && msgctxt[0] == BLF_I18NCONTEXT_DEFAULT_BPY[0]) { + if (msgctxt && (!msgctxt[0] || msgctxt[0] == BLF_I18NCONTEXT_DEFAULT_BPY[0])) { /* BLF_I18NCONTEXT_DEFAULT_BPY context is reserved and considered the same as default NULL one. */ msgctxt = BLF_I18NCONTEXT_DEFAULT; } -- cgit v1.2.3