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 20:21:27 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-06-01 20:42:56 +0300
commitbec3131112bb1f568f948e244784389523927111 (patch)
tree46a531df746d909052f1c4c4d19c6a223869a09f /source/blender/imbuf/intern/thumbs_font.c
parent2d8880643dad51f09370851248d3d6d80b5bf6d9 (diff)
Font Preview: much better handling of i18n case.
We have to regenerate previews when we change language. But we also need to do it when translation is changed or added for a language, etc. Previously, we were storing one preview per language, which was also stuffing preview dir with (potentially) tens of PNGs per font file, if user plays with translations. Now we use a better system, which is storing an additional optional metadata in previews (some hexdigest), that Blender can use in addition to datetime to decide when to regenerate previews. This is only used (and needed) by font previews so far, but can easily be reused for other types of previews if needed.
Diffstat (limited to 'source/blender/imbuf/intern/thumbs_font.c')
-rw-r--r--source/blender/imbuf/intern/thumbs_font.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/source/blender/imbuf/intern/thumbs_font.c b/source/blender/imbuf/intern/thumbs_font.c
index 7c94742a187..4b024f3c51b 100644
--- a/source/blender/imbuf/intern/thumbs_font.c
+++ b/source/blender/imbuf/intern/thumbs_font.c
@@ -25,6 +25,9 @@
*/
#include "BLI_utildefines.h"
+#include "BLI_string.h"
+#include "BLI_fileops.h"
+#include "BLI_hash_md5.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
@@ -36,18 +39,18 @@
#include "../../blenfont/BLF_api.h"
#include "../../blenfont/BLF_translation.h" /* 'N_' macro and BLF_lang_get()... */
+static const char *thumb_str[] = {
+ N_("AaBbCc"),
+
+ N_("The quick"),
+ N_("brown fox"),
+ N_("jumps over"),
+ N_("the lazy dog"),
+};
struct ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned int y)
{
const int font_size = y / 4;
- const char *thumb_str[] = {
- N_("AaBbCc"),
-
- N_("The quick"),
- N_("brown fox"),
- N_("jumps over"),
- N_("the lazy dog"),
- };
struct ImBuf *ibuf;
float font_color[4];
@@ -72,7 +75,26 @@ struct ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned
return ibuf;
}
-const char *IMB_thumb_load_font_get_language(void)
+bool IMB_thumb_load_font_get_hash(char *r_hash)
{
- return BLF_lang_get();
+ char buf[1024];
+ char *str = buf;
+ size_t len = 0;
+
+ int draw_str_lines = ARRAY_SIZE(thumb_str);
+ int i;
+
+ unsigned char digest[16];
+
+ len += BLI_strncpy_rlen(str + len, THUMB_DEFAULT_HASH, sizeof(buf) - len);
+
+ for (i = 0; (i < draw_str_lines) && (len < sizeof(buf)); i++) {
+ len += BLI_strncpy_rlen(str + len, BLF_translate_do(BLF_I18NCONTEXT_DEFAULT, thumb_str[i]), sizeof(buf) - len);
+ }
+
+ BLI_hash_md5_buffer(str, len, digest);
+ r_hash[0] = '\0';
+ BLI_hash_md5_to_hexdigest(digest, r_hash);
+
+ return true;
}