Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenfont/intern/blf_font_i18n.c
| Context not available. | |||||
| #include "BKE_appdir.h" | #include "BKE_appdir.h" | ||||
| #ifdef WITH_INTERNATIONAL | typedef struct TTFFont { | ||||
| static const char unifont_filename[] = "droidsans.ttf.gz"; | const char *filename; | ||||
| static unsigned char *unifont_ttf = NULL; | unsigned char *ttf; | ||||
| static int unifont_size = 0; | int size; | ||||
| static const char unifont_mono_filename[] = "bmonofont-i18n.ttf.gz"; | } TTFFont; | ||||
| 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) | #define UNIFONT_FILENAME "droidsans.ttf.gz" | ||||
| #define UNIFONT_MONO_FILENAME "bmonofont-i18n.ttf.gz" | |||||
| static TTFFont unifont_ttf; | |||||
| static TTFFont unifont_mono_ttf; | |||||
| void BLF_load_ttf(TTFFont *ttf_font, char *filename, char *description) | |||||
| { | { | ||||
| #ifdef WITH_INTERNATIONAL | const char *fontpath = BKE_appdir_folder_id(BLENDER_DATAFILES, "fonts"); | ||||
| if (unifont_ttf == NULL) { | unsigned char *ttf = NULL; | ||||
| const char * const fontpath = BKE_appdir_folder_id(BLENDER_DATAFILES, "fonts"); | if (fontpath) { | ||||
| if (fontpath) { | char unifont_path[1024]; | ||||
| char unifont_path[1024]; | int size = 0; | ||||
| 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__); | |||||
| } | |||||
| } | |||||
| *r_unifont_size = unifont_size; | BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, filename); | ||||
| return unifont_ttf; | ttf_font->filename = filename; | ||||
| #else | ttf_font->ttf = (unsigned char *)BLI_file_ungzip_to_mem(unifont_path, &size); | ||||
| (void)r_unifont_size; | ttf_font->size = size; | ||||
| return NULL; | } | ||||
| #endif | else { | ||||
| printf("%s: 'fonts' data path not found for %s, continuing\n", __func__, description); | |||||
| } | |||||
| } | } | ||||
| void BLF_free_unifont(void) | void BLF_free_ttf(TTFFont *ttf_font) | ||||
| { | |||||
| if (ttf_font && ttf_font->ttf) { | |||||
| MEM_SAFE_FREE(ttf_font->ttf); | |||||
| ttf_font->filename = NULL; | |||||
| ttf_font->size = 0; | |||||
| } | |||||
| } | |||||
| unsigned char *BLF_get_ttf(TTFFont *ttf_font, char *filename, char *description, int *r_size) | |||||
| { | { | ||||
| BLI_assert(ttf_font); | |||||
| #ifdef WITH_INTERNATIONAL | #ifdef WITH_INTERNATIONAL | ||||
| if (unifont_ttf) | if (ttf_font->ttf == NULL) { | ||||
| MEM_freeN(unifont_ttf); | BLF_load_ttf(ttf_font, filename, description); | ||||
| } | |||||
| #else | #else | ||||
| UNUSED_VARS(filename, description); | |||||
| #endif | #endif | ||||
| *r_size = ttf_font->size; | |||||
| return ttf_font->ttf; | |||||
| } | } | ||||
| unsigned char *BLF_get_unifont_mono(int *r_unifont_size) | unsigned char *BLF_get_unifont(int *r_unifont_size) | ||||
| { | { | ||||
| #ifdef WITH_INTERNATIONAL | return BLF_get_ttf(&unifont_ttf, UNIFONT_MONO_FILENAME, "international font", r_unifont_size); | ||||
| 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; | unsigned char *BLF_get_unifont_mono(int *r_unifont_size) | ||||
| { | |||||
| return BLF_get_ttf(&unifont_mono_ttf, UNIFONT_MONO_FILENAME, "international monospace font", r_unifont_size); | |||||
| } | |||||
| return unifont_mono_ttf; | void BLF_free_unifont(void) | ||||
| #else | { | ||||
| (void)r_unifont_size; | BLF_free_ttf(&unifont_ttf); | ||||
| return NULL; | |||||
| #endif | |||||
| } | } | ||||
| void BLF_free_unifont_mono(void) | void BLF_free_unifont_mono(void) | ||||
| { | { | ||||
| #ifdef WITH_INTERNATIONAL | BLF_free_ttf(&unifont_mono_ttf); | ||||
| if (unifont_mono_ttf) | |||||
| MEM_freeN(unifont_mono_ttf); | |||||
| #else | |||||
| #endif | |||||
| } | } | ||||
| Context not available. | |||||