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:
authorHarley Acheson <harley.acheson@gmail.com>2022-09-24 20:55:46 +0300
committerHarley Acheson <harley.acheson@gmail.com>2022-09-24 20:57:34 +0300
commit4e7983e0732015d9fe52ecd12e203a230b30af16 (patch)
tree9bab0be140084c783ba930bf819996eed0bb1832 /source/blender/imbuf
parent2ff5d42cd3b41cc1412d4a896d8f9e8d2977686f (diff)
UI: Improved Font Thumbnails
Thumbnails of fonts that better show design, shapes, contents, intent, and intended language. Previews almost every known language - living and dead - and symbol, specialty fonts, etc. See D12032 for more details and samples. Differential Revision: https://developer.blender.org/D12032 Reviewed by Campbell Barton
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/IMB_thumbs.h2
-rw-r--r--source/blender/imbuf/intern/thumbs_font.c84
2 files changed, 15 insertions, 71 deletions
diff --git a/source/blender/imbuf/IMB_thumbs.h b/source/blender/imbuf/IMB_thumbs.h
index b55a6f653b8..ac287856fa9 100644
--- a/source/blender/imbuf/IMB_thumbs.h
+++ b/source/blender/imbuf/IMB_thumbs.h
@@ -87,8 +87,6 @@ struct ImBuf *IMB_thumb_load_blend(const char *blen_path,
*/
struct ImBuf *IMB_thumb_load_font(const char *filepath, unsigned int x, unsigned int y);
bool IMB_thumb_load_font_get_hash(char *r_hash);
-void IMB_thumb_clear_translations(void);
-void IMB_thumb_ensure_translations(void);
/* Threading */
diff --git a/source/blender/imbuf/intern/thumbs_font.c b/source/blender/imbuf/intern/thumbs_font.c
index 65848bfb55e..0f18e9dd4cb 100644
--- a/source/blender/imbuf/intern/thumbs_font.c
+++ b/source/blender/imbuf/intern/thumbs_font.c
@@ -6,94 +6,40 @@
#include "BLI_fileops.h"
#include "BLI_hash_md5.h"
-#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
-#include "IMB_thumbs.h"
+#include "IMB_thumbs.h" /* own include. */
/* XXX, bad level call */
#include "../../blenfont/BLF_api.h"
-#include "../../blentranslation/BLT_translation.h"
-#define THUMB_TXT_ITEMS \
- N_("AaBbCc"), N_("The quick"), N_("brown fox"), N_("jumps over"), N_("the lazy dog"),
+/* Only change if we need to update the previews in the on-disk cache. */
+#define FONT_THUMB_VERSION "1.0.0"
-static const char *thumb_str[] = {THUMB_TXT_ITEMS};
-
-static const char *i18n_thumb_str[] = {THUMB_TXT_ITEMS};
-
-#undef THUMB_TXT_ITEMS
-
-void IMB_thumb_clear_translations(void)
-{
- for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) {
- i18n_thumb_str[i] = NULL;
- }
-}
-
-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]);
- }
-}
-
-struct ImBuf *IMB_thumb_load_font(const char *filepath, uint x, uint y)
+struct ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned int y)
{
- const int font_size = y / 4;
+ struct ImBuf *ibuf = IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata);
- struct ImBuf *ibuf;
- float font_color[4];
+ /* fill with white and zero alpha */
+ const float col[4] = {1.0f, 1.0f, 1.0f, 0.0f};
+ IMB_rectfill(ibuf, col);
- /* create a white image (theme color is used for drawing) */
- font_color[0] = font_color[1] = font_color[2] = 1.0f;
-
- /* fill with zero alpha */
- font_color[3] = 0.0f;
-
- ibuf = IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata);
- IMB_rectfill(ibuf, font_color);
-
- /* draw with full alpha */
- font_color[3] = 1.0f;
-
- BLF_thumb_preview(filepath,
- thumb_str,
- i18n_thumb_str,
- ARRAY_SIZE(thumb_str),
- font_color,
- font_size,
- (uchar *)ibuf->rect,
- ibuf->x,
- ibuf->y,
- ibuf->channels);
+ if (!BLF_thumb_preview(
+ filename, (unsigned char *)ibuf->rect, ibuf->x, ibuf->y, ibuf->channels)) {
+ IMB_freeImBuf(ibuf);
+ ibuf = NULL;
+ }
return ibuf;
}
bool IMB_thumb_load_font_get_hash(char *r_hash)
{
- char buf[1024];
- char *str = buf;
- size_t len = 0;
-
- int draw_str_lines = ARRAY_SIZE(thumb_str);
- int i;
-
- uchar 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,
- i18n_thumb_str[i] != NULL ? i18n_thumb_str[i] : thumb_str[i],
- sizeof(buf) - len);
- }
-
- BLI_hash_md5_buffer(str, len, digest);
+ unsigned char digest[16];
+ BLI_hash_md5_buffer(FONT_THUMB_VERSION, sizeof(FONT_THUMB_VERSION), digest);
r_hash[0] = '\0';
BLI_hash_md5_to_hexdigest(digest, r_hash);