Pango.FontDescription

Fields

None

Methods

class

from_string (str)

class

new ()

better_match (old_match, new_match)

copy ()

copy_static ()

equal (desc2)

free ()

get_family ()

get_gravity ()

get_set_fields ()

get_size ()

get_size_is_absolute ()

get_stretch ()

get_style ()

get_variant ()

get_variations ()

get_weight ()

hash ()

merge (desc_to_merge, replace_existing)

merge_static (desc_to_merge, replace_existing)

set_absolute_size (size)

set_family (family)

set_family_static (family)

set_gravity (gravity)

set_size (size)

set_stretch (stretch)

set_style (style)

set_variant (variant)

set_variations (variations)

set_variations_static (variations)

set_weight (weight)

to_filename ()

to_string ()

unset_fields (to_unset)

Details

class Pango.FontDescription(*args, **kwargs)

A PangoFontDescription describes a font in an implementation-independent manner.

PangoFontDescription structures are used both to list what fonts are available on the system and also for specifying the characteristics of a font to load.

classmethod from_string(str)[source]
Parameters:

str (str) – string representation of a font description.

Returns:

a new PangoFontDescription.

Return type:

Pango.FontDescription

Creates a new font description from a string representation.

The string must have the form

“\[FAMILY-LIST] \[STYLE-OPTIONS] \[SIZE] \[VARIATIONS]”,

where FAMILY-LIST is a comma-separated list of families optionally terminated by a comma, STYLE_OPTIONS is a whitespace-separated list of words where each word describes one of style, variant, weight, stretch, or gravity, and SIZE is a decimal number (size in points) or optionally followed by the unit modifier “px” for absolute size. VARIATIONS is a comma-separated list of font variation specifications of the form “\`axis`=value” (the = sign is optional).

The following words are understood as styles: “Normal”, “Roman”, “Oblique”, “Italic”.

The following words are understood as variants: “Small-Caps”, “All-Small-Caps”, “Petite-Caps”, “All-Petite-Caps”, “Unicase”, “Title-Caps”.

The following words are understood as weights: “Thin”, “Ultra-Light”, “Extra-Light”, “Light”, “Semi-Light”, “Demi-Light”, “Book”, “Regular”, “Medium”, “Semi-Bold”, “Demi-Bold”, “Bold”, “Ultra-Bold”, “Extra-Bold”, “Heavy”, “Black”, “Ultra-Black”, “Extra-Black”.

The following words are understood as stretch values: “Ultra-Condensed”, “Extra-Condensed”, “Condensed”, “Semi-Condensed”, “Semi-Expanded”, “Expanded”, “Extra-Expanded”, “Ultra-Expanded”.

The following words are understood as gravity values: “Not-Rotated”, “South”, “Upside-Down”, “North”, “Rotated-Left”, “East”, “Rotated-Right”, “West”.

Any one of the options may be absent. If FAMILY-LIST is absent, then the family_name field of the resulting font description will be initialized to None. If STYLE-OPTIONS is missing, then all style options will be set to the default values. If SIZE is missing, the size in the resulting font description will be set to 0.

A typical example:

“Cantarell Italic Light 15 \`wght`=200”

classmethod new()[source]
Returns:

the newly allocated PangoFontDescription, which should be freed using [method`Pango`.FontDescription.free].

Return type:

Pango.FontDescription

Creates a new font description structure with all fields unset.

better_match(old_match, new_match)[source]
Parameters:
Returns:

True if new_match is a better match

Return type:

bool

Determines if the style attributes of new_match are a closer match for self than those of old_match are, or if old_match is None, determines if new_match is a match at all.

Approximate matching is done for weight and style; other style attributes must match exactly. Style attributes are all attributes other than family and size-related attributes. Approximate matching for style considers Pango.Style.OBLIQUE and Pango.Style.ITALIC as matches, but not as good a match as when the styles are equal.

Note that old_match must match self.

copy()[source]
Returns:

the newly allocated PangoFontDescription, which should be freed with [method`Pango`.FontDescription.free], or None if self was None.

Return type:

Pango.FontDescription or None

Make a copy of a PangoFontDescription.

copy_static()[source]
Returns:

the newly allocated PangoFontDescription, which should be freed with [method`Pango`.FontDescription.free], or None if self was None.

Return type:

Pango.FontDescription or None

Make a copy of a PangoFontDescription, but don’t duplicate allocated fields.

This is like [method`Pango`.FontDescription.copy], but only a shallow copy is made of the family name and other allocated fields. The result can only be used until self is modified or freed. This is meant to be used when the copy is only needed temporarily.

equal(desc2)[source]
Parameters:

desc2 (Pango.FontDescription) – another PangoFontDescription

Returns:

True if the two font descriptions are identical, False otherwise.

Return type:

