summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2007-05-10 21:26:21 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2007-05-10 21:26:21 +0000
commitdd0245c7629630c52a33f301ce5ba687ec353cff (patch)
treefefc5c8f24a7ad1fd4db35a1e33fe4fcce78a276
parentf20dc94b7ed3bcf37f5bfc8bc5d8bf8596954a60 (diff)
downloadpango-dd0245c7629630c52a33f301ce5ba687ec353cff.tar.gz
New public API:
2007-05-10 Behdad Esfahbod <behdad@gnome.org> * pango/Makefile.am: * pango/pango-ot.h: * pango/pango-ot-tag.c (pango_ot_tag_from_script), (pango_ot_tag_to_script), (lang_compare_first_component), (pango_ot_tag_from_language), (pango_ot_tag_to_language): New public API: PANGO_OT_DEFAULT_SCRIPT pango_ot_tag_from_script() pango_ot_tag_to_script() pango_ot_tag_from_language() pango_ot_tag_to_language() * tests/Makefile.am: * tests/test-ot-tags.c: Test case for new functions. * pango/pangoft2.def: * docs/pango-docs.sgml: * docs/pango-sections.txt: * docs/tmpl/main.sgml: * docs/tmpl/opentype.sgml: Updated. svn path=/trunk/; revision=2274
-rw-r--r--ChangeLog34
-rw-r--r--docs/pango-docs.sgml3
-rw-r--r--docs/pango-sections.txt5
-rw-r--r--docs/tmpl/main.sgml3
-rw-r--r--docs/tmpl/opentype.sgml46
-rw-r--r--pango/Makefile.am3
-rw-r--r--pango/pango-ot-tag.c453
-rw-r--r--pango/pango-ot.h16
-rw-r--r--pango/pangoft2.def4
-rw-r--r--tests/Makefile.am21
-rw-r--r--tests/test-ot-tags.c131
11 files changed, 695 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index 8aa0b8de..3641a99c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,39 @@
2007-05-10 Behdad Esfahbod <behdad@gnome.org>
+ * pango/Makefile.am:
+ * pango/pango-ot.h:
+ * pango/pango-ot-tag.c (pango_ot_tag_from_script),
+ (pango_ot_tag_to_script), (lang_compare_first_component),
+ (pango_ot_tag_from_language), (pango_ot_tag_to_language):
+ New public API:
+
+ PANGO_OT_DEFAULT_SCRIPT
+ pango_ot_tag_from_script()
+ pango_ot_tag_to_script()
+ pango_ot_tag_from_language()
+ pango_ot_tag_to_language()
+
+ * tests/Makefile.am:
+ * tests/test-ot-tags.c:
+ Test case for new functions.
+
+ * pango/pangoft2.def:
+ * docs/pango-docs.sgml:
+ * docs/pango-sections.txt:
+ * docs/tmpl/main.sgml:
+ * docs/tmpl/opentype.sgml:
+ Updated.
+
+2007-05-10 Behdad Esfahbod <behdad@gnome.org>
+
+ Bug 437534 – pango_language_includes_script is buggy
+
+ * pango/pango-language.c (lang_compare_first_component),
+ (lang_info_compare), (script_for_lang_compare),
+ (pango_language_includes_script): Fix script_for_lang table lookup.
+
+2007-05-10 Behdad Esfahbod <behdad@gnome.org>
+
* pango/pangofc-fontmap.c (pango_fc_font_description_from_pattern),
(pango_fc_face_describe): Don't set gravity in
pango_fc_font_description_from_pattern() if it was not set on the
diff --git a/docs/pango-docs.sgml b/docs/pango-docs.sgml
index c38cf8f7..b8670dec 100644
--- a/docs/pango-docs.sgml
+++ b/docs/pango-docs.sgml
@@ -116,4 +116,7 @@
<index role="1.16">
<title>Index of new symbols in 1.16</title>
</index>
+ <index role="1.18">
+ <title>Index of new symbols in 1.18</title>
+ </index>
</book>
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 6c9e6426..e7348d31 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -943,6 +943,7 @@ PangoOTRuleset
PangoOTTableType
PANGO_OT_ALL_GLYPHS
PANGO_OT_DEFAULT_LANGUAGE
+PANGO_OT_DEFAULT_SCRIPT
pango_ot_info_get
pango_ot_info_find_script
pango_ot_info_find_language
@@ -962,6 +963,10 @@ pango_ot_ruleset_new
pango_ot_ruleset_add_feature
pango_ot_ruleset_substitute
pango_ot_ruleset_position
+pango_ot_tag_from_language
+pango_ot_tag_from_script
+pango_ot_tag_to_language
+pango_ot_tag_to_script
</SECTION>
<SECTION>
diff --git a/docs/tmpl/main.sgml b/docs/tmpl/main.sgml
index 9a3a9f39..dc3ed934 100644
--- a/docs/tmpl/main.sgml
+++ b/docs/tmpl/main.sgml
@@ -50,8 +50,9 @@ fields:
@lang_engine: the engine for doing rendering-system-independent processing.
@font: the font for this segment.
@level: the bidirectional level for this segment.
-@gravity: the glyph orientation for this segment.
+@gravity: the glyph orientation for this segment (A #PangoGravity).
@flags: boolean flags for this segment (currently only one) (Since: 1.16).
+@script: the detected script for this segment (A #PangoScript) (Since: 1.18).
@language: the detected language for this segment.
@extra_attrs: extra attributes for this segment.
diff --git a/docs/tmpl/opentype.sgml b/docs/tmpl/opentype.sgml
index f1a304fe..1bc78474 100644
--- a/docs/tmpl/opentype.sgml
+++ b/docs/tmpl/opentype.sgml
@@ -96,12 +96,20 @@ feature should be applied to all glyphs.
<!-- ##### MACRO PANGO_OT_DEFAULT_LANGUAGE ##### -->
<para>
-This is used as the language index in pango_ot_info_find_feature() when a
+This is used as the language index in pango_ot_info_find_feature() when
the default language system of the script is desired.
</para>
+<!-- ##### MACRO PANGO_OT_DEFAULT_SCRIPT ##### -->
+<para>
+Expands to the #PangoOTTag corresponding to the special OpenType
+script tag 'DFLT'.
+</para>
+
+
+
<!-- ##### FUNCTION pango_ot_info_get ##### -->
<para>
@@ -297,3 +305,39 @@ the default language system of the script is desired.
@buffer:
+<!-- ##### FUNCTION pango_ot_tag_from_language ##### -->
+<para>
+
+</para>
+
+@language:
+@Returns:
+
+
+<!-- ##### FUNCTION pango_ot_tag_from_script ##### -->
+<para>
+
+</para>
+
+@script:
+@Returns:
+
+
+<!-- ##### FUNCTION pango_ot_tag_to_language ##### -->
+<para>
+
+</para>
+
+@language_tag:
+@Returns:
+
+
+<!-- ##### FUNCTION pango_ot_tag_to_script ##### -->
+<para>
+
+</para>
+
+@script_tag:
+@Returns:
+
+
diff --git a/pango/Makefile.am b/pango/Makefile.am
index 78765a0c..af0e6cf5 100644
--- a/pango/Makefile.am
+++ b/pango/Makefile.am
@@ -218,7 +218,8 @@ libpangoft2_1_0_la_SOURCES = \
pango-ot-private.h \
pango-ot-buffer.c \
pango-ot-info.c \
- pango-ot-ruleset.c
+ pango-ot-ruleset.c \
+ pango-ot-tag.c
if OS_WIN32
diff --git a/pango/pango-ot-tag.c b/pango/pango-ot-tag.c
new file mode 100644
index 00000000..c3d853d4
--- /dev/null
+++ b/pango/pango-ot-tag.c
@@ -0,0 +1,453 @@
+/* Pango
+ * pango-ot-tag.h:
+ *
+ * Copyright (C) 2007 Red Hat Software
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include "pango-ot.h"
+
+/*
+ * complete list at:
+ * http://www.microsoft.com/typography/developers/opentype/scripttags.aspx
+ */
+static const char ot_scripts[][4] = {
+ "DFLT", /* PANGO_SCRIPT_COMMON */
+ "DFLT", /* PANGO_SCRIPT_INHERITED */
+ "arab", /* PANGO_SCRIPT_ARABIC */
+ "armn", /* PANGO_SCRIPT_ARMENIAN */
+ "beng", /* PANGO_SCRIPT_BENGALI */
+ "bopo", /* PANGO_SCRIPT_BOPOMOFO */
+ "cher", /* PANGO_SCRIPT_CHEROKEE */
+ "copt", /* PANGO_SCRIPT_COPTIC */
+ "cyrl", /* PANGO_SCRIPT_CYRILLIC */
+ "dsrt", /* PANGO_SCRIPT_DESERET */
+ "deva", /* PANGO_SCRIPT_DEVANAGARI */
+ "ethi", /* PANGO_SCRIPT_ETHIOPIC */
+ "geor", /* PANGO_SCRIPT_GEORGIAN */
+ "goth", /* PANGO_SCRIPT_GOTHIC */
+ "grek", /* PANGO_SCRIPT_GREEK */
+ "gujr", /* PANGO_SCRIPT_GUJARATI */
+ "guru", /* PANGO_SCRIPT_GURMUKHI */
+ "hani", /* PANGO_SCRIPT_HAN */
+ "hang", /* PANGO_SCRIPT_HANGUL */
+ "hebr", /* PANGO_SCRIPT_HEBREW */
+ "kana", /* PANGO_SCRIPT_HIRAGANA */
+ "knda", /* PANGO_SCRIPT_KANNADA */
+ "kana", /* PANGO_SCRIPT_KATAKANA */
+ "khmr", /* PANGO_SCRIPT_KHMER */
+ "lao ", /* PANGO_SCRIPT_LAO */
+ "latn", /* PANGO_SCRIPT_LATIN */
+ "mlym", /* PANGO_SCRIPT_MALAYALAM */
+ "mong", /* PANGO_SCRIPT_MONGOLIAN */
+ "mymr", /* PANGO_SCRIPT_MYANMAR */
+ "ogam", /* PANGO_SCRIPT_OGHAM */
+ "ital", /* PANGO_SCRIPT_OLD_ITALIC */
+ "orya", /* PANGO_SCRIPT_ORIYA */
+ "runr", /* PANGO_SCRIPT_RUNIC */
+ "sinh", /* PANGO_SCRIPT_SINHALA */
+ "syrc", /* PANGO_SCRIPT_SYRIAC */
+ "taml", /* PANGO_SCRIPT_TAMIL */
+ "telu", /* PANGO_SCRIPT_TELUGU */
+ "thaa", /* PANGO_SCRIPT_THAANA */
+ "thai", /* PANGO_SCRIPT_THAI */
+ "tibt", /* PANGO_SCRIPT_TIBETAN */
+ "cans", /* PANGO_SCRIPT_CANADIAN_ABORIGINAL */
+ "yi ", /* PANGO_SCRIPT_YI */
+ "tglg", /* PANGO_SCRIPT_TAGALOG */
+ "hano", /* PANGO_SCRIPT_HANUNOO */
+ "buhd", /* PANGO_SCRIPT_BUHID */
+ "tagb", /* PANGO_SCRIPT_TAGBANWA */
+ "brai", /* PANGO_SCRIPT_BRAILLE */
+ "cprt", /* PANGO_SCRIPT_CYPRIOT */
+ "limb", /* PANGO_SCRIPT_LIMBU */
+ "osma", /* PANGO_SCRIPT_OSMANYA */
+ "shaw", /* PANGO_SCRIPT_SHAVIAN */
+ "linb", /* PANGO_SCRIPT_LINEAR_B */
+ "tale", /* PANGO_SCRIPT_TAI_LE */
+ "ugar", /* PANGO_SCRIPT_UGARITIC */
+ "talu", /* PANGO_SCRIPT_NEW_TAI_LUE */
+ "bugi", /* PANGO_SCRIPT_BUGINESE */
+ "glag", /* PANGO_SCRIPT_GLAGOLITIC */
+ "tfng", /* PANGO_SCRIPT_TIFINAGH */
+ "sylo", /* PANGO_SCRIPT_SYLOTI_NAGRI */
+ "xpeo", /* PANGO_SCRIPT_OLD_PERSIAN */
+ "khar", /* PANGO_SCRIPT_KHAROSHTHI */
+ "DFLT", /* PANGO_SCRIPT_UNKNOWN */
+ "bali", /* PANGO_SCRIPT_BALINESE */
+ "xsux", /* PANGO_SCRIPT_CUNEIFORM */
+ "phnx", /* PANGO_SCRIPT_PHOENICIAN */
+ "phag", /* PANGO_SCRIPT_PHAGS_PA */
+ "nko " /* PANGO_SCRIPT_NKO */
+};
+
+/**
+ * pango_ot_tag_from_script:
+ * @script: A #PangoScript.
+ *
+ * Finds the OpenType script tag corresponding to @script.
+ *
+ * The %PANGO_SCRIPT_COMMON, %PANGO_SCRIPT_INHERITED, and
+ * %PANGO_SCRIPT_UNKNOWN scripts are mapped to the OpenType
+ * 'DFLT' script tag that is also defined as
+ * %PANGO_OT_DEFAULT_SCRIPT.
+ *
+ * Note that multiple #PangoScript values may map to the same
+ * OpenType script tag. In particular, %PANGO_SCRIPT_HIRAGANA
+ * and %PANGO_SCRIPT_KATAKANA both map to the OT tag 'kana'.
+ *
+ * Return value: #PangoOTTag corresponding to @script or
+ * %PANGO_OT_DEFAULT_SCRIPT if none found.
+ *
+ * Since: 1.18
+ **/
+PangoOTTag
+pango_ot_tag_from_script (PangoScript script)
+{
+ g_return_val_if_fail (script >= 0 && (guint)script < G_N_ELEMENTS (ot_scripts), PANGO_OT_DEFAULT_SCRIPT);
+
+ return GUINT32_FROM_BE (* (PangoOTTag *) ot_scripts[script]);
+}
+
+/**
+ * pango_ot_tag_to_script:
+ * @script_tag: A #PangoOTTag OpenType script tag.
+ *
+ * Finds the #PangoScript corresponding to @script_tag.
+ *
+ * The 'DFLT' script tag is mapped to %PANGO_SCRIPT_COMMON.
+ *
+ * Note that an OpenType script tag may correspond to multiple
+ * #PangoScript values. In such cases, the #PangoScript value
+ * with the smallest value is returned.
+ * In particular, %PANGO_SCRIPT_HIRAGANA
+ * and %PANGO_SCRIPT_KATAKANA both map to the OT tag 'kana'.
+ * This function will return %PANGO_SCRIPT_HIRAGANA for
+ * 'kana'.
+ *
+ * Return value: #PangoScript corresponding to @script_tag or
+ * %PANGO_SCRIPT_UNKNOWN if none found.
+ *
+ * Since: 1.18
+ **/
+PangoScript
+pango_ot_tag_to_script (PangoOTTag script_tag)
+{
+ PangoScript i;
+ guint32 be_tag = GUINT32_TO_BE (script_tag);
+
+ for (i = 0; i < (PangoScript) G_N_ELEMENTS (ot_scripts); i++)
+ {
+ guint32 tag = * (guint32 *) ot_scripts[i];
+
+ if (tag == be_tag)
+ return i;
+ }
+
+ return PANGO_SCRIPT_UNKNOWN;
+}
+
+
+typedef struct {
+ char language[6];
+ char tag[4];
+} LangTag;
+
+/*
+ * complete list at:
+ * http://www.microsoft.com/OpenType/OTSpec/languagetags.htm
+ *
+ * Generated by intersecting the above list with the ISO 639-2 codes
+ * and then adjusting manually. A lot of items missing still, feel
+ * free to add. Keep sorted for bsearch purpose.
+ */
+static const LangTag ot_languages[] = {
+ {"aa", "AFR "},
+ {"ab", "ABK "},
+ {"ady", "ADY "},
+ {"af", "AFK "},
+ {"am", "AMH "},
+ {"ar", "ARA "},
+ {"as", "ASM "},
+ {"awa", "AWA "},
+ {"ay", "AYM "},
+ {"az", "AZE "},
+ {"ba", "BSH "},
+ {"bem", "BEM "},
+ {"bg", "BGR "},
+ {"bho", "BHO "},
+ {"bik", "BIK "},
+ {"bin", "EDO "},
+ {"bm", "BMB "},
+ {"bn", "BEN "},
+ {"bo", "TIB "},
+ {"br", "BRE "},
+ {"ca", "CAT "},
+ {"ce", "CHE "},
+ {"ceb", "CEB "},
+ {"chp", "CHP "},
+ {"chr", "CHR "},
+ {"cop", "COP "},
+ {"cr", "CRE "},
+ {"crh", "CRT "},
+ {"cs", "CSY "},
+ {"cu", "CSL "},
+ {"cv", "CHU "},
+ {"cy", "WEL "},
+ {"da", "DAN "},
+ {"dar", "DAR "},
+ {"din", "DNK "},
+ {"doi", "DGR "},
+ {"dv", "DHV "},
+ {"dz", "DZN "},
+ {"ee", "EWE "},
+ {"efi", "EFI "},
+ {"en", "ENG "},
+ {"eo", "NTO "},
+ {"es", "ESP "},
+ {"et", "ETI "},
+ {"eu", "EUQ "},
+ {"fa", "FAR "},
+ {"fi", "FIN "},
+ {"fil", "PIL "},
+ {"fj", "FJI "},
+ {"fo", "FOS "},
+ {"fon", "FON "},
+ {"fr", "FRA "},
+ {"fur", "FRL "},
+ {"ga", "IRI "},
+ {"gaa", "GAD "},
+ {"gd", "GAE "},
+ {"gl", "GAL "},
+ {"gn", "GUA "},
+ {"gon", "GON "},
+ {"gu", "GUJ "},
+ {"ha", "HAU "},
+ {"he", "IWR "},
+ {"hi", "HIN "},
+ {"hil", "HIL "},
+ {"hr", "HRV "},
+ {"hsb", "USB "},
+ {"ht", "HAI "},
+ {"hu", "HUN "},
+ {"hy", "HYE "},
+ {"id", "IND "},
+ {"ig", "IBO "},
+ {"inh", "ING "},
+ {"is", "ISL "},
+ {"it", "ITA "},
+ {"iu", "INU "},
+ {"ja", "JAN "},
+ {"jv", "JAV "},
+ {"ka", "KAT "},
+ {"kam", "KMB "},
+ {"kbd", "KAB "},
+ {"kha", "KSI "},
+ {"ki", "KIK "},
+ {"kk", "KAZ "},
+ {"kl", "GRN "},
+ {"kn", "KAN "},
+ {"ko", "KOR "},
+ {"kok", "KOK "},
+ {"kpe", "KPL "},
+ {"kr", "KNR "},
+ {"krl", "KRL "},
+ {"kru", "KUU "},
+ {"ks", "KSH "},
+ {"ku", "KUR "},
+ {"kum", "KUM "},
+ {"ky", "KIR "},
+ {"ln", "LIN "},
+ {"lt", "LTH "},
+ {"mai", "MTH "},
+ {"mdf", "MOK "},
+ {"men", "MDE "},
+ {"mg", "MLG "},
+ {"mi", "MRI "},
+ {"mnc", "MCH "},
+ {"mni", "MNI "},
+ {"mo", "MOL "},
+ {"mr", "MAR "},
+ {"ms", "MLY "},
+ {"mt", "MTS "},
+ {"mwr", "MAW "},
+ {"my", "BRM "},
+ {"myv", "ERZ "},
+ {"nl", "FLE "},
+ {"nl", "NLD "},
+ {"no", "NOR "},
+ {"ny", "CHI "},
+ {"om", "ORO "},
+ {"or", "ORI "},
+ {"os", "OSS "},
+ {"pa", "PAN "},
+ {"pi", "PAL "},
+ {"pl", "PLK "},
+ {"ps", "PAS "},
+ {"pt", "PTG "},
+ {"ro", "ROM "},
+ {"rom", "ROY "},
+ {"ru", "RUS "},
+ {"sa", "SAN "},
+ {"sat", "SAT "},
+ {"sd", "SND "},
+ {"sel", "SEL "},
+ {"sg", "SGO "},
+ {"shn", "SHN "},
+ {"si", "SNH "},
+ {"sid", "SID "},
+ {"sk", "SKY "},
+ {"sl", "SLV "},
+ {"sm", "SMO "},
+ {"smj", "LSM "},
+ {"smn", "ISM "},
+ {"sms", "SKS "},
+ {"snk", "SNK "},
+ {"so", "SML "},
+ {"sq", "SQI "},
+ {"sr", "SRB "},
+ {"srr", "SRR "},
+ {"sv", "SVE "},
+ {"sw", "SWK "},
+ {"syr", "SYR "},
+ {"tg", "TAJ "},
+ {"ti", "TGY "},
+ {"tig", "TGR "},
+ {"tk", "TKM "},
+ {"tn", "TNA "},
+ {"tr", "TRK "},
+ {"ts", "TSG "},
+ {"tw", "TWI "},
+ {"udm", "UDM "},
+ {"ug", "UYG "},
+ {"uk", "UKR "},
+ {"ur", "URD "},
+ {"uz", "UZB "},
+ {"ve", "VEN "},
+ {"vi", "VIT "},
+ {"wo", "WLF "},
+ {"xal", "KLM "},
+ {"xh", "XHS "},
+ {"yo", "YBA "},
+ {"zh-cn", "ZHS "},
+ {"zh-hk", "ZHH "},
+ {"zh-mo", "ZHT "},
+ {"zh-sg", "ZHS "},
+ {"zh-tw", "ZHT "},
+ {"zu", "ZUL "}
+};
+
+static int
+lang_compare_first_component (gconstpointer pa,
+ gconstpointer pb)
+{
+ const char *a = pa, *b = pb;
+ unsigned int da, db;
+ const char *p;
+
+ p = strstr (a, "-");
+ da = p ? (unsigned int) (p - a) : strlen (a);
+
+ p = strstr (b, "-");
+ db = p ? (unsigned int) (p - b) : strlen (b);
+
+ return strncmp (a, b, MAX (da, db));
+}
+
+/**
+ * pango_ot_tag_from_language:
+ * @language: A #PangoLanguage.
+ *
+ * Finds the OpenType language-system tag best describing @language.
+ *
+ * Return value: #PangoOTTag best matching @language or
+ * %PANGO_OT_DEFAULT_LANGUAGE if none found.
+ *
+ * Since: 1.18
+ **/
+PangoOTTag
+pango_ot_tag_from_language (PangoLanguage *language)
+{
+ const char *lang_str = pango_language_to_string (language);
+
+ /* find a language matching in the first component */
+ LangTag *lang_tag = bsearch (lang_str, ot_languages,
+ G_N_ELEMENTS (ot_languages), sizeof (LangTag),
+ lang_compare_first_component);
+
+ /* we now need to find the best language matching */
+ if (lang_tag)
+ {
+ gboolean found = FALSE;
+
+ /* go to the final one matching in the first component */
+ while (lang_tag + 1 < ot_languages + G_N_ELEMENTS (ot_languages) &&
+ lang_compare_first_component (lang_str, lang_tag + 1) == 0)
+ lang_tag++;
+
+ /* go back, find which one matches completely */
+ while (lang_tag >= ot_languages &&
+ lang_compare_first_component (lang_str, lang_tag) == 0)
+ {
+ if (pango_language_matches (language, lang_tag->language))
+ {
+ found = TRUE;
+ break;
+ }
+
+ lang_tag--;
+ }
+
+ if (!found)
+ lang_tag = NULL;
+ }
+
+ if (lang_tag)
+ return GUINT32_FROM_BE (* (PangoOTTag *) lang_tag->tag);
+
+ return PANGO_OT_DEFAULT_LANGUAGE;
+}
+
+/**
+ * pango_ot_tag_to_language:
+ * @language_tag: A #PangoOTTag OpenType language-system tag.
+ *
+ * Finds a #PangoLanguage corresponding to @language_tag.
+ *
+ * Return value: #PangoLanguage best matching @language_tag or
+ * #PangoLanguage corresponding to the string "xx" if none found.
+ *
+ * Since: 1.18
+ **/
+PangoLanguage *
+pango_ot_tag_to_language (PangoOTTag language_tag)
+{
+ int i;
+ guint32 be_tag = GUINT32_TO_BE (language_tag);
+
+ for (i = 0; i < (int) G_N_ELEMENTS (ot_languages); i++)
+ {
+ guint32 tag = * (guint32 *) ot_languages[i].tag;
+
+ if (tag == be_tag)
+ return pango_language_from_string (ot_languages[i].language);
+ }
+
+ return pango_language_from_string ("xx");
+}
diff --git a/pango/pango-ot.h b/pango/pango-ot.h
index 3d6c4f1f..ce8778f3 100644
--- a/pango/pango-ot.h
+++ b/pango/pango-ot.h
@@ -1,7 +1,7 @@
/* Pango
* pango-ot.h:
*
- * Copyright (C) 2000 Red Hat Software
+ * Copyright (C) 2000,2007 Red Hat Software
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -25,12 +25,14 @@
#include <pango/pangofc-font.h>
#include <pango/pango-glyph.h>
#include <pango/pango-font.h>
+#include <pango/pango-script.h>
+#include <pango/pango-language.h>
G_BEGIN_DECLS
#ifdef PANGO_ENABLE_ENGINE
-typedef guint32 PangoOTTag;
+typedef guint32 PangoOTTag;
typedef struct _PangoOTInfo PangoOTInfo;
typedef struct _PangoOTBuffer PangoOTBuffer;
@@ -44,8 +46,9 @@ typedef enum
} PangoOTTableType;
-#define PANGO_OT_ALL_GLYPHS ((guint)0xFFFF)
-#define PANGO_OT_DEFAULT_LANGUAGE ((guint)0xFFFF)
+#define PANGO_OT_ALL_GLYPHS ((guint) 0xFFFF)
+#define PANGO_OT_DEFAULT_LANGUAGE ((PangoOTTag) 0xFFFF)
+#define PANGO_OT_DEFAULT_SCRIPT ((PangoOTTag) FT_MAKE_TAG ('D', 'F', 'L', 'T'))
/* Note that this must match HB_GlyphItem */
struct _PangoOTGlyph
@@ -118,6 +121,11 @@ void pango_ot_ruleset_substitute (PangoOTRuleset *ruleset,
void pango_ot_ruleset_position (PangoOTRuleset *ruleset,
PangoOTBuffer *buffer);
+PangoScript pango_ot_tag_to_script (PangoOTTag script_tag);
+PangoOTTag pango_ot_tag_from_script (PangoScript script);
+PangoLanguage* pango_ot_tag_to_language (PangoOTTag language_tag);
+PangoOTTag pango_ot_tag_from_language (PangoLanguage *language);
+
#endif /* PANGO_ENABLE_ENGINE */
G_END_DECLS
diff --git a/pango/pangoft2.def b/pango/pangoft2.def
index 100909b7..826b3f8d 100644
--- a/pango/pangoft2.def
+++ b/pango/pangoft2.def
@@ -62,3 +62,7 @@ EXPORTS
pango_ot_ruleset_new
pango_ot_ruleset_position
pango_ot_ruleset_substitute
+ pango_ot_tag_from_language
+ pango_ot_tag_from_script
+ pango_ot_tag_to_language
+ pango_ot_tag_to_script
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 549b89c4..d05667e3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -44,29 +44,16 @@ check_PROGRAMS = testboundaries testcolor testscript
if HAVE_CAIRO
check_PROGRAMS += testiter
endif
-
-gen_all_unicode_SOURCES = gen-all-unicode.c
-
-testboundaries_SOURCES = testboundaries.c
-
-testcolor_SOURCES = testcolor.c
-
-testiter_SOURCES = testiter.c
-
-testscript_SOURCES = testscript.c
-
-
-dump_boundaries_SOURCES = dump-boundaries.c
+if HAVE_FREETYPE
+check_PROGRAMS += test-ot-tags
+endif
gen_all_unicode_LDADD = $(GLIB_LIBS)
-
testboundaries_LDADD = ../pango/libpango-$(PANGO_API_VERSION).la
-
testcolor_LDADD = ../pango/libpango-$(PANGO_API_VERSION).la
-
testiter_LDADD = ../pango/libpango-$(PANGO_API_VERSION).la ../pango/libpangocairo-$(PANGO_API_VERSION).la
-
testscript_LDADD = ../pango/libpango-$(PANGO_API_VERSION).la
+test_ot_tags_LDADD = ../pango/libpango-$(PANGO_API_VERSION).la ../pango/libpangoft2-$(PANGO_API_VERSION).la
dump_boundaries_LDADD = ../pango/libpango-$(PANGO_API_VERSION).la
diff --git a/tests/test-ot-tags.c b/tests/test-ot-tags.c
new file mode 100644
index 00000000..dbfca369
--- /dev/null
+++ b/tests/test-ot-tags.c
@@ -0,0 +1,131 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* Pango
+ * testscript.c: Test cases for PangoScriptIter
+ *
+ * Copyright (C) 2002 Red Hat Software
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#define PANGO_ENABLE_ENGINE
+#include <pango/pango-ot.h>
+
+#undef VERBOSE
+
+#define ASSERT(stmt) G_STMT_START { \
+ if (stmt) { } \
+ else \
+ { \
+ g_warning ("%s:%d (%s): assertion '%s' failed", \
+ __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, #stmt); \
+ exit (1); \
+ } \
+} G_STMT_END
+
+static void
+test_script_tags (void)
+{
+ gunichar ch;
+ PangoScript i, max_script;
+
+ /* we need to know what the maximum script number is. but we don't
+ * provide an api for that. instead of looking into internal tables,
+ * we'll go over all chars and see what their script is, taking the max!
+ */
+
+ max_script = PANGO_SCRIPT_INVALID_CODE;
+ for (ch = 0; ch <= 0x10FFFF; ch++)
+ max_script = MAX (max_script, pango_script_for_unichar (ch));
+
+ for (i = PANGO_SCRIPT_COMMON; i <= max_script; i++)
+ {
+ PangoOTTag tag = pango_ot_tag_from_script (i);
+ PangoScript j = pango_ot_tag_to_script (tag);
+
+ if (i <= PANGO_SCRIPT_INHERITED || i == PANGO_SCRIPT_UNKNOWN)
+ {
+ ASSERT (tag == PANGO_OT_DEFAULT_SCRIPT);
+ ASSERT (j == PANGO_SCRIPT_COMMON);
+ }
+ else if (tag == FT_MAKE_TAG ('k', 'a', 'n', 'a'))
+ {
+ /* Hiragana and Katakana both map to tag 'kana' */
+ ASSERT (i == PANGO_SCRIPT_HIRAGANA || i == PANGO_SCRIPT_KATAKANA);
+ ASSERT (j == PANGO_SCRIPT_HIRAGANA || j == PANGO_SCRIPT_KATAKANA);
+ }
+ else
+ {
+ if (j != i)
+ g_error ("Got back %d for script %d (OT tag '%c%c%c%c')", j, i,
+ tag>>24, (tag>>16)&255, (tag>>8)&255, tag&255);
+ }
+ }
+
+ ASSERT (pango_ot_tag_to_script (FT_MAKE_TAG ('X', 'Y', 'Z', ' ')) == PANGO_SCRIPT_UNKNOWN);
+}
+
+static void
+test_language_tags (void)
+{
+ /* just test it for a few known languages to make sure it's working */
+ const char languages[][6] = {
+ "xy", /* hopefully nonexistent */
+ "aa",
+ "az_IR",
+ "en",
+ "en_US",
+ "fa",
+ "fa_IR",
+ "fr",
+ "zh_CN",
+ "zu"
+ };
+ unsigned int i;
+
+ for (i = 0; i < G_N_ELEMENTS (languages); i++)
+ {
+ PangoLanguage *l = pango_language_from_string (languages[i]);
+ PangoOTTag tag = pango_ot_tag_from_language (l);
+ PangoLanguage *m = pango_ot_tag_to_language (tag);
+
+ if (i == 0)
+ {
+ ASSERT (tag == PANGO_OT_DEFAULT_LANGUAGE);
+ ASSERT (strcmp (pango_language_to_string (m), "xx") == 0);
+ }
+ else
+ {
+ if (tag == PANGO_OT_DEFAULT_LANGUAGE)
+ g_error ("Got PANGO_OT_DEFAULT_LANGUAGE for language '%s'", pango_language_to_string (l));
+
+ if (!pango_language_matches (l, pango_language_to_string (m)))
+ g_error ("Got back %s for language %s (OT tag '%c%c%c%c')",
+ pango_language_to_string (m), pango_language_to_string (l),
+ tag>>24, (tag>>16)&255, (tag>>8)&255, tag&255);
+ }
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ g_setenv ("PANGO_RC_FILE", "./pangorc", TRUE);
+
+ test_script_tags ();
+ test_language_tags ();
+
+ return 0;
+}