Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-06-01 18:12:56 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-06-01 20:42:56 +0300
commit2d8880643dad51f09370851248d3d6d80b5bf6d9 (patch)
treecf9529064c9cebad1b7013ecc8f3c0983cf27b44 /source/blender/blenfont/intern/blf_thumbs.c
parent7173069cbe76b69b5800cee91a25cee6cb2a9586 (diff)
Font Preview: fallback to default english strings in case translated ones have not enough chars in current font.
This avoids some ugly 'missing char' in previews - not all cases of course, but most common ones. A complete solution would be much much more involved, and probably not worth it here. Definitively not before a release, at least!
Diffstat (limited to 'source/blender/blenfont/intern/blf_thumbs.c')
-rw-r--r--source/blender/blenfont/intern/blf_thumbs.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c
index 7c0a43e09ee..4b7a568b8b0 100644
--- a/source/blender/blenfont/intern/blf_thumbs.c
+++ b/source/blender/blenfont/intern/blf_thumbs.c
@@ -90,6 +90,10 @@ void BLF_thumb_preview(
font_size_curr = font_size;
for (i = 0; i < draw_str_lines; i++) {
+ const char *draw_str_i18n = BLF_translate_do(BLF_I18NCONTEXT_DEFAULT, draw_str[i]);
+ const size_t draw_str_i18n_len = strlen(draw_str_i18n);
+ int draw_str_i18n_nbr = 0;
+
blf_font_size(font, (unsigned int)MAX2(font_size_min, font_size_curr), dpi);
/* decrease font size each time */
@@ -98,7 +102,19 @@ void BLF_thumb_preview(
font->pos[1] -= font->glyph_cache->ascender * 1.1f;
- blf_font_buffer(font, BLF_translate_do(BLF_I18NCONTEXT_DEFAULT, draw_str[i]));
+ /* We fallback to default english strings in case not enough chars are available in current font for given
+ * translated string (useful in non-latin i18n context, like chinese, since many fonts will then show
+ * nothing but ugly 'missing char' in their preview).
+ * Does not handle all cases, but much better than nothing.
+ */
+ if (blf_font_count_missing_chars(
+ font, draw_str_i18n, draw_str_i18n_len, &draw_str_i18n_nbr) > (draw_str_i18n_nbr / 2))
+ {
+ blf_font_buffer(font, draw_str[i]);
+ }
+ else {
+ blf_font_buffer(font, draw_str_i18n);
+ }
}
blf_font_free(font);