Pango.Font

g GObject.Object GObject.Object Pango.Font Pango.Font GObject.Object->Pango.Font

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

descriptions_free (descs)

class

deserialize (context, bytes)

describe ()

describe_with_absolute_size ()

get_coverage (language)

get_face ()

get_features (num_features)

get_font_map ()

get_glyph_extents (glyph)

get_languages ()

get_metrics (language)

has_char (wc)

serialize ()

Virtual Methods

Inherited:

GObject.Object (7)

do_create_hb_font ()

do_describe ()

do_describe_absolute ()

do_get_coverage (language)

do_get_features (num_features)

do_get_font_map ()

do_get_glyph_extents (glyph)

do_get_metrics (language)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Pango.Font(**kwargs)
Bases:

GObject.Object

Abstract:

Yes

Structure:

Pango.FontClass

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

classmethod descriptions_free(descs)[source]
Parameters:

descs ([Pango.FontDescription] or None) – a pointer to an array of PangoFontDescription, may be None

Frees an array of font descriptions.

classmethod deserialize(context, bytes)[source]
Parameters:
Raises:

GLib.Error

Returns:

a new PangoFont

Return type:

Pango.Font or None

Loads data previously created via [method`Pango`.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.

New in version 1.50.

describe()[source]
Returns:

a newly-allocated PangoFontDescription object.

Return type:

Pango.FontDescription

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

Use [method`Pango`.Font.describe_with_absolute_size] if you want the font size in device units.

describe_with_absolute_size()[source]
Returns:

a newly-allocated PangoFontDescription object.

Return type:

Pango.FontDescription

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

Use [method`Pango`.Font.describe] if you want the font size in points.

New in version 1.14.

get_coverage(language)[source]
Parameters:

language (Pango.Language) – the language tag

Returns:

a newly-allocated PangoCoverage object.

Return type:

Pango.Coverage

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

get_face()[source]
Returns:

the PangoFontFace

Return type:

Pango.FontFace

Gets the PangoFontFace to which self belongs.

New in version 1.46.

get_features(num_features)[source]
Parameters:

num_features (int) – the number of used items in features

Returns:

features:

Array to features in

num_features:

the number of used items in features

Return type:

(features: [HarfBuzz.feature_t], num_features: 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.

New in version 1.44.

get_font_map()[source]
Returns:

the PangoFontMap for the font

Return type:

Pango.FontMap or 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.

New in version 1.10.

get_glyph_extents(glyph)[source]
Parameters:

glyph (int) – the glyph index

Returns:

ink_rect:

rectangle used to store the extents of the glyph as drawn

logical_rect:

rectangle used to store the logical extents of the glyph

Return type:

(ink_rect: Pango.Rectangle, logical_rect: Pango.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 self is None, this function gracefully sets some sane values in the output variables and returns.

get_languages()[source]
Returns:

an array of PangoLanguage

Return type:

[Pango.Language] or None

Returns the languages that are supported by self.

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.

New in version 1.50.

get_metrics(language)[source]
Parameters:

language (Pango.Language or None) – language tag used to determine which script to get the metrics for, or None to indicate to get the metrics for the entire font.

Returns:

a PangoFontMetrics object. The caller must call [method`Pango`.FontMetrics.unref] when finished using the object.

Return type:

Pango.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 self is None, this function gracefully sets some sane values in the output variables and returns.

has_char(wc)[source]
Parameters:

wc (str) – a Unicode character

Returns:

TRUE if self can render wc

Return type:

bool

Returns whether the font provides a glyph for this character.

New in version 1.44.

serialize()[source]
Returns:

a GBytes containing the serialized form of self

Return type:

GLib.Bytes

Serializes the self 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 [func`Pango`.Font.deserialize].

New in version 1.50.

do_create_hb_font() virtual
Return type:

HarfBuzz.font_t

do_describe() virtual
Returns:

a newly-allocated PangoFontDescription object.

Return type:

Pango.FontDescription

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

Use [method`Pango`.Font.describe_with_absolute_size] if you want the font size in device units.

do_describe_absolute() virtual
Return type:

Pango.FontDescription

do_get_coverage(language) virtual
Parameters:

language (Pango.Language) – the language tag

Returns:

a newly-allocated PangoCoverage object.

Return type:

Pango.Coverage

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

do_get_features(num_features) virtual
Parameters:

num_features (int) – the number of used items in features

Returns:

features:

Array to features in

num_features:

the number of used items in features

Return type:

(features: [HarfBuzz.feature_t], num_features: 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.

New in version 1.44.

do_get_font_map() virtual
Returns:

the PangoFontMap for the font

Return type:

Pango.FontMap or 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.

New in version 1.10.

do_get_glyph_extents(glyph) virtual
Parameters:

glyph (int) – the glyph index

Returns:

ink_rect:

rectangle used to store the extents of the glyph as drawn

logical_rect:

rectangle used to store the logical extents of the glyph

Return type:

(ink_rect: Pango.Rectangle, logical_rect: Pango.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.

do_get_metrics(language) virtual
Parameters:

language (Pango.Language or None) – language tag used to determine which script to get the metrics for, or None to indicate to get the metrics for the entire font.

Returns:

a PangoFontMetrics object. The caller must call [method`Pango`.FontMetrics.unref] when finished using the object.

Return type:

Pango.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.