bool

Compares two font descriptions for equality.

Two font descriptions are considered equal if the fonts they describe are provably identical. This means that their masks do not have to match, as long as other fields are all the same. (Two font descriptions may result in identical fonts being loaded, but still compare False.)

free()[source]

Frees a font description.

get_family()[source]
Returns:

the family name field for the font description, or None if not previously set. This has the same life-time as the font description itself and should not be freed.

Return type:

str or None

Gets the family name field of a font description.

See [method`Pango`.FontDescription.set_family].

get_gravity()[source]
Returns:

the gravity field for the font description. Use [method`Pango`.FontDescription.get_set_fields] to find out if the field was explicitly set or not.

Return type:

Pango.Gravity

Gets the gravity field of a font description.

See [method`Pango`.FontDescription.set_gravity].

New in version 1.16.

get_set_fields()[source]
Returns:

a bitmask with bits set corresponding to the fields in self that have been set.

Return type:

Pango.FontMask

Determines which fields in a font description have been set.

get_size()[source]
Returns:

the size field for the font description in points or device units. You must call [method`Pango`.FontDescription.get_size_is_absolute] to find out which is the case. Returns 0 if the size field has not previously been set or it has been set to 0 explicitly. Use [method`Pango`.FontDescription.get_set_fields] to find out if the field was explicitly set or not.

Return type:

int

Gets the size field of a font description.

See [method`Pango`.FontDescription.set_size].

get_size_is_absolute()[source]
Returns:

whether the size for the font description is in points or device units. Use [method`Pango`.FontDescription.get_set_fields] to find out if the size field of the font description was explicitly set or not.

Return type:

bool

Determines whether the size of the font is in points (not absolute) or device units (absolute).

See [method`Pango`.FontDescription.set_size] and [method`Pango`.FontDescription.set_absolute_size].

New in version 1.8.

get_stretch()[source]
Returns:

the stretch field for the font description. Use [method`Pango`.FontDescription.get_set_fields] to find out if the field was explicitly set or not.

Return type:

Pango.Stretch

Gets the stretch field of a font description.

See [method`Pango`.FontDescription.set_stretch].

get_style()[source]
Returns:

the style field for the font description. Use [method`Pango`.FontDescription.get_set_fields] to find out if the field was explicitly set or not.

Return type:

Pango.Style

Gets the style field of a PangoFontDescription.

See [method`Pango`.FontDescription.set_style].

get_variant()[source]
Returns:

the variant field for the font description. Use [method`Pango`.FontDescription.get_set_fields] to find out if the field was explicitly set or not.

Return type:

Pango.Variant

Gets the variant field of a PangoFontDescription.

See [method`Pango`.FontDescription.set_variant].

get_variations()[source]
Returns:

the variations field for the font description, or None if not previously set. This has the same life-time as the font description itself and should not be freed.

Return type:

str or None

Gets the variations field of a font description.

See [method`Pango`.FontDescription.set_variations].

New in version 1.42.

get_weight()[source]
Returns:

the weight field for the font description. Use [method`Pango`.FontDescription.get_set_fields] to find out if the field was explicitly set or not.

Return type:

Pango.Weight

Gets the weight field of a font description.

See [method`Pango`.FontDescription.set_weight].

hash()[source]
Returns:

the hash value.

Return type:

int

Computes a hash of a PangoFontDescription structure.

This is suitable to be used, for example, as an argument to g_hash_table_new(). The hash value is independent of self->mask.

merge(desc_to_merge, replace_existing)[source]
Parameters:
  • desc_to_merge (Pango.FontDescription or None) – the PangoFontDescription to merge from, or None

  • replace_existing (bool) – if True, replace fields in self with the corresponding values from desc_to_merge, even if they are already exist.

Merges the fields that are set in desc_to_merge into the fields in self.

If replace_existing is False, only fields in self that are not already set are affected. If True, then fields that are already set will be replaced as well.

If desc_to_merge is None, this function performs nothing.

merge_static(desc_to_merge, replace_existing)[source]
Parameters:
  • desc_to_merge (Pango.FontDescription) – the PangoFontDescription to merge from

  • replace_existing (bool) – if True, replace fields in self with the corresponding values from desc_to_merge, even if they are already exist.

Merges the fields that are set in desc_to_merge into the fields in self, without copying allocated fields.

This is like [method`Pango`.FontDescription.merge], but only a shallow copy is made of the family name and other allocated fields. self can only be used until desc_to_merge is modified or freed. This is meant to be used when the merged font description is only needed temporarily.

set_absolute_size(size)[source]
Parameters:

size (float) – the new size, in Pango units. There are Pango.SCALE Pango units in one device unit. For an output backend where a device unit is a pixel, a size value of 10 * Pango.SCALE gives a 10 pixel font.

