Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/thumbs_font.c
| Show All 26 Lines | |||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_thumbs.h" | #include "IMB_thumbs.h" | ||||
| /* XXX, bad level call */ | /* XXX, bad level call */ | ||||
| #include "../../blenfont/BLF_api.h" | #include "../../blenfont/BLF_api.h" | ||||
| #include "../../blentranslation/BLT_translation.h" | #include "../../blentranslation/BLT_translation.h" | ||||
| static const char *thumb_str[] = { | #define THUMB_TXT_ITEMS \ | ||||
| N_("AaBbCc"), | N_("AaBbCc"), N_("The quick"), N_("brown fox"), N_("jumps over"), N_("the lazy dog"), | ||||
| N_("The quick"), | static const char *thumb_str[] = {THUMB_TXT_ITEMS}; | ||||
| N_("brown fox"), | |||||
| N_("jumps over"), | static const char *i18n_thumb_str[] = {THUMB_TXT_ITEMS}; | ||||
campbellbarton: Don't think define is needed here, use `static const char *i18n_thumb_str[ARRAY_SIZE… | |||||
| N_("the lazy dog"), | |||||
| }; | #undef THUMB_TXT_ITEMS | ||||
| void IMB_thumb_clear_translations(void) | |||||
| { | |||||
| for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) { | |||||
| i18n_thumb_str[i] = NULL; | |||||
| printf("%s: clearing i18n string %d\n", __func__, i); | |||||
| } | |||||
| } | |||||
| void IMB_thumb_ensure_translations(void) | |||||
| { | |||||
| for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) { | |||||
| i18n_thumb_str[i] = BLT_translate_do(BLT_I18NCONTEXT_DEFAULT, thumb_str[i]); | |||||
| printf("%s: translated %s to %s\n", __func__, thumb_str[i], i18n_thumb_str[i]); | |||||
| } | |||||
| } | |||||
| struct ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned int y) | struct ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned int y) | ||||
| { | { | ||||
| const int font_size = y / 4; | const int font_size = y / 4; | ||||
| struct ImBuf *ibuf; | struct ImBuf *ibuf; | ||||
| float font_color[4]; | float font_color[4]; | ||||
| /* create a white image (theme color is used for drawing) */ | /* create a white image (theme color is used for drawing) */ | ||||
| font_color[0] = font_color[1] = font_color[2] = 1.0f; | font_color[0] = font_color[1] = font_color[2] = 1.0f; | ||||
| /* fill with zero alpha */ | /* fill with zero alpha */ | ||||
| font_color[3] = 0.0f; | font_color[3] = 0.0f; | ||||
| ibuf = IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata); | ibuf = IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata); | ||||
| IMB_rectfill(ibuf, font_color); | IMB_rectfill(ibuf, font_color); | ||||
| /* draw with full alpha */ | /* draw with full alpha */ | ||||
| font_color[3] = 1.0f; | font_color[3] = 1.0f; | ||||
| BLF_thumb_preview(filename, | BLF_thumb_preview(filename, | ||||
| thumb_str, | thumb_str, | ||||
| i18n_thumb_str, | |||||
| ARRAY_SIZE(thumb_str), | ARRAY_SIZE(thumb_str), | ||||
| font_color, | font_color, | ||||
| font_size, | font_size, | ||||
| (unsigned char *)ibuf->rect, | (unsigned char *)ibuf->rect, | ||||
| ibuf->x, | ibuf->x, | ||||
| ibuf->y, | ibuf->y, | ||||
| ibuf->channels); | ibuf->channels); | ||||
| Show All 9 Lines | bool IMB_thumb_load_font_get_hash(char *r_hash) | ||||
| int draw_str_lines = ARRAY_SIZE(thumb_str); | int draw_str_lines = ARRAY_SIZE(thumb_str); | ||||
| int i; | int i; | ||||
| unsigned char digest[16]; | unsigned char digest[16]; | ||||
| len += BLI_strncpy_rlen(str + len, THUMB_DEFAULT_HASH, sizeof(buf) - len); | len += BLI_strncpy_rlen(str + len, THUMB_DEFAULT_HASH, sizeof(buf) - len); | ||||
| for (i = 0; (i < draw_str_lines) && (len < sizeof(buf)); i++) { | for (i = 0; (i < draw_str_lines) && (len < sizeof(buf)); i++) { | ||||
| len += BLI_strncpy_rlen( | len += BLI_strncpy_rlen(str + len, | ||||
| str + len, BLT_translate_do(BLT_I18NCONTEXT_DEFAULT, thumb_str[i]), sizeof(buf) - len); | i18n_thumb_str[i] != NULL ? i18n_thumb_str[i] : thumb_str[i], | ||||
| sizeof(buf) - len); | |||||
| } | } | ||||
| BLI_hash_md5_buffer(str, len, digest); | BLI_hash_md5_buffer(str, len, digest); | ||||
| r_hash[0] = '\0'; | r_hash[0] = '\0'; | ||||
| BLI_hash_md5_to_hexdigest(digest, r_hash); | BLI_hash_md5_to_hexdigest(digest, r_hash); | ||||
| return true; | return true; | ||||
| } | } | ||||
Don't think define is needed here, use static const char *i18n_thumb_str[ARRAY_SIZE(thumb_str)] = {NULL}; instead.