Skip to content

Pango.Font

class — extends GObject.Object

A PangoFont is used to represent a font in a rendering-system-independent manner.

Methods

describe

def describe(self) -> FontDescription

Returns a description of the font, with font size set in points.

Use Font.describe_with_absolute_size if you want the font size in device units.

describe_with_absolute_size

def describe_with_absolute_size(self) -> FontDescription

Returns a description of the font, with absolute font size set in device units.

Use Font.describe if you want the font size in points.

get_coverage

def get_coverage(self, language: Language) -> Coverage

Computes the coverage map for a given font and language tag.

Parameters:

  • language — the language tag

get_face

def get_face(self) -> FontFace | None

Gets the PangoFontFace to which font belongs.

Note that this function can return NULL in cases where the font outlives its font map.

get_features

def get_features(self, num_features: int) -> tuple[list[HarfBuzz.feature_t], int]

Obtain the OpenType features that are provided by the font.

These are passed to the rendering system, together with features that have been explicitly set via attributes.

Note that this does not include OpenType features which the rendering system enables by default.

Parameters:

  • num_features — the number of used items in features

get_font_map

def get_font_map(self) -> FontMap | None

Gets the font map for which the font was created.

Note that the font maintains a weak reference to the font map, so if all references to font map are dropped, the font map will be finalized even if there are fonts created with the font map that are still alive. In that case this function will return None.

It is the responsibility of the user to ensure that the font map is kept alive. In most uses this is not an issue as a PangoContext holds a reference to the font map.

get_glyph_extents

def get_glyph_extents(self, glyph: Glyph) -> tuple[Rectangle, Rectangle]

Gets the logical and ink extents of a glyph within a font.

The coordinate system for each rectangle has its origin at the base line and horizontal origin of the character with increasing coordinates extending to the right and down. The macros PANGO_ASCENT(), PANGO_DESCENT(), PANGO_LBEARING(), and PANGO_RBEARING() can be used to convert from the extents rectangle to more traditional font metrics. The units of the rectangles are in 1/PANGO_SCALE of a device unit.

If font is None, this function gracefully sets some sane values in the output variables and returns.

Parameters:

  • glyph — the glyph index

get_languages

def get_languages(self) -> list[Language] | None

Returns the languages that are supported by font.

If the font backend does not provide this information, None is returned. For the fontconfig backend, this corresponds to the FC_LANG member of the FcPattern.

The returned array is only valid as long as the font and its fontmap are valid.

get_metrics

def get_metrics(self, language: Language | None = ...) -> FontMetrics

Gets overall metric information for a font.

Since the metrics may be substantially different for different scripts, a language tag can be provided to indicate that the metrics should be retrieved that correspond to the script(s) used by that language.

If font is None, this function gracefully sets some sane values in the output variables and returns.

Parameters:

  • language — language tag used to determine which script to get the metrics for, or None to indicate to get the metrics for the entire font.

has_char

def has_char(self, wc: str) -> bool

Returns whether the font provides a glyph for this character.

Parameters:

  • wc — a Unicode character

serialize

def serialize(self) -> bytes

Serializes the font in a way that can be uniquely identified.

There are no guarantees about the format of the output across different versions of Pango.

The intended use of this function is testing, benchmarking and debugging. The format is not meant as a permanent storage format.

To recreate a font from its serialized form, use Font.deserialize.

Static functions

descriptions_free

@staticmethod
def descriptions_free(descs: list[FontDescription] | None = ...) -> None

:::warning Deprecated since 1.56 This API is deprecated. :::

Frees an array of font descriptions.

Parameters:

  • descs — a pointer to an array of PangoFontDescription, may be None

deserialize

@staticmethod
def deserialize(context: Context, bytes: bytes) -> Font | None

Loads data previously created via Font.serialize.

For a discussion of the supported format, see that function.

Note: to verify that the returned font is identical to the one that was serialized, you can compare bytes to the result of serializing the font again.

Parameters:

  • context — a PangoContext
  • bytes — the bytes containing the data

Virtual methods

do_create_hb_font

def do_create_hb_font(self) -> HarfBuzz.font_t

do_describe

def do_describe(self) -> FontDescription

Returns a description of the font, with font size set in points.

Use Font.describe_with_absolute_size if you want the font size in device units.

do_describe_absolute

def do_describe_absolute(self) -> FontDescription

do_get_coverage

def do_get_coverage(self, language: Language) -> Coverage

Computes the coverage map for a given font and language tag.

Parameters:

  • language — the language tag

do_get_features

def do_get_features(self, num_features: int) -> tuple[list[HarfBuzz.feature_t], int]

Obtain the OpenType features that are provided by the font.

These are passed to the rendering system, together with features that have been explicitly set via attributes.

Note that this does not include OpenType features which the rendering system enables by default.

Parameters:

  • num_features — the number of used items in features

do_get_font_map

def do_get_font_map(self) -> FontMap | None

Gets the font map for which the font was created.

Note that the font maintains a weak reference to the font map, so if all references to font map are dropped, the font map will be finalized even if there are fonts created with the font map that are still alive. In that case this function will return None.

It is the responsibility of the user to ensure that the font map is kept alive. In most uses this is not an issue as a PangoContext holds a reference to the font map.

do_get_glyph_extents

def do_get_glyph_extents(self, glyph: Glyph) -> tuple[Rectangle, Rectangle]

Gets the logical and ink extents of a glyph within a font.

The coordinate system for each rectangle has its origin at the base line and horizontal origin of the character with increasing coordinates extending to the right and down. The macros PANGO_ASCENT(), PANGO_DESCENT(), PANGO_LBEARING(), and PANGO_RBEARING() can be used to convert from the extents rectangle to more traditional font metrics. The units of the rectangles are in 1/PANGO_SCALE of a device unit.

If font is None, this function gracefully sets some sane values in the output variables and returns.

Parameters:

  • glyph — the glyph index

do_get_metrics

def do_get_metrics(self, language: Language | None = ...) -> FontMetrics

Gets overall metric information for a font.

Since the metrics may be substantially different for different scripts, a language tag can be provided to indicate that the metrics should be retrieved that correspond to the script(s) used by that language.

If font is None, this function gracefully sets some sane values in the output variables and returns.

Parameters:

  • language — language tag used to determine which script to get the metrics for, or None to indicate to get the metrics for the entire font.