📄 pango-ot-ruleset.c
字号:
/* Pango * pango-ot-ruleset.c: Shaping using OpenType features * * Copyright (C) 2000 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-private.h"#include "pango-impl-utils.h"typedef struct _PangoOTRule PangoOTRule;struct _PangoOTRule{ gulong property_bit; HB_UShort feature_index; guint table_type : 1;};static void pango_ot_ruleset_class_init (GObjectClass *object_class);static void pango_ot_ruleset_init (PangoOTRuleset *ruleset);static void pango_ot_ruleset_finalize (GObject *object);static GObjectClass *parent_class;GTypepango_ot_ruleset_get_type (void){ static GType object_type = 0; if (G_UNLIKELY (!object_type)) { const GTypeInfo object_info = { sizeof (PangoOTRulesetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc)pango_ot_ruleset_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (PangoOTRuleset), 0, /* n_preallocs */ (GInstanceInitFunc)pango_ot_ruleset_init, NULL /* value_table */ }; object_type = g_type_register_static (G_TYPE_OBJECT, I_("PangoOTRuleset"), &object_info, 0); } return object_type;}static voidpango_ot_ruleset_class_init (GObjectClass *object_class){ parent_class = g_type_class_peek_parent (object_class); object_class->finalize = pango_ot_ruleset_finalize;}static voidpango_ot_ruleset_init (PangoOTRuleset *ruleset){ ruleset->rules = g_array_new (FALSE, FALSE, sizeof (PangoOTRule)); 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;}static voidpango_ot_ruleset_finalize (GObject *object){ PangoOTRuleset *ruleset = PANGO_OT_RULESET (object); g_array_free (ruleset->rules, TRUE); if (ruleset->info) g_object_remove_weak_pointer (G_OBJECT (ruleset->info), &ruleset->info); parent_class->finalize (object);}/** * pango_ot_ruleset_get_for_description: * @info: a #PangoOTInfo. * @desc: a #PangoOTRulesetDescription. * * Returns a ruleset for the given OpenType info and ruleset * description. Rulesets are created on demand using * pango_ot_ruleset_new_from_description(). * The returned ruleset should not be modified or destroyed. * * The static feature map members of @desc should be alive as * long as @info is. * * Return value: the #PangoOTRuleset for @desc. This object will have * the same lifetime as @info. * * Since: 1.18 **/G_CONST_RETURN PangoOTRuleset *pango_ot_ruleset_get_for_description (PangoOTInfo *info, const PangoOTRulesetDescription *desc){ PangoOTRuleset *ruleset; static GQuark rulesets_quark = 0; GHashTable *rulesets; g_return_val_if_fail (info != NULL, NULL); g_return_val_if_fail (desc != NULL, NULL); if (!rulesets_quark) rulesets_quark = g_quark_from_string ("pango-info-rulesets"); rulesets = g_object_get_qdata (G_OBJECT (info), rulesets_quark); if (!rulesets) { rulesets = g_hash_table_new_full ((GHashFunc) pango_ot_ruleset_description_hash, (GEqualFunc) pango_ot_ruleset_description_equal, (GDestroyNotify) pango_ot_ruleset_description_free, (GDestroyNotify) g_object_unref); g_object_set_qdata_full (G_OBJECT (info), rulesets_quark, rulesets, (GDestroyNotify) g_hash_table_destroy); } ruleset = g_hash_table_lookup (rulesets, desc); if (!ruleset) { ruleset = pango_ot_ruleset_new_from_description (info, desc); g_hash_table_insert (rulesets, pango_ot_ruleset_description_copy (desc), ruleset); } return ruleset;}/** * pango_ot_ruleset_new: * @info: a #PangoOTInfo. * * Creates a new #PangoOTRuleset for the given OpenType info. * * Return value: the newly allocated #PangoOTRuleset, which * should be freed with g_object_unref(). **/PangoOTRuleset *pango_ot_ruleset_new (PangoOTInfo *info){ PangoOTRuleset *ruleset; g_return_val_if_fail (PANGO_IS_OT_INFO (info), NULL); ruleset = g_object_new (PANGO_TYPE_OT_RULESET, NULL); ruleset->info = info; g_object_add_weak_pointer (G_OBJECT (ruleset->info), &ruleset->info); 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; PangoOTTag script_tag, language_tag; PangoOTTableType table_type; g_return_val_if_fail (PANGO_IS_OT_INFO (info), NULL); ruleset = pango_ot_ruleset_new (info); 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;}/** * pango_ot_ruleset_new_from_description: * @info: a #PangoOTInfo. * @desc: a #PangoOTRulesetDescription. * * Creates a new #PangoOTRuleset for the given OpenType infor and * matching the given ruleset description. * * This is a convenience function that calls pango_ot_ruleset_new_for() and * adds the static GSUB/GPOS features to the resulting ruleset, followed by * adding other features to both GSUB and GPOS. * * The static feature map members of @desc should be alive as * long as @info is. * * Return value: the newly allocated #PangoOTRuleset, which * should be freed with g_object_unref(). * * Since: 1.18 **/PangoOTRuleset *pango_ot_ruleset_new_from_description (PangoOTInfo *info, const PangoOTRulesetDescription *desc){ PangoOTRuleset *ruleset; g_return_val_if_fail (info != NULL, NULL); g_return_val_if_fail (desc != NULL, NULL); ruleset = pango_ot_ruleset_new_for (info, desc->script, desc->language); if (desc->n_static_gsub_features) pango_ot_ruleset_maybe_add_features (ruleset, PANGO_OT_TABLE_GSUB, desc->static_gsub_features, desc->n_static_gsub_features); if (desc->n_static_gpos_features) pango_ot_ruleset_maybe_add_features (ruleset, PANGO_OT_TABLE_GPOS, desc->static_gpos_features, desc->n_static_gpos_features); if (desc->n_other_features) { pango_ot_ruleset_maybe_add_features (ruleset, PANGO_OT_TABLE_GSUB, desc->other_features, desc->n_other_features); pango_ot_ruleset_maybe_add_features (ruleset, PANGO_OT_TABLE_GPOS, desc->other_features, desc->n_other_features); } return ruleset;}/** * pango_ot_ruleset_add_feature: * @ruleset: a #PangoOTRuleset. * @table_type: the table type to add a feature to. * @feature_index: the index 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. * * Adds a feature to the ruleset. **/voidpango_ot_ruleset_add_feature (PangoOTRuleset *ruleset, PangoOTTableType table_type, guint feature_index, gulong property_bit){ PangoOTRule tmp_rule; g_return_if_fail (PANGO_IS_OT_RULESET (ruleset)); g_return_if_fail (ruleset->info != NULL); 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; g_array_append_val (ruleset->rules, tmp_rule); ruleset->n_features[table_type]++;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -