diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2007-06-02 18:55:29 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2007-06-02 18:55:29 +0000 |
commit | 317895038e4eb68a333b4baed3865c90ab0316a4 (patch) | |
tree | d8c7041c5ddeb9118c7ecccafbe6fbc8764e9dfc | |
parent | da84aec9cee5d1bf6548704876aa1c37cf53c4d4 (diff) | |
download | pango-317895038e4eb68a333b4baed3865c90ab0316a4.tar.gz |
Bug 443206 – PANGO_SCRIPT_UNKNOWN should not cause a run break Patch
2007-06-02 Behdad Esfahbod <behdad@gnome.org>
Bug 443206 – PANGO_SCRIPT_UNKNOWN should not cause a run break
Patch from Martin Hosken
* pango/pango-script.c: Treat Unknown script like Common and other
non-"real" scripts.
svn path=/branches/pango-1-16/; revision=2327
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | pango/pango-script.c | 92 |
2 files changed, 98 insertions, 2 deletions
@@ -1,3 +1,11 @@ +2007-06-02 Behdad Esfahbod <behdad@gnome.org> + + Bug 443206 – PANGO_SCRIPT_UNKNOWN should not cause a run break + Patch from Martin Hosken + + * pango/pango-script.c: Treat Unknown script like Common and other + non-"real" scripts. + 2007-05-10 Behdad Esfahbod <behdad@gnome.org> * ChangeLog.pre-1-16: Split ChangeLog. diff --git a/pango/pango-script.c b/pango/pango-script.c index 3036c999..5d93d826 100644 --- a/pango/pango-script.c +++ b/pango/pango-script.c @@ -257,7 +257,7 @@ get_pair_index (gunichar ch) } #define REAL_SCRIPT(script) \ - ((script) > PANGO_SCRIPT_INHERITED) + ((script) > PANGO_SCRIPT_INHERITED && (script) != PANGO_SCRIPT_UNKNOWN) #define SAME_SCRIPT(script1, script2) \ (!REAL_SCRIPT (script1) || !REAL_SCRIPT (script2) || (script1) == (script2)) @@ -380,6 +380,94 @@ pango_script_iter_next (PangoScriptIter *iter) * End of code from ICU **********************************************************/ +#include "pango-script-lang-table.h" + +/* The fact that this comparison function works is dependent + * on a property of the pango_script_lang_table which accidental rather + * than inherent. + * + * The property is if we take any element in the table and suffix it + * <elem>-<suffix> then that must strcmp() between any elements + * preceding the element in the table and any element following in the + * table. So, if we had something like: + * + * 'zh' + *' zh-cn' + * + * in the table we would have a problem since 'zh-tw' follows 'zh-cn'. + * On the other hand: + * + * 'zh' + * 'zha' + * + * Works because 'zh-tw' precedes 'zha'. + */ +static int +script_for_lang_compare (gconstpointer key, + gconstpointer member) +{ + PangoLanguage *lang = (PangoLanguage *)key; + const PangoScriptForLang *script_for_lang = member; + + if (pango_language_matches (lang, script_for_lang->lang)) + return 0; + else + return strcmp (pango_language_to_string (lang), + script_for_lang->lang); +} + +/** + * pango_language_includes_script: + * @language: a #PangoLanguage + * @script: a #PangoScript + * + * Determines if @script is one of the scripts used to + * write @language. The returned value is conservative; + * if nothing is known about the language tag @language, + * %TRUE will be returned, since, as far as Pango knows, + * @script might be used to write @language. + * + * This routine is used in Pango's itemization process when + * determining if a supplied language tag is relevant to + * a particular section of text. It probably is not useful for + * applications in most circumstances. + * + * Return value: %TRUE if @script is one of the scripts used + * to write @language, or if nothing is known about @language. + * + * Since: 1.4 + **/ +gboolean +pango_language_includes_script (PangoLanguage *language, + PangoScript script) +{ + PangoScriptForLang *script_for_lang; + unsigned int j; + + g_return_val_if_fail (language != NULL, FALSE); + + if (!REAL_SCRIPT (script)) + return TRUE; + + /* This bsearch could be optimized to occur only once if + * we store the pointer to the PangoScriptForLang in the + * same block as the string value for the PangoLanguage. + */ + script_for_lang = bsearch (pango_language_to_string (language), + pango_script_for_lang, + G_N_ELEMENTS (pango_script_for_lang), + sizeof (PangoScriptForLang), + script_for_lang_compare); + if (!script_for_lang) + return TRUE; + + for (j = 0; j < G_N_ELEMENTS (script_for_lang->scripts); j++) + if (script_for_lang->scripts[j] == script) + return TRUE; + + return FALSE; +} + /** * pango_script_get_sample_language: * @script: a #PangoScript @@ -414,7 +502,7 @@ pango_script_get_sample_language (PangoScript script) * (Shavian for English, Osmanya for Somali, etc), typically * have no sample language */ - static const char sample_languages[][4] = { + const char sample_languages[][4] = { "", /* PANGO_SCRIPT_COMMON */ "", /* PANGO_SCRIPT_INHERITED */ "ar", /* PANGO_SCRIPT_ARABIC */ |