2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* The Original Code is Copyright (C) 2011 Blender Foundation.
19
* All rights reserved.
21
* Contributor(s): Blender Foundation,
24
* ***** END GPL LICENSE BLOCK *****
27
/** \file blender/blenfont/intern/blf_translation.c
34
#ifdef WITH_INTERNATIONAL
38
#define GETTEXT_CONTEXT_GLUE "\004"
40
/* needed for windows version of gettext */
42
# define LC_MESSAGES 1729
47
#include "MEM_guardedalloc.h"
49
#include "BLI_utildefines.h"
50
#include "BLI_path_util.h"
51
#include "BLI_string.h"
52
#include "BLI_path_util.h"
53
#include "BLI_fileops.h"
55
#include "BLF_translation.h"
57
#include "DNA_userdef_types.h" /* For user settings. */
59
#ifdef WITH_INTERNATIONAL
60
#ifdef WITH_FONTCONFIG
61
#include <fontconfig/fontconfig.h>
63
static const char unifont_filename[] ="droidsans.ttf.gz";
65
static unsigned char *unifont_ttf = NULL;
66
static int unifont_size = 0;
68
unsigned char *BLF_get_unifont(int *unifont_size_r)
70
if (unifont_ttf == NULL) {
71
#ifdef WITH_FONTCONFIG
72
FcFontSet *fontset = NULL;
74
FcPattern *pattern = FcPatternBuild (0, FC_FAMILY, FcTypeString, "Droid Sans",FC_STYLE, FcTypeString, "Regular", (char *) 0);
75
fontset = FcFontList(0,pattern,0);
76
if (fontset->nfont > 0) {
77
//get the file of the first font in the fontset that match pattern
78
FcPatternGet(fontset->fonts[0], FC_FILE, 0, &v);
79
//load the file stored in the union of FcValue into memory
80
unifont_ttf = (unsigned char*)BLI_file_to_mem(
86
printf("%s: 'Droid Sans Regular' font not found with fontconfig\n",__func__);
89
char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts");
91
char unifont_path[1024];
93
BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_filename);
95
unifont_ttf = (unsigned char*)BLI_file_ungzip_to_mem(unifont_path, &unifont_size);
98
printf("%s: 'fonts' data path not found for international font, continuing\n", __func__);
103
*unifont_size_r = unifont_size;
108
void BLF_free_unifont(void)
111
MEM_freeN(unifont_ttf);
116
const char* BLF_gettext(const char *msgid)
118
#ifdef WITH_INTERNATIONAL
119
if (msgid && msgid[0])
120
return gettext(msgid);
127
const char *BLF_pgettext(const char *context, const char *message)
129
#ifdef WITH_INTERNATIONAL
130
char static_msg_ctxt_id[1024];
131
char *dynamic_msg_ctxt_id = NULL;
133
const char *translation;
135
size_t overall_length = strlen(context) + strlen(message) + sizeof(GETTEXT_CONTEXT_GLUE) + 1;
137
if (!message || !context || !message[0])
140
if (overall_length > sizeof(static_msg_ctxt_id)) {
141
dynamic_msg_ctxt_id = malloc(overall_length);
142
msg_ctxt_id = dynamic_msg_ctxt_id;
145
msg_ctxt_id = static_msg_ctxt_id;
148
sprintf(msg_ctxt_id, "%s%s%s", context, GETTEXT_CONTEXT_GLUE, message);
150
translation = (char*)dcgettext(TEXT_DOMAIN_NAME, msg_ctxt_id, LC_MESSAGES);
152
if (dynamic_msg_ctxt_id)
153
free(dynamic_msg_ctxt_id);
155
if (translation == msg_ctxt_id)
156
translation = message;
165
int BLF_translate_iface(void)
167
#ifdef WITH_INTERNATIONAL
168
return (U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_IFACE);
174
int BLF_translate_tooltips(void)
176
#ifdef WITH_INTERNATIONAL
177
return (U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_TOOLTIPS);
183
const char *BLF_translate_do_iface(const char *context, const char *msgid)
185
#ifdef WITH_INTERNATIONAL
186
if (BLF_translate_iface()) {
188
return BLF_pgettext(context, msgid);
190
return BLF_gettext(msgid);
200
const char *BLF_translate_do_tooltip(const char *context, const char *msgid)
202
#ifdef WITH_INTERNATIONAL
203
if (BLF_translate_tooltips()) {
205
return BLF_pgettext(context, msgid);
207
return BLF_gettext(msgid);