~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/blenfont/intern/blf_translation.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
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. 
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 * The Original Code is Copyright (C) 2011 Blender Foundation.
 
19
 * All rights reserved.
 
20
 *
 
21
 * Contributor(s): Blender Foundation,
 
22
 *                 Sergey Sharybin
 
23
 *
 
24
 * ***** END GPL LICENSE BLOCK *****
 
25
 */
 
26
 
 
27
/** \file blender/blenfont/intern/blf_translation.c
 
28
 *  \ingroup blf
 
29
 */
 
30
 
 
31
#include <stdlib.h>
 
32
#include <string.h>
 
33
 
 
34
#ifdef WITH_INTERNATIONAL
 
35
#include <libintl.h>
 
36
#include <locale.h>
 
37
 
 
38
#define GETTEXT_CONTEXT_GLUE "\004"
 
39
 
 
40
/* needed for windows version of gettext */
 
41
#ifndef LC_MESSAGES
 
42
#       define LC_MESSAGES 1729
 
43
#endif
 
44
 
 
45
#endif
 
46
 
 
47
#include "MEM_guardedalloc.h"
 
48
 
 
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"
 
54
 
 
55
#include "BLF_translation.h"
 
56
 
 
57
#include "DNA_userdef_types.h" /* For user settings. */
 
58
 
 
59
#ifdef WITH_INTERNATIONAL
 
60
#ifdef WITH_FONTCONFIG
 
61
#include <fontconfig/fontconfig.h>
 
62
#else
 
63
static const char unifont_filename[] ="droidsans.ttf.gz";
 
64
#endif
 
65
static unsigned char *unifont_ttf = NULL;
 
66
static int unifont_size = 0;
 
67
 
 
68
unsigned char *BLF_get_unifont(int *unifont_size_r)
 
69
{
 
70
        if (unifont_ttf == NULL) {
 
71
#ifdef WITH_FONTCONFIG
 
72
                FcFontSet *fontset = NULL;
 
73
                FcValue v;
 
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(
 
81
                                (const char *)v.u.s,
 
82
                                &unifont_size
 
83
                        );
 
84
                }
 
85
                else {
 
86
                        printf("%s: 'Droid Sans Regular' font not found with fontconfig\n",__func__);
 
87
                }
 
88
#else
 
89
                char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts");
 
90
                if (fontpath) {
 
91
                        char unifont_path[1024];
 
92
 
 
93
                        BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_filename);
 
94
 
 
95
                        unifont_ttf = (unsigned char*)BLI_file_ungzip_to_mem(unifont_path, &unifont_size);
 
96
                }
 
97
                else {
 
98
                        printf("%s: 'fonts' data path not found for international font, continuing\n", __func__);
 
99
                }
 
100
#endif
 
101
        }
 
102
 
 
103
        *unifont_size_r = unifont_size;
 
104
 
 
105
        return unifont_ttf;
 
106
}
 
107
 
 
108
void BLF_free_unifont(void)
 
109
{
 
110
        if (unifont_ttf)
 
111
                MEM_freeN(unifont_ttf);
 
112
}
 
113
 
 
114
#endif
 
115
 
 
116
const char* BLF_gettext(const char *msgid)
 
117
{
 
118
#ifdef WITH_INTERNATIONAL
 
119
        if (msgid && msgid[0])
 
120
                return gettext(msgid);
 
121
        return "";
 
122
#else
 
123
        return msgid;
 
124
#endif
 
125
}
 
126
 
 
127
const char *BLF_pgettext(const char *context, const char *message)
 
128
{
 
129
#ifdef WITH_INTERNATIONAL
 
130
        char static_msg_ctxt_id[1024];
 
131
        char *dynamic_msg_ctxt_id = NULL;
 
132
        char *msg_ctxt_id;
 
133
        const char *translation;
 
134
 
 
135
        size_t overall_length = strlen(context) + strlen(message) + sizeof(GETTEXT_CONTEXT_GLUE) + 1;
 
136
 
 
137
        if (!message || !context || !message[0])
 
138
                return "";
 
139
 
 
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;
 
143
        }
 
144
        else {
 
145
                msg_ctxt_id = static_msg_ctxt_id;
 
146
        }
 
147
 
 
148
        sprintf(msg_ctxt_id, "%s%s%s", context, GETTEXT_CONTEXT_GLUE, message);
 
149
 
 
150
        translation = (char*)dcgettext(TEXT_DOMAIN_NAME, msg_ctxt_id, LC_MESSAGES);
 
151
 
 
152
        if (dynamic_msg_ctxt_id)
 
153
                free(dynamic_msg_ctxt_id);
 
154
 
 
155
        if (translation == msg_ctxt_id)
 
156
                translation = message;
 
157
 
 
158
        return translation;
 
159
#else
 
160
        (void)context;
 
161
        return message;
 
162
#endif
 
163
}
 
164
 
 
165
int BLF_translate_iface(void)
 
166
{
 
167
#ifdef WITH_INTERNATIONAL
 
168
        return (U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_IFACE);
 
169
#else
 
170
        return 0;
 
171
#endif
 
172
}
 
173
 
 
174
int BLF_translate_tooltips(void)
 
175
{
 
176
#ifdef WITH_INTERNATIONAL
 
177
        return (U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_TOOLTIPS);
 
178
#else
 
179
        return 0;
 
180
#endif
 
181
}
 
182
 
 
183
const char *BLF_translate_do_iface(const char *context, const char *msgid)
 
184
{
 
185
#ifdef WITH_INTERNATIONAL
 
186
        if (BLF_translate_iface()) {
 
187
                if (context)
 
188
                        return BLF_pgettext(context, msgid);
 
189
                else
 
190
                        return BLF_gettext(msgid);
 
191
        }
 
192
        else
 
193
                return msgid;
 
194
#else
 
195
        (void)context;
 
196
        return msgid;
 
197
#endif
 
198
}
 
199
 
 
200
const char *BLF_translate_do_tooltip(const char *context, const char *msgid)
 
201
{
 
202
#ifdef WITH_INTERNATIONAL
 
203
        if (BLF_translate_tooltips()) {
 
204
                if (context)
 
205
                        return BLF_pgettext(context, msgid);
 
206
                else
 
207
                        return BLF_gettext(msgid);
 
208
        }
 
209
        else
 
210
                return msgid;
 
211
#else
 
212
        (void)context;
 
213
        return msgid;
 
214
#endif
 
215
}