Sets the size field of a font description, in device units.

This is mutually exclusive with [method`Pango`.FontDescription.set_size] which sets the font size in points.

New in version 1.8.

set_family(family)[source]
Parameters:

family (str) – a string representing the family name.

Sets the family name field of a font description.

The family name represents a family of related font styles, and will resolve to a particular PangoFontFamily. In some uses of PangoFontDescription, it is also possible to use a comma separated list of family names for this field.

set_family_static(family)[source]
Parameters:

family (str) – a string representing the family name

Sets the family name field of a font description, without copying the string.

This is like [method`Pango`.FontDescription.set_family], except that no copy of family is made. The caller must make sure that the string passed in stays around until self has been freed or the name is set again. This function can be used if family is a static string such as a C string literal, or if self is only needed temporarily.

set_gravity(gravity)[source]
Parameters:

gravity (Pango.Gravity) – the gravity for the font description.

Sets the gravity field of a font description.

The gravity field specifies how the glyphs should be rotated. If gravity is Pango.Gravity.AUTO, this actually unsets the gravity mask on the font description.

This function is seldom useful to the user. Gravity should normally be set on a PangoContext.

New in version 1.16.

set_size(size)[source]
Parameters:

size (int) – the size of the font in points, scaled by Pango.SCALE. (That is, a size value of 10 * Pango.SCALE is a 10 point font. The conversion factor between points and device units depends on system configuration and the output device. For screen display, a logical DPI of 96 is common, in which case a 10 point font corresponds to a 10 * (96 / 72) = 13.3 pixel font. Use [method`Pango`.FontDescription.set_absolute_size] if you need a particular size in device units.

Sets the size field of a font description in fractional points.

This is mutually exclusive with [method`Pango`.FontDescription.set_absolute_size].

set_stretch(stretch)[source]
Parameters:

stretch (Pango.Stretch) – the stretch for the font description

Sets the stretch field of a font description.

The [enum`Pango`.Stretch] field specifies how narrow or wide the font should be.

set_style(style)[source]
Parameters:

style (Pango.Style) – the style for the font description

Sets the style field of a PangoFontDescription.

The [enum`Pango`.Style] enumeration describes whether the font is slanted and the manner in which it is slanted; it can be either Pango.Style.NORMAL, Pango.Style.ITALIC, or Pango.Style.OBLIQUE.

Most fonts will either have a italic style or an oblique style, but not both, and font matching in Pango will match italic specifications with oblique fonts and vice-versa if an exact match is not found.

set_variant(variant)[source]
Parameters:

variant (Pango.Variant) – the variant type for the font description.

Sets the variant field of a font description.

The [enum`Pango`.Variant] can either be Pango.Variant.NORMAL or Pango.Variant.SMALL_CAPS.

set_variations(variations)[source]
Parameters:

variations (str or None) – a string representing the variations

Sets the variations field of a font description.

OpenType font variations allow to select a font instance by specifying values for a number of axes, such as width or weight.

The format of the variations string is

AXIS1=VALUE,AXIS2=VALUE…

with each AXIS a 4 character tag that identifies a font axis, and each VALUE a floating point number. Unknown axes are ignored, and values are clamped to their allowed range.

Pango does not currently have a way to find supported axes of a font. Both harfbuzz and freetype have API for this. See for example hb_ot_var_get_axis_infos.

New in version 1.42.

set_variations_static(variations)[source]
Parameters:

variations (str) – a string representing the variations

Sets the variations field of a font description.

This is like [method`Pango`.FontDescription.set_variations], except that no copy of variations is made. The caller must make sure that the string passed in stays around until self has been freed or the name is set again. This function can be used if variations is a static string such as a C string literal, or if self is only needed temporarily.

New in version 1.42.

set_weight(weight)[source]
Parameters:

weight (Pango.Weight) – the weight for the font description.

Sets the weight field of a font description.

The weight field specifies how bold or light the font should be. In addition to the values of the [enum`Pango`.Weight] enumeration, other intermediate numeric values are possible.

to_filename()[source]
Returns:

a new string that must be freed with GLib.free().

Return type:

str or None

Creates a filename representation of a font description.

The filename is identical to the result from calling [method`Pango`.FontDescription.to_string], but with underscores instead of characters that are untypical in filenames, and in lower case only.

to_string()[source]
Returns:

a new string that must be freed with GLib.free().

Return type:

str

Creates a string representation of a font description.

See [func`Pango`.FontDescription.from_string] for a description of the format of the string representation. The family list in the string description will only have a terminating comma if the last word of the list is a valid style option.

unset_fields(to_unset)[source]
Parameters:

to_unset (Pango.FontMask) – bitmask of fields in the self to unset.

Unsets some of the fields in a PangoFontDescription.

The unset fields will get back to their default values.