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

thumbs_font.c « intern « imbuf « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0a33f608a5b07906305789ff5a8efe1a8313203 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup imbuf
 */

#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"

/* 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"),

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, unsigned int x, unsigned int y)
{
  const int font_size = y / 4;

  struct ImBuf *ibuf;
  float font_color[4];

  /* 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,
                    (unsigned char *)ibuf->rect,
                    ibuf->x,
                    ibuf->y,
                    ibuf->channels);

  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;

  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,
                            i18n_thumb_str[i] != NULL ? i18n_thumb_str[i] : 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;
}