Font#
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.
- classmethod deserialize(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:
bytes – the bytes containing the data
- do_describe(self) FontDescription #
- do_describe_absolute(self) FontDescription #
- do_get_metrics(self, language: Language | None = None) FontMetrics #
- Parameters:
language
- get_coverage(language: Language) Coverage #
Computes the coverage map for a given font and language tag.
- Parameters:
language – the language tag
- get_features(num_features: int) 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.
- Parameters:
num_features – the number of used items in
features
- 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()
, andRBEARING()
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
isNone
, 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
isNone
, 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_describe(type, self) 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.- Parameters:
type
self
- do_describe_absolute(type, self) FontDescription #
The type of the None singleton.
- Parameters:
type
self
- do_get_coverage(type, self, language: Language) Coverage #
Computes the coverage map for a given font and language tag.
- Parameters:
type
self
language – the language tag
- do_get_features(type, self, num_features: int) 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.
- Parameters:
type
self
num_features – the number of used items in
features
- do_get_font_map(type, 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.Added in version 1.10.
- Parameters:
type
self
- do_get_glyph_extents(type, self, 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()
, andRBEARING()
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
isNone
, this function gracefully sets some sane values in the output variables and returns.- Parameters:
type
self
glyph – the glyph index
- do_get_metrics(type, self, 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
isNone
, this function gracefully sets some sane values in the output variables and returns.- Parameters:
type
self
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#