Ruleset

class Ruleset(**properties: Any)

Superclasses: Object

The PangoOTRuleset structure holds a set of features selected from the tables in an OpenType font.

A feature is an operation such as adjusting glyph positioning that should be applied to a text feature such as a certain type of accent.

A PangoOTRuleset is created with new, features are added to it with add_feature, then it is applied to a PangoGlyphString with position.

Constructors

class Ruleset
classmethod new(info: Info) Ruleset

Creates a new PangoOTRuleset for the given OpenType info.

Parameters:

info – a PangoOTInfo

classmethod new_for(info: Info, script: Script, language: Language) Ruleset

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 addition to what new does, this function will:

  • Find the PangoOTTag script and language tags associated with script and language using tag_from_script and tag_from_language,

  • For each of table types GSUB and 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 find_script and find_language,

  • For found language-systems, if they have required feature index, add that feature to the ruleset using add_feature,

  • Remember found script and language indices for both table types, and use them in future maybe_add_feature and maybe_add_features.

Because of the way return values of find_script and find_language are ignored, this function automatically finds and uses the ‘DFLT’ script and the default language-system.

Added in version 1.18.

Parameters:
  • info – a PangoOTInfo

  • script – a PangoScript

  • language – a PangoLanguage

classmethod new_from_description(info: Info, desc: RulesetDescription) Ruleset

Creates a new PangoOTRuleset for the given OpenType info and matching the given ruleset description.

This is a convenience function that calls 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.

Added in version 1.18.

Parameters:
  • info – a PangoOTInfo

  • desc – a PangoOTRulesetDescription

Methods

class Ruleset
add_feature(table_type: TableType, feature_index: int, property_bit: int) None

Adds a feature to the ruleset.

Parameters:
  • 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 ALL_GLYPHS if it should be applied to all glyphs.

get_feature_count() tuple[int, int, int]

Gets the number of GSUB and GPOS features in the ruleset.

Added in version 1.18.

get_for_description(info: Info, desc: RulesetDescription) Ruleset

Returns a ruleset for the given OpenType info and ruleset description.

Rulesets are created on demand using 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.

Added in version 1.18.

Parameters:
  • info – a PangoOTInfo

  • desc – a PangoOTRulesetDescription

maybe_add_feature(table_type: TableType, feature_tag: int, property_bit: int) bool

This is a convenience function that first tries to find the feature using find_feature and the ruleset script and language passed to new_for and if the feature is found, adds it to the ruleset.

If ruleset was not created using new_for, this function does nothing.

Added in version 1.18.

Parameters:
  • 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 ALL_GLYPHS if it should be applied to all glyphs.

maybe_add_features(table_type: TableType, features: FeatureMap, n_features: int) int

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 TAG_MAKE() and calls maybe_add_feature on it.

Added in version 1.18.

Parameters:
  • 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

position(buffer: Buffer) None

Performs the OpenType GPOS positioning on buffer using the features in ruleset.

Added in version 1.4.

Parameters:

buffer – a PangoOTBuffer

substitute(buffer: Buffer) None

Performs the OpenType GSUB substitution on buffer using the features in ruleset.

Added in version 1.4.

Parameters:

buffer – a PangoOTBuffer