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:
authorCampbell Barton <ideasman42@gmail.com>2019-01-22 05:51:21 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-01-22 05:51:21 +0300
commit88218946da3b6fff7dd4b6779f1a23885bf89a4e (patch)
treea559a4d84e558f9a1899ea342023121e6505bdd4 /source/blender/blenfont
parentb4aec5200773cc65f5b4123a6e1511d93c328107 (diff)
Cleanup: minor changes to reduce code duplication
D4236 by @sobakasu w/ edits.
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r--source/blender/blenfont/intern/blf_font_i18n.c103
1 files changed, 51 insertions, 52 deletions
diff --git a/source/blender/blenfont/intern/blf_font_i18n.c b/source/blender/blenfont/intern/blf_font_i18n.c
index b6ff7ed865a..e88accdad6a 100644
--- a/source/blender/blenfont/intern/blf_font_i18n.c
+++ b/source/blender/blenfont/intern/blf_font_i18n.c
@@ -45,80 +45,79 @@
#include "BKE_appdir.h"
#ifdef WITH_INTERNATIONAL
-static const char unifont_filename[] = "droidsans.ttf.gz";
-static unsigned char *unifont_ttf = NULL;
-static int unifont_size = 0;
-static const char unifont_mono_filename[] = "bmonofont-i18n.ttf.gz";
-static unsigned char *unifont_mono_ttf = NULL;
-static int unifont_mono_size = 0;
-#endif /* WITH_INTERNATIONAL */
-
-unsigned char *BLF_get_unifont(int *r_unifont_size)
+
+struct FontBuf {
+ const char *filename;
+ uchar *data;
+ int data_len;
+};
+
+static struct FontBuf unifont_ttf = {"droidsans.ttf.gz"};
+static struct FontBuf unifont_mono_ttf = {"bmonofont-i18n.ttf.gz"};
+
+static void fontbuf_load(struct FontBuf *fb)
{
-#ifdef WITH_INTERNATIONAL
- if (unifont_ttf == NULL) {
- const char * const fontpath = BKE_appdir_folder_id(BLENDER_DATAFILES, "fonts");
- if (fontpath) {
- char unifont_path[1024];
-
- BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_filename);
-
- unifont_ttf = (unsigned char *)BLI_file_ungzip_to_mem(unifont_path, &unifont_size);
- }
- else {
- printf("%s: 'fonts' data path not found for international font, continuing\n", __func__);
- }
+ const char *fontpath = BKE_appdir_folder_id(BLENDER_DATAFILES, "fonts");
+ uchar *data = NULL;
+ if (fontpath) {
+ char unifont_path[1024];
+ BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, fb->filename);
+ fb->data = (uchar *)BLI_file_ungzip_to_mem(unifont_path, &fb->data_len);
+
+ }
+ else {
+ printf("%s: 'fonts' data path not found for '%s', continuing\n", __func__, fb->filename);
+ }
+}
+
+static void fontbuf_free(struct FontBuf *fb)
+{
+ MEM_SAFE_FREE(fb->data);
+ fb->data_len = 0;
+}
+
+static uchar *fontbuf_get_mem(struct FontBuf *fb, int *r_size)
+{
+ if (fb->data == NULL) {
+ fontbuf_load(fb);
}
+ *r_size = fb->data_len;
+ return fb->data;
+}
+
+#endif /* WITH_INTERNATIONAL */
- *r_unifont_size = unifont_size;
- return unifont_ttf;
+uchar *BLF_get_unifont(int *r_unifont_size)
+{
+#ifdef WITH_INTERNATIONAL
+ return fontbuf_get_mem(&unifont_ttf, r_unifont_size);
#else
- (void)r_unifont_size;
+ UNUSED_VARS(r_unifont_size);
return NULL;
#endif
}
-void BLF_free_unifont(void)
+uchar *BLF_get_unifont_mono(int *r_unifont_size)
{
#ifdef WITH_INTERNATIONAL
- if (unifont_ttf)
- MEM_freeN(unifont_ttf);
+ return fontbuf_get_mem(&unifont_mono_ttf, r_unifont_size);
#else
+ UNUSED_VARS(r_unifont_size);
+ return NULL;
#endif
}
-unsigned char *BLF_get_unifont_mono(int *r_unifont_size)
+void BLF_free_unifont(void)
{
#ifdef WITH_INTERNATIONAL
- if (unifont_mono_ttf == NULL) {
- const char *fontpath = BKE_appdir_folder_id(BLENDER_DATAFILES, "fonts");
- if (fontpath) {
- char unifont_path[1024];
-
- BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_mono_filename);
-
- unifont_mono_ttf = (unsigned char *)BLI_file_ungzip_to_mem(unifont_path, &unifont_mono_size);
- }
- else {
- printf("%s: 'fonts' data path not found for international monospace font, continuing\n", __func__);
- }
- }
-
- *r_unifont_size = unifont_mono_size;
-
- return unifont_mono_ttf;
-#else
- (void)r_unifont_size;
- return NULL;
+ fontbuf_free(&unifont_ttf);
#endif
}
void BLF_free_unifont_mono(void)
{
#ifdef WITH_INTERNATIONAL
- if (unifont_mono_ttf)
- MEM_freeN(unifont_mono_ttf);
-#else
+ fontbuf_free(&unifont_mono_ttf);
#endif
}