diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2006-12-06 23:00:31 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2006-12-06 23:00:31 +0000 |
commit | f3507cc8cf4106cd4731c57b32092f5362883bdd (patch) | |
tree | 028c81ff5aa62a22f73b2b9c7a7bd13ac373f5bf | |
parent | b7c74a7787b624bdf1ef6a4f6dba2007317b9265 (diff) | |
download | pango-f3507cc8cf4106cd4731c57b32092f5362883bdd.tar.gz |
Bug 333982 – Fallback to $LANG whenever NULL PangoLanguage is used Patch
2006-12-06 Behdad Esfahbod <behdad@gnome.org>
Bug 333982 – Fallback to $LANG whenever NULL PangoLanguage is used
Patch from LingNing Zhang
* docs/pango-sections.txt:
* docs/tmpl/utils.sgml:
* pango/pango-context.c:
* pango/pango-types.h:
* pango/pango-utils.c (_pango_get_lc_ctype),
(pango_language_get_default):
* pango/pango.def:
New public function pango_language_get_default(). Note that, this
does not make Pango fallback to the default language automatically,
but the user can use this function to set the default language of the
locale on a context:
pango_context_set_language (context, pango_language_get_default());
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | docs/pango-sections.txt | 1 | ||||
-rw-r--r-- | docs/tmpl/utils.sgml | 8 | ||||
-rw-r--r-- | pango/pango-context.c | 4 | ||||
-rw-r--r-- | pango/pango-types.h | 2 | ||||
-rw-r--r-- | pango/pango-utils.c | 90 | ||||
-rw-r--r-- | pango/pango.def | 1 |
7 files changed, 124 insertions, 1 deletions
@@ -1,5 +1,24 @@ 2006-12-06 Behdad Esfahbod <behdad@gnome.org> + Bug 333982 – Fallback to $LANG whenever NULL PangoLanguage is used + Patch from LingNing Zhang + + * docs/pango-sections.txt: + * docs/tmpl/utils.sgml: + * pango/pango-context.c: + * pango/pango-types.h: + * pango/pango-utils.c (_pango_get_lc_ctype), + (pango_language_get_default): + * pango/pango.def: + New public function pango_language_get_default(). Note that, this + does not make Pango fallback to the default language automatically, + but the user can use this function to set the default language of the + locale on a context: + + pango_context_set_language (context, pango_language_get_default()); + +2006-12-06 Behdad Esfahbod <behdad@gnome.org> + Bug 373856 – Wish: Function to convert a GdkColor to a string Patch from Matthew Barnes diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt index afa6afe2..ba268e5e 100644 --- a/docs/pango-sections.txt +++ b/docs/pango-sections.txt @@ -965,6 +965,7 @@ pango_parse_stretch pango_get_sysconf_subdirectory pango_get_lib_subdirectory pango_log2vis_get_embedding_levels +pango_language_get_default pango_language_get_sample_string pango_is_zero_width pango_quantize_line_geometry diff --git a/docs/tmpl/utils.sgml b/docs/tmpl/utils.sgml index eab7fbaf..d836f661 100644 --- a/docs/tmpl/utils.sgml +++ b/docs/tmpl/utils.sgml @@ -175,6 +175,14 @@ backends and modules, but may be useful for other purposes too. @Returns: +<!-- ##### FUNCTION pango_language_get_default ##### --> +<para> + +</para> + +@Returns: + + <!-- ##### FUNCTION pango_language_get_sample_string ##### --> <para> diff --git a/pango/pango-context.c b/pango/pango-context.c index c6814ba8..26c20cdb 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -350,7 +350,9 @@ pango_context_get_font_description (PangoContext *context) * @context: a #PangoContext * @language: the new language tag. * - * Sets the global language tag for the context. + * Sets the global language tag for the context. The default language + * for the locale of the running process can be found using + * pango_language_get_default(). **/ void pango_context_set_language (PangoContext *context, diff --git a/pango/pango-types.h b/pango/pango-types.h index 2e8b5a83..221bc64b 100644 --- a/pango/pango-types.h +++ b/pango/pango-types.h @@ -70,9 +70,11 @@ typedef struct _PangoLanguage PangoLanguage; GType pango_language_get_type (void); PangoLanguage *pango_language_from_string (const char *language); + #define pango_language_to_string(language) ((const char *)language) G_CONST_RETURN char *pango_language_get_sample_string (PangoLanguage *language); +PangoLanguage *pango_language_get_default (void); gboolean pango_language_matches (PangoLanguage *language, const char *range_list); diff --git a/pango/pango-utils.c b/pango/pango-utils.c index 81700d2a..ea480840 100644 --- a/pango/pango-utils.c +++ b/pango/pango-utils.c @@ -24,6 +24,7 @@ #include <string.h> #include <stdlib.h> #include <math.h> +#include <locale.h> #include "pango-font.h" #include "pango-impl-utils.h" @@ -988,6 +989,92 @@ pango_language_get_type (void) } /** + * _pango_get_lc_ctype: + * + * Return the Unix-style locale string for the language currently in + * effect. On Unix systems, this is the return value from + * <literal>setlocale(LC_CTYPE, NULL)</literal>, and the user can + * affect this through the environment variables LC_ALL, LC_CTYPE or + * LANG (checked in that order). The locale strings typically is in + * the form lang_COUNTRY, where lang is an ISO-639 language code, and + * COUNTRY is an ISO-3166 country code. For instance, sv_FI for + * Swedish as written in Finland or pt_BR for Portuguese as written in + * Brazil. + * + * On Windows, the C library doesn't use any such environment + * variables, and setting them won't affect the behaviour of functions + * like ctime(). The user sets the locale through the Regional Options + * in the Control Panel. The C library (in the setlocale() function) + * does not use country and language codes, but country and language + * names spelled out in English. + * However, this function does check the above environment + * variables, and does return a Unix-style locale string based on + * either said environment variables or the thread's current locale. + * + * Return value: a dynamically allocated string, free with g_free(). + */ +static gchar * +_pango_get_lc_ctype (void) +{ +#ifdef G_OS_WIN32 + /* Somebody might try to set the locale for this process using the + * LANG or LC_ environment variables. The Microsoft C library + * doesn't know anything about them. You set the locale in the + * Control Panel. Setting these env vars won't have any affect on + * locale-dependent C library functions like ctime(). But just for + * kicks, do obey LC_ALL, LC_CTYPE and LANG in Pango. (This also makes + * it easier to test GTK and Pango in various default languages, you + * don't have to clickety-click in the Control Panel, you can simply + * start the program with LC_ALL=something on the command line.) + */ + + gchar *p; + + p = getenv ("LC_ALL"); + if (p != NULL) + return g_strdup (p); + + p = getenv ("LC_CTYPE"); + if (p != NULL) + return g_strdup (p); + + p = getenv ("LANG"); + if (p != NULL) + return g_strdup (p); + + return g_win32_getlocale (); +#else + return g_strdup (setlocale (LC_CTYPE, NULL)); +#endif +} + +/** + * pango_language_get_default: + * + * Returns the #PangoLanguage for the current locale of the running + * process. Note that this can change over the life of an + * application. + * + * Return value: the default language as a #PangoLanguage, must not be + * freed. + * + * Since: 1.16 + **/ +PangoLanguage * +pango_language_get_default (void) +{ + gchar *lang; + PangoLanguage *result; + + lang = _pango_get_lc_ctype (); + + result = pango_language_from_string (lang); + g_free (lang); + + return result; +} + +/** * pango_language_from_string: * @language: a string representing a language tag * @@ -999,6 +1086,9 @@ pango_language_get_type (void) * This function first canonicalizes the string by converting it to * lowercase, mapping '_' to '-', and stripping all characters other * than letters and '-'. + * + * Use pango_language_get_default() if you want to get the #PangoLanguage for + * the current locale of the process. * * Return value: an opaque pointer to a #PangoLanguage structure. * this will be valid forever after. diff --git a/pango/pango.def b/pango/pango.def index a8430f9c..cb64cce1 100644 --- a/pango/pango.def +++ b/pango/pango.def @@ -194,6 +194,7 @@ EXPORTS pango_itemize pango_itemize_with_base_dir pango_language_from_string + pango_language_get_default pango_language_get_sample_string pango_language_get_type pango_language_includes_script |