📄 pango-ot-ruleset.c
字号:
/** * 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 **/gbooleanpango_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 (ruleset->info != NULL, 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 **/guintpango_ot_ruleset_maybe_add_features (PangoOTRuleset *ruleset, PangoOTTableType table_type, const PangoOTFeatureMap *features, guint n_features){ guint i, n_found_features = 0; g_return_val_if_fail (PANGO_IS_OT_RULESET (ruleset), 0); g_return_val_if_fail (ruleset->info != NULL, 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_get_feature_count: * @ruleset: a #PangoOTRuleset. * @n_gsub_features: location to store number of GSUB features, or %NULL. * @n_gpos_features: location to store number of GPOS features, or %NULL. * * Gets the number of GSUB and GPOS features in the ruleset. * * Return value: Total number of features in the @ruleset. * * Since: 1.18 **/guintpango_ot_ruleset_get_feature_count (const PangoOTRuleset *ruleset, guint *n_gsub_features, guint *n_gpos_features){ g_return_val_if_fail (PANGO_IS_OT_RULESET (ruleset), 0); if (n_gsub_features) *n_gsub_features = ruleset->n_features[PANGO_OT_TABLE_GSUB]; if (n_gpos_features) *n_gpos_features = ruleset->n_features[PANGO_OT_TABLE_GPOS]; return ruleset->n_features[PANGO_OT_TABLE_GSUB] + ruleset->n_features[PANGO_OT_TABLE_GPOS];}/** * pango_ot_ruleset_substitute: * @ruleset: a #PangoOTRuleset. * @buffer: a #PangoOTBuffer. * * Performs the OpenType GSUB substitution on @buffer using the features * in @ruleset * * Since: 1.4 **/voidpango_ot_ruleset_substitute (const PangoOTRuleset *ruleset, PangoOTBuffer *buffer){ unsigned int i; HB_GSUB gsub = NULL; g_return_if_fail (PANGO_IS_OT_RULESET (ruleset)); g_return_if_fail (ruleset->info != NULL); for (i = 0; i < ruleset->rules->len; i++) { PangoOTRule *rule = &g_array_index (ruleset->rules, PangoOTRule, i); if (rule->table_type != PANGO_OT_TABLE_GSUB) continue; if (!gsub) { gsub = pango_ot_info_get_gsub (ruleset->info); if (gsub) HB_GSUB_Clear_Features (gsub); else return; } HB_GSUB_Add_Feature (gsub, rule->feature_index, rule->property_bit); } HB_GSUB_Apply_String (gsub, buffer->buffer);}/** * pango_ot_ruleset_position: * @ruleset: a #PangoOTRuleset. * @buffer: a #PangoOTBuffer. * * Performs the OpenType GPOS positioning on @buffer using the features * in @ruleset * * Since: 1.4 **/voidpango_ot_ruleset_position (const PangoOTRuleset *ruleset, PangoOTBuffer *buffer){ unsigned int i; HB_GPOS gpos = NULL; g_return_if_fail (PANGO_IS_OT_RULESET (ruleset)); g_return_if_fail (ruleset->info != NULL); for (i = 0; i < ruleset->rules->len; i++) { PangoOTRule *rule = &g_array_index (ruleset->rules, PangoOTRule, i); if (rule->table_type != PANGO_OT_TABLE_GPOS) continue; if (!gpos) { gpos = pango_ot_info_get_gpos (ruleset->info); if (gpos) HB_GPOS_Clear_Features (gpos); else return; } HB_GPOS_Add_Feature (gpos, rule->feature_index, rule->property_bit); } if (HB_GPOS_Apply_String (ruleset->info->face, gpos, 0, buffer->buffer, FALSE /* enable device-dependant values */, buffer->rtl) == FT_Err_Ok) buffer->applied_gpos = TRUE;}/* ruleset descriptions *//** * pango_ot_ruleset_description_hash: * @desc: a ruleset description * * Computes a hash of a #PangoOTRulesetDescription structure suitable * to be used, for example, as an argument to g_hash_table_new(). * * Return value: the hash value. * * Since: 1.18 **/guintpango_ot_ruleset_description_hash (const PangoOTRulesetDescription *desc){ guint hash = 0; guint i; hash ^= desc->script; hash ^= GPOINTER_TO_UINT (desc->language); hash ^= desc->n_static_gsub_features << 8; hash ^= GPOINTER_TO_UINT (desc->static_gsub_features); hash ^= desc->n_static_gpos_features << 12; hash ^= GPOINTER_TO_UINT (desc->static_gpos_features); hash ^= desc->n_other_features << 16; for (i = 0; i < desc->n_other_features; i++) { hash ^= * (guint32 *) desc->other_features[i].feature_name; hash ^= desc->other_features[i].property_bit; } return hash;}/** * pango_ot_ruleset_description_equal: * @desc1: a ruleset description * @desc2: a ruleset description * * Compares two ruleset descriptions for equality. * Two ruleset descriptions are considered equal if the rulesets * they describe are provably identical. This means that their * script, language, and all feature sets should be equal. For static feature * sets, the array addresses are compared directly, while for other * features, the list of features is compared one by one. * (Two ruleset descriptions may result in identical rulesets * being created, but still compare %FALSE.) * * Return value: %TRUE if two ruleset descriptions are identical, * %FALSE otherwise. * * Since: 1.18 **/gbooleanpango_ot_ruleset_description_equal (const PangoOTRulesetDescription *desc1, const PangoOTRulesetDescription *desc2){ guint i;#undef CHECK#define CHECK(x) if (desc1->x != desc2->x) return FALSE;#define CHECK_FEATURE_NAME(x) if (*(guint32 *)desc1->x != *(guint32 *)desc2->x) return FALSE CHECK (script); CHECK (language); CHECK (static_gsub_features); CHECK (n_static_gsub_features); CHECK (static_gpos_features); CHECK (n_static_gpos_features); CHECK (n_other_features); for (i = 0; i < desc1->n_other_features; i++) { CHECK_FEATURE_NAME (other_features[i].feature_name); CHECK (other_features[i].property_bit); }#undef CHECK return TRUE;}/** * pango_ot_ruleset_description_copy: * @desc: ruleset description to copy * * Creates a copy of @desc, which should be freed with * pango_ot_ruleset_description_free(). Primarily used internally * by pango_ot_ruleset_get_for_description() to cache rulesets for * ruleset descriptions. * * Return value: the newly allocated #PangoOTRulesetDescription, which * should be freed with pango_ot_ruleset_description_free(). * * Since: 1.18 **/PangoOTRulesetDescription *pango_ot_ruleset_description_copy (const PangoOTRulesetDescription *desc){ PangoOTRulesetDescription *copy; g_return_val_if_fail (desc != NULL, NULL); copy = g_slice_new (PangoOTRulesetDescription); *copy = *desc; if (desc->n_other_features) { PangoOTFeatureMap *map = g_new (PangoOTFeatureMap, desc->n_other_features); memcpy (map, desc->other_features, desc->n_other_features * sizeof (PangoOTFeatureMap)); copy->other_features = map; } else { copy->other_features = NULL; } return copy;}/** * pango_ot_ruleset_description_free: * @desc: an allocated #PangoOTRulesetDescription * * Frees a ruleset description allocated by * pango_ot_ruleset_description_copy(). * * Since: 1.18 **/voidpango_ot_ruleset_description_free (PangoOTRulesetDescription *desc){ g_return_if_fail (desc != NULL); free ((gpointer) desc->other_features); g_slice_free (PangoOTRulesetDescription, desc);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -