Font

class Font(**properties: Any)

Superclasses: Object

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

Methods

class Font
describe() FontDescription

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

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

describe_with_absolute_size() FontDescription

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

Use describe if you want the font size in points.

Added in version 1.14.

descriptions_free(descs: Sequence[FontDescription] | None = None) None

Frees an array of font descriptions.

Parameters:

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

deserialize(context: Context, bytes: Bytes) Font | None

Loads data previously created via 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.

Added in version 1.50.

Parameters:
  • context – a PangoContext

  • bytes – the bytes containing the data

get_coverage(language: Language) Coverage

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

Parameters:

language – the language tag

get_face() FontFace

Gets the PangoFontFace to which font belongs.

Added in version 1.46.

get_features() tuple[list[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.

Added in version 1.44.

get_font_map() 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.

Added in version 1.10.

get_glyph_extents(glyph: int) 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 ASCENT(), DESCENT(), LBEARING(), and 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() 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.

Added in version 1.50.

get_metrics(language: Language | None = 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(wc: str) bool

Returns whether the font provides a glyph for this character.

Added in version 1.44.

Parameters:

wc – a Unicode character

serialize() 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 deserialize.

Added in version 1.50.

Virtual Methods

class Font
do_create_hb_font() font_t
do_describe() FontDescription

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

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

do_describe_absolute() FontDescription
do_get_coverage(language: Language) Coverage

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

Parameters:

language – the language tag

do_get_features() tuple[list[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.

Added in version 1.44.

do_get_font_map() 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.

Added in version 1.10.

do_get_glyph_extents(glyph: int) 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 ASCENT(), DESCENT(), LBEARING(), and 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(language: Language | None = 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.

Fields

class Font
parent_instance