summaryrefslogtreecommitdiff
path: root/pango/pango-ot-ruleset.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2007-05-14 04:02:58 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2007-05-14 04:02:58 +0000
commit5268099b137dee60aacc04cbeb5051242c35b256 (patch)
treec974955ad45cabb06fd7166f7507c1ba8541e547 /pango/pango-ot-ruleset.c
parent9f09571a932149e77ceeb7ccec8bd7bdea6aac4a (diff)
downloadpango-5268099b137dee60aacc04cbeb5051242c35b256.tar.gz
Part of Bug 325714 – Pango should respect $LANGUAGE
2007-05-13 Behdad Esfahbod <behdad@gnome.org> Part of Bug 325714 – Pango should respect $LANGUAGE * pango/pango-ot.h: * pango/pango-ot-private.h: * pango/pango-ot-tag.c (pango_ot_tag_from_script), (pango_ot_tag_from_language): * pango/pango-ot-info.c (pango_ot_info_find_script), (pango_ot_info_find_language), (pango_ot_info_find_feature), (pango_ot_info_list_languages), (pango_ot_info_list_features): * pango/pango-ot-ruleset.c (pango_ot_ruleset_new), (pango_ot_ruleset_new_for), (pango_ot_ruleset_add_feature), (pango_ot_ruleset_maybe_add_feature), (pango_ot_ruleset_maybe_add_features): Add new engine API: PANGO_OT_NO_FEATURE PANGO_OT_NO_SCRIPT PANGO_OT_TAG_DEFAULT_SCRIPT PANGO_OT_TAG_DEFAULT_LANGUAGE pango_ot_ruleset_new_for() pango_ot_ruleset_maybe_add_feature() pango_ot_ruleset_maybe_add_features() Using pango_ot_ruleset_new_for() and pango_ot_ruleset_maybe_add_features() drastically simplifies ruleset building in modules, and does correct script and language selection too. Modules need to be updated to use it though. * docs/pango-docs.sgml: * docs/pango-sections.txt: * docs/tmpl/opentype.sgml: Update. svn path=/trunk/; revision=2284
Diffstat (limited to 'pango/pango-ot-ruleset.c')
-rw-r--r--pango/pango-ot-ruleset.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/pango/pango-ot-ruleset.c b/pango/pango-ot-ruleset.c
index a54c87ef..75896f56 100644
--- a/pango/pango-ot-ruleset.c
+++ b/pango/pango-ot-ruleset.c
@@ -115,6 +115,94 @@ pango_ot_ruleset_new (PangoOTInfo *info)
ruleset->info = info;
g_object_add_weak_pointer (ruleset->info, &ruleset->info);
+ ruleset->script_index[0] = PANGO_OT_NO_SCRIPT;
+ ruleset->script_index[1] = PANGO_OT_NO_SCRIPT;
+ ruleset->language_index[0] = PANGO_OT_DEFAULT_LANGUAGE;
+ ruleset->language_index[1] = PANGO_OT_DEFAULT_LANGUAGE;
+
+ return ruleset;
+}
+
+/**
+ * pango_ot_ruleset_new_for:
+ * @info: a #PangoOTInfo.
+ * @script: a #PangoScript.
+ * @language: a #PangoLanguage.
+ *
+ * Creates a new #PangoOTRuleset for the given OpenType info, script, and
+ * language.
+ *
+ * This function is part of a convenience scheme that highly simplifies
+ * using a #PangoOTRuleset to represent features for a specific pair of script
+ * and language. So one can use this function passing in the script and
+ * language of interest, and later try to add features to the ruleset by just
+ * specifying the feature name or tag, without having to deal with finding
+ * script, language, or feature indices manually.
+ *
+ * In excess to what pango_ot_ruleset_new() does, this function will:
+ * <itemizedlist>
+ * <listitem>
+ * Find the #PangoOTTag script and language tags associated with
+ * @script and @language using pango_ot_tag_from_script() and
+ * pango_ot_tag_from_language(),
+ * </listitem>
+ * <listitem>
+ * For each of table types %PANGO_OT_TABLE_GSUB and %PANGO_OT_TABLE_GPOS,
+ * find the script index of the script tag found and the language
+ * system index of the language tag found in that script system, using
+ * pango_ot_info_find_script() and pango_ot_info_find_language(),
+ * </listitem>
+ * <listitem>
+ * For found language-systems, if they have required feature
+ * index, add that feature to the ruleset using
+ * pango_ot_ruleset_add_feature(),
+ * </listitem>
+ * <listitem>
+ * Remember found script and language indices for both table types,
+ * and use them in future pango_ot_ruleset_maybe_add_feature() and
+ * pango_ot_ruleset_maybe_add_features().
+ * </listitem>
+ * </itemizedlist>
+ *
+ * Because of the way return values of pango_ot_info_find_script() and
+ * pango_ot_info_find_language() are ignored, this function automatically
+ * finds and uses the 'DFLT' script and the default language-system.
+ *
+ * Return value: the newly allocated #PangoOTRuleset, which
+ * should be freed with g_object_unref().
+ *
+ * Since: 1.18
+ **/
+PangoOTRuleset *
+pango_ot_ruleset_new_for (PangoOTInfo *info,
+ PangoScript script,
+ PangoLanguage *language)
+{
+ PangoOTRuleset *ruleset = pango_ot_ruleset_new (info);
+ PangoOTTag script_tag, language_tag;
+ PangoOTTableType table_type;
+
+ script_tag = pango_ot_tag_from_script (script);
+ language_tag = pango_ot_tag_from_language (language);
+
+ for (table_type = PANGO_OT_TABLE_GSUB; table_type <= PANGO_OT_TABLE_GPOS; table_type++)
+ {
+ guint script_index, language_index, feature_index;
+
+ pango_ot_info_find_script (ruleset->info, table_type,
+ script_tag, &script_index);
+ pango_ot_info_find_language (ruleset->info, table_type, script_index,
+ language_tag, &language_index,
+ &feature_index);
+
+ ruleset->script_index[table_type] = script_index;
+ ruleset->language_index[table_type] = language_index;
+
+ /* add required feature of the language */
+ pango_ot_ruleset_add_feature (ruleset, table_type,
+ feature_index, PANGO_OT_ALL_GLYPHS);
+ }
+
return ruleset;
}
@@ -140,6 +228,9 @@ pango_ot_ruleset_add_feature (PangoOTRuleset *ruleset,
g_return_if_fail (PANGO_IS_OT_RULESET (ruleset));
g_return_if_fail (PANGO_IS_OT_INFO (ruleset->info));
+ if (feature_index == PANGO_OT_NO_FEATURE)
+ return;
+
tmp_rule.table_type = table_type;
tmp_rule.feature_index = feature_index;
tmp_rule.property_bit = property_bit;
@@ -148,6 +239,99 @@ pango_ot_ruleset_add_feature (PangoOTRuleset *ruleset,
}
/**
+ * pango_ot_ruleset_maybe_add_feature:
+ * @ruleset: a #PangoOTRuleset.
+ * @table_type: the table type to add a feature to.
+ * @feature_tag: the tag of the feature to add.
+ * @property_bit: the property bit to use for this feature. Used to identify
+ * the glyphs that this feature should be applied to, or
+ * %PANGO_OT_ALL_GLYPHS if it should be applied to all glyphs.
+ *
+ * This is a convenience function that first tries to find the feature
+ * using pango_ot_info_find_feature() and the ruleset script and language
+ * passed to pango_ot_ruleset_new_for(),
+ * and if the feature is found, adds it to the ruleset.
+ *
+ * If @ruleset was not created using pango_ot_ruleset_new_for(), this function
+ * does nothing.
+ *
+ * Return value: %TRUE if the feature was found and added to ruleset,
+ * %FALSE otherwise.
+ *
+ * Since: 1.18
+ **/
+gboolean
+pango_ot_ruleset_maybe_add_feature (PangoOTRuleset *ruleset,
+ PangoOTTableType table_type,
+ PangoOTTag feature_tag,
+ gulong property_bit)
+{
+ guint feature_index;
+
+ g_return_val_if_fail (PANGO_IS_OT_RULESET (ruleset), FALSE);
+ g_return_val_if_fail (PANGO_IS_OT_INFO (ruleset->info), FALSE);
+
+ pango_ot_info_find_feature (ruleset->info, table_type,
+ feature_tag,
+ ruleset->script_index[table_type],
+ ruleset->language_index[table_type],
+ &feature_index);
+
+ if (feature_index != PANGO_OT_NO_FEATURE)
+ {
+ pango_ot_ruleset_add_feature (ruleset, table_type,
+ feature_index, property_bit);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/**
+ * pango_ot_ruleset_maybe_add_features:
+ * @ruleset: a #PangoOTRuleset.
+ * @table_type: the table type to add features to.
+ * @features: array of feature name and property bits to add.
+ * @n_features: number of feature records in @features array.
+ *
+ * This is a convenience function that
+ * for each feature in the feature map array @features
+ * converts the feature name to a #PangoOTTag feature tag using FT_MAKE_TAG()
+ * and calls pango_ot_ruleset_maybe_add_feature() on it.
+ *
+ * Return value: The number of features in @features that were found
+ * and added to @ruleset.
+ *
+ * Since: 1.18
+ **/
+int
+pango_ot_ruleset_maybe_add_features (PangoOTRuleset *ruleset,
+ PangoOTTableType table_type,
+ const PangoOTFeatureMap *features,
+ int n_features)
+{
+ int i, n_found_features = 0;
+
+ g_return_val_if_fail (PANGO_IS_OT_RULESET (ruleset), 0);
+ g_return_val_if_fail (PANGO_IS_OT_INFO (ruleset->info), 0);
+
+ for (i = 0; i < n_features; i++)
+ {
+ PangoOTTag feature_tag = FT_MAKE_TAG (features[i].feature_name[0],
+ features[i].feature_name[1],
+ features[i].feature_name[2],
+ features[i].feature_name[3]);
+
+ n_found_features += pango_ot_ruleset_maybe_add_feature (ruleset,
+ table_type,
+ feature_tag,
+ features[i].property_bit);
+ }
+
+ return n_found_features;
+}
+
+/**
* pango_ot_ruleset_substitute:
* @ruleset: a #PangoOTRuleset.
* @buffer: a #PangoOTBuffer.