diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-01-27 03:49:13 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-01-27 03:49:13 +0400 |
commit | 556912792ad3c37c294256a558c96b39f264e7b5 (patch) | |
tree | 9b6ee8cf1ad92ee89c04f27a89be11599c5b40c0 /source/blender/blenfont | |
parent | 9251d628db0abe599d927d79170025d8545c8ace (diff) | |
parent | c84383301c5a2582e95259a7e4468a23a3566401 (diff) |
Merged changes in the trunk up to revision 54110.
Conflicts resolved:
source/blender/blenfont/SConscript
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/makesdna/intern/makesdna.c
source/blender/makesrna/intern/rna_scene.c
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r-- | source/blender/blenfont/BLF_api.h | 1 | ||||
-rw-r--r-- | source/blender/blenfont/BLF_translation.h | 93 | ||||
-rw-r--r-- | source/blender/blenfont/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/blenfont/SConscript | 4 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_glyph.c | 6 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_lang.c | 127 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_translation.c | 50 |
7 files changed, 209 insertions, 73 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 25b55eacd77..0ca97975d87 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -183,6 +183,7 @@ void BLF_dir_free(char **dirs, int count); #define BLF_KERNING_DEFAULT (1 << 3) #define BLF_MATRIX (1 << 4) #define BLF_ASPECT (1 << 5) +#define BLF_HINTING (1 << 6) #define BLF_DRAW_STR_DUMMY_MAX 1024 diff --git a/source/blender/blenfont/BLF_translation.h b/source/blender/blenfont/BLF_translation.h index 9a2789d36cc..5b2c4e87165 100644 --- a/source/blender/blenfont/BLF_translation.h +++ b/source/blender/blenfont/BLF_translation.h @@ -33,6 +33,8 @@ #ifndef __BLF_TRANSLATION_H__ #define __BLF_TRANSLATION_H__ +#include "BLI_utildefines.h" /* for bool type */ + #define TEXT_DOMAIN_NAME "blender" /* blf_lang.c */ @@ -48,24 +50,30 @@ void BLF_lang_free(void); /* Set the current locale. */ void BLF_lang_set(const char *); -/* Get the current locale (short code, e.g. es_ES). */ +/* Get the current locale ([partial] ISO code, e.g. es_ES). */ const char *BLF_lang_get(void); +/* Get locale's elements (if relevant pointer is not NULL and element actually exists, e.g. if there is no variant, + * *variant and *language_variant will always be NULL). + * Non-null elements are always MEM_mallocN'ed, it's the caller's responsibility to free them. + * NOTE: Always available, even in non-WITH_INTERNATIONAL builds. + */ +void BLF_locale_explode(const char *locale, char **language, char **country, char **variant, + char **language_country, char **language_variant); + /* Get EnumPropertyItem's for translations menu. */ struct EnumPropertyItem *BLF_RNA_lang_enum_properties(void); /* blf_translation.c */ -#ifdef WITH_INTERNATIONAL unsigned char *BLF_get_unifont(int *unifont_size); void BLF_free_unifont(void); -#endif const char *BLF_pgettext(const char *msgctxt, const char *msgid); /* translation */ -int BLF_translate_iface(void); -int BLF_translate_tooltips(void); +bool BLF_translate_iface(void); +bool BLF_translate_tooltips(void); const char *BLF_translate_do_iface(const char *msgctxt, const char *msgid); const char *BLF_translate_do_tooltip(const char *msgctxt, const char *msgid); @@ -76,17 +84,17 @@ const char *BLF_translate_do_tooltip(const char *msgctxt, const char *msgid); /* Those macros should be used everywhere in UI code. */ #ifdef WITH_INTERNATIONAL -/* #define _(msgid) BLF_gettext(msgid) */ - #define IFACE_(msgid) BLF_translate_do_iface(NULL, msgid) - #define TIP_(msgid) BLF_translate_do_tooltip(NULL, msgid) - #define CTX_IFACE_(context, msgid) BLF_translate_do_iface(context, msgid) - #define CTX_TIP_(context, msgid) BLF_translate_do_tooltip(context, msgid) +/*# define _(msgid) BLF_gettext(msgid) */ +# define IFACE_(msgid) BLF_translate_do_iface(NULL, msgid) +# define TIP_(msgid) BLF_translate_do_tooltip(NULL, msgid) +# define CTX_IFACE_(context, msgid) BLF_translate_do_iface(context, msgid) +# define CTX_TIP_(context, msgid) BLF_translate_do_tooltip(context, msgid) #else -/* #define _(msgid) msgid */ - #define IFACE_(msgid) msgid - #define TIP_(msgid) msgid - #define CTX_IFACE_(context, msgid) msgid - #define CTX_TIP_(context, msgid) msgid +/*# define _(msgid) msgid */ +# define IFACE_(msgid) msgid +# define TIP_(msgid) msgid +# define CTX_IFACE_(context, msgid) msgid +# define CTX_TIP_(context, msgid) msgid #endif /* Helper macro, when we want to define a same msgid for multiple msgctxt... @@ -102,8 +110,11 @@ const char *BLF_translate_do_tooltip(const char *msgctxt, const char *msgid); * things, and limit the number of existing contexts! */ -/* Default, void context. Just in case... */ -#define BLF_I18NCONTEXT_DEFAULT "" +/* Default, void context. + * WARNING! The "" context is not the same as no (NULL) context at mo/boost::locale level! + */ +#define BLF_I18NCONTEXT_DEFAULT NULL /* Translated as None in Python. */ +#define BLF_I18NCONTEXT_DEFAULT_BPY_INTERN "" /* Only used in code, never exposed to user! */ /* Default context for operator names/labels. */ #define BLF_I18NCONTEXT_OPERATOR_DEFAULT "Operator" @@ -146,4 +157,52 @@ const char *BLF_translate_do_tooltip(const char *msgctxt, const char *msgid); #define BLF_I18NCONTEXT_ID_MOVIECLIP "MovieClip" #define BLF_I18NCONTEXT_ID_MASK "Mask" +/* Helper for bpy.app.i18n object... */ +typedef struct +{ + const char *c_id; + const char *py_id; + const char *value; +} BLF_i18n_contexts_descriptor; + +#define BLF_I18NCONTEXTS_ITEM(ctxt_id, py_id) {#ctxt_id, py_id, ctxt_id} + +#define BLF_I18NCONTEXTS_DESC { \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_DEFAULT, "default"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "operator_default"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ACTION, "id_action"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ARMATURE, "id_armature"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_BRUSH, "id_brush"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_CAMERA, "id_camera"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_CURVE, "id_curve"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_GPENCIL, "id_gpencil"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_GROUP, "id_group"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ID, "id_id"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_IMAGE, "id_image"), \ + /*BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_IPO, "id_ipo"),*/ \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SHAPEKEY, "id_shapekey"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_LAMP, "id_lamp"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_LIBRARY, "id_library"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_LATTICE, "id_lattice"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MATERIAL, "id_material"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_METABALL, "id_metaball"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MESH, "id_mesh"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_NODETREE, "id_nodetree"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_OBJECT, "id_object"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_PARTICLESETTINGS, "id_particlesettings"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SCENE, "id_scene"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SCREEN, "id_screen"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SEQUENCE, "id_sequence"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SPEAKER, "id_speaker"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SOUND, "id_sound"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_TEXTURE, "id_texture"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_TEXT, "id_text"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_VFONT, "id_vfont"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_WORLD, "id_world"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_WINDOWMANAGER, "id_windowmanager"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MOVIECLIP, "id_movieclip"), \ + BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MASK, "id_mask"), \ + {NULL, NULL, NULL} \ +} + #endif /* __BLF_TRANSLATION_H__ */ diff --git a/source/blender/blenfont/CMakeLists.txt b/source/blender/blenfont/CMakeLists.txt index a3afd853cba..42298133d7d 100644 --- a/source/blender/blenfont/CMakeLists.txt +++ b/source/blender/blenfont/CMakeLists.txt @@ -29,6 +29,7 @@ set(INC ../editors/include ../makesdna ../makesrna + ../python ../imbuf ../../../intern/guardedalloc ../../../intern/locale diff --git a/source/blender/blenfont/SConscript b/source/blender/blenfont/SConscript index 354a030775e..8273ddf1e40 100644 --- a/source/blender/blenfont/SConscript +++ b/source/blender/blenfont/SConscript @@ -31,7 +31,7 @@ Import ('env') sources = env.Glob('intern/*.c') incs = '. intern #/intern/guardedalloc #/intern/locale ../blenkernel ../blenlib ../blenloader' -incs += ' ../makesdna ../makesrna ../imbuf ../editors/include' +incs += ' ../makesdna ../makesrna ../python ../imbuf ../editors/include' incs += ' #/extern/glew/include' incs += ' ' + env['BF_FREETYPE_INC'] @@ -46,4 +46,4 @@ if env['WITH_BF_INTERNATIONAL']: if env['WITH_BF_FREESTYLE']: defs.append('WITH_FREESTYLE') -env.BlenderLib ( 'bf_blenfont', sources, Split(incs), Split(defs), libtype=['core','player'], priority=[210,210] ) +env.BlenderLib ( 'bf_blenfont', sources, Split(incs), defines=defs, libtype=['core','player'], priority=[210,210] ) diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 12c0088e93e..a6b04b24399 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -213,6 +213,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) FT_Error err; FT_Bitmap bitmap, tempbitmap; int sharp = (U.text_render & USER_TEXT_DISABLE_AA); + int flags = FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; FT_BBox bbox; unsigned int key; @@ -220,10 +221,13 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) if (g) return g; + if (font->flags & BLF_HINTING) + flags &= ~FT_LOAD_NO_HINTING; + if (sharp) err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_MONO); else - err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP); /* Sure about NO_* flags? */ + err = FT_Load_Glyph(font->face, (FT_UInt)index, flags); if (err) return NULL; diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index 9086799f984..73294f1aed6 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -27,41 +27,35 @@ * \ingroup blf */ - -#include "BLF_translation.h" /* own include */ - -#include "BLI_utildefines.h" - -#ifdef WITH_INTERNATIONAL - #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "boost_locale_wrapper.h" - -#include "BKE_global.h" - -#include "DNA_userdef_types.h" - #include "RNA_types.h" -#include "MEM_guardedalloc.h" +#include "BLF_translation.h" /* own include */ #include "BLI_fileops.h" #include "BLI_linklist.h" #include "BLI_path_util.h" #include "BLI_string.h" +#include "BKE_global.h" + +#include "DNA_userdef_types.h" + +#include "MEM_guardedalloc.h" + +#ifdef WITH_INTERNATIONAL + +#include "boost_locale_wrapper.h" + /* Locale options. */ static const char **locales = NULL; static int num_locales = 0; static EnumPropertyItem *locales_menu = NULL; static int num_locales_menu = 0; -#define ULANGUAGE ((U.language >= 0 && U.language < num_locales) ? U.language : 0) -#define LOCALE(_id) (locales ? locales[_id] : "") - static void free_locales(void) { if (locales) { @@ -113,7 +107,7 @@ static void fill_locales(void) } num_locales_menu++; /* The "closing" void item... */ - /* And now, buil locales and locale_menu! */ + /* And now, build locales and locale_menu! */ locales_menu = MEM_callocN(num_locales_menu * sizeof(EnumPropertyItem), __func__); line = lines; /* Do not allocate locales with zero-sized mem, as LOCALE macro uses NULL locales as invalid marker! */ @@ -177,14 +171,20 @@ static void fill_locales(void) BLI_file_free_lines(lines); } +#endif /* WITH_INTERNATIONAL */ EnumPropertyItem *BLF_RNA_lang_enum_properties(void) { +#ifdef WITH_INTERNATIONAL return locales_menu; +#else + return NULL; +#endif } void BLF_lang_init(void) { +#ifdef WITH_INTERNATIONAL char *messagepath = BLI_get_folder(BLENDER_DATAFILES, "locale"); if (messagepath) { @@ -194,15 +194,24 @@ void BLF_lang_init(void) else { printf("%s: 'locale' data path for translations not found, continuing\n", __func__); } +#else +#endif } void BLF_lang_free(void) { +#ifdef WITH_INTERNATIONAL free_locales(); +#else +#endif } +#define ULANGUAGE ((U.language >= 0 && U.language < num_locales) ? U.language : 0) +#define LOCALE(_id) (locales ? locales[(_id)] : "") + void BLF_lang_set(const char *str) { +#ifdef WITH_INTERNATIONAL int ulang = ULANGUAGE; const char *short_locale = str ? str : LOCALE(ulang); const char *short_locale_utf8 = NULL; @@ -232,37 +241,77 @@ void BLF_lang_set(const char *str) if (short_locale[0]) { MEM_freeN((void *)short_locale_utf8); } +#else + (void)str; +#endif } +/* Get the current locale (short code, e.g. es_ES). */ const char *BLF_lang_get(void) { - int uilang = ULANGUAGE; - return LOCALE(uilang); +#ifdef WITH_INTERNATIONAL + const char *locale = LOCALE(ULANGUAGE); + if (locale[0] == '\0') { + /* Default locale, we have to find which one we are actually using! */ + locale = bl_locale_get(); + } + return locale; +#else + return ""; +#endif } #undef LOCALE #undef ULANGUAGE -#else /* ! WITH_INTERNATIONAL */ - -void BLF_lang_init(void) -{ - return; -} - -void BLF_lang_free(void) +/* Get locale's elements (if relevant pointer is not NULL and element actually exists, e.g. if there is no variant, + * *variant and *language_variant will always be NULL). + * Non-null elements are always MEM_mallocN'ed, it's the caller's responsibility to free them. + * NOTE: Keep that one always available, you never know, may become useful even in no-WITH_INTERNATIONAL context... + */ +void BLF_locale_explode(const char *locale, char **language, char **country, char **variant, + char **language_country, char **language_variant) { - return; -} + char *m1, *m2, *_t = NULL; -void BLF_lang_set(const char *UNUSED(str)) -{ - return; -} + m1 = strchr(locale, '_'); + m2 = strchr(locale, '@'); -const char *BLF_lang_get(void) -{ - return ""; + if (language || language_variant) { + if (m1 || m2) { + _t = m1 ? BLI_strdupn(locale, m1 - locale) : BLI_strdupn(locale, m2 - locale); + if (language) + *language = _t; + } + else if (language) { + *language = BLI_strdup(locale); + } + } + if (country) { + if (m1) + *country = m2 ? BLI_strdupn(m1 + 1, m2 - (m1 + 1)) : BLI_strdup(m1 + 1); + else + *country = NULL; + } + if (variant) { + if (m2) + *variant = BLI_strdup(m2 + 1); + else + *variant = NULL; + } + if (language_country) { + if (m1) + *language_country = m2 ? BLI_strdupn(locale, m2 - locale) : BLI_strdup(locale); + else + *language_country = NULL; + } + if (language_variant) { + if (m2) + *language_variant = m1 ? BLI_strdupcat(_t, m2) : BLI_strdup(locale); + else + *language_variant = NULL; + } + if (_t && !language) { + MEM_freeN(_t); + } } - -#endif /* WITH_INTERNATIONAL */ diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c index 5d4b631688a..a77b464822b 100644 --- a/source/blender/blenfont/intern/blf_translation.c +++ b/source/blender/blenfont/intern/blf_translation.c @@ -33,26 +33,28 @@ #include "BLF_translation.h" -#ifdef WITH_INTERNATIONAL - -#include "boost_locale_wrapper.h" - #include "MEM_guardedalloc.h" -#include "BLI_utildefines.h" +#include "BLI_fileops.h" #include "BLI_path_util.h" #include "BLI_string.h" -#include "BLI_path_util.h" -#include "BLI_fileops.h" #include "DNA_userdef_types.h" /* For user settings. */ +#include "BPY_extern.h" + +#ifdef WITH_INTERNATIONAL + +#include "boost_locale_wrapper.h" + static const char unifont_filename[] = "droidsans.ttf.gz"; static unsigned char *unifont_ttf = NULL; static int unifont_size = 0; +#endif /* WITH_INTERNATIONAL */ unsigned char *BLF_get_unifont(int *unifont_size_r) { +#ifdef WITH_INTERNATIONAL if (unifont_ttf == NULL) { char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts"); if (fontpath) { @@ -70,21 +72,41 @@ unsigned char *BLF_get_unifont(int *unifont_size_r) *unifont_size_r = unifont_size; return unifont_ttf; +#else + (void)unifont_size_r; + return NULL; +#endif } void BLF_free_unifont(void) { +#ifdef WITH_INTERNATIONAL if (unifont_ttf) MEM_freeN(unifont_ttf); -} - +#else #endif +} const char *BLF_pgettext(const char *msgctxt, const char *msgid) { #ifdef WITH_INTERNATIONAL if (msgid && msgid[0]) { - return bl_locale_pgettext(msgctxt, msgid); + const char *ret; + + /*if (msgctxt && !strcmp(msgctxt, BLF_I18NCONTEXT_DEFAULT_BPY_INTERN)) { */ + if (msgctxt && !msgctxt[0]) { + /* BLF_I18NCONTEXT_DEFAULT_BPY_INTERN context is reserved and considered the same as default NULL one. */ + msgctxt = NULL; + } + ret = bl_locale_pgettext(msgctxt, msgid); + /* We assume if the returned string is the same (memory level) as the msgid, no translation was found, + * and we can try py scripts' ones! + */ + if (ret == msgid) { + ret = BPY_app_translations_py_pgettext(msgctxt, msgid); + } + + return ret; } return ""; #else @@ -93,21 +115,21 @@ const char *BLF_pgettext(const char *msgctxt, const char *msgid) #endif } -int BLF_translate_iface(void) +bool BLF_translate_iface(void) { #ifdef WITH_INTERNATIONAL return (U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_IFACE); #else - return 0; + return false; #endif } -int BLF_translate_tooltips(void) +bool BLF_translate_tooltips(void) { #ifdef WITH_INTERNATIONAL return (U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_TOOLTIPS); #else - return 0; + return false; #endif } |