Skip to content

Pango.FontMap

class — extends GObject.Object, Gio.ListModel

A PangoFontMap represents the set of fonts available for a particular rendering system.

This is a virtual object with implementations being specific to particular rendering systems.

Methods

add_font_file

def add_font_file(self, filename: str | bytes | os.PathLike[str] | os.PathLike[bytes]) -> bool

Loads a font file with one or more fonts into the PangoFontMap.

The added fonts will take precedence over preexisting fonts with the same name.

Parameters:

  • filename — Path to the font file

changed

def changed(self) -> None

Forces a change in the fontmap, which will cause any PangoContext using this fontmap to change.

This function is only useful when implementing a new backend for Pango, something applications won't do. Backends should call this function if they have attached extra data to the fontmap and such data is changed.

create_context

def create_context(self) -> Context

Creates a PangoContext connected to fontmap.

This is equivalent to Context.new followed by Context.set_font_map.

If you are using Pango as part of a higher-level system, that system may have it's own way of create a PangoContext. For instance, the GTK toolkit has, among others, Gtk.Widget.get_pango_context. Use those instead.

get_family

def get_family(self, name: str) -> FontFamily | None

Gets a font family by name.

Parameters:

  • name — a family name

get_serial

def get_serial(self) -> int

Returns the current serial number of fontmap.

The serial number is initialized to an small number larger than zero when a new fontmap is created and is increased whenever the fontmap is changed. It may wrap, but will never have the value 0. Since it can wrap, never compare it with "less than", always use "not equals".

The fontmap can only be changed using backend-specific API, like changing fontmap resolution.

This can be used to automatically detect changes to a PangoFontMap, like in PangoContext.

list_families

def list_families(self) -> list[FontFamily]

List all families for a fontmap.

Note that the returned families are not in any particular order.

PangoFontMap also implemented the Gio.ListModel interface for enumerating families.

load_font

def load_font(self, context: Context, desc: FontDescription) -> Font | None

Load the font in the fontmap that is the closest match for desc.

Parameters:

  • context — the PangoContext the font will be used with
  • desc — a PangoFontDescription describing the font to load

load_fontset

def load_fontset(self, context: Context, desc: FontDescription, language: Language) -> Fontset | None

Load a set of fonts in the fontmap that can be used to render a font matching desc.

Parameters:

  • context — the PangoContext the font will be used with
  • desc — a PangoFontDescription describing the font to load
  • language — a PangoLanguage the fonts will be used for

reload_font

def reload_font(self, font: Font, scale: float, context: Context | None = ..., variations: str | None = ...) -> Font

Returns a new font that is like font, except that it is scaled by scale, its backend-dependent configuration (e.g. cairo font options) is replaced by the one in context, and its variations are replaced by variations.

Note that the scaling here is meant to be linear, so this scaling can be used to render a font on a hi-dpi display without changing its optical size.

Parameters:

  • font — a font in fontmap
  • scale — the scale factor to apply
  • context — a PangoContext
  • variations — font variations to use

Virtual methods

do_changed

def do_changed(self) -> None

Forces a change in the fontmap, which will cause any PangoContext using this fontmap to change.

This function is only useful when implementing a new backend for Pango, something applications won't do. Backends should call this function if they have attached extra data to the fontmap and such data is changed.

do_get_family

def do_get_family(self, name: str) -> FontFamily | None

Gets a font family by name.

Parameters:

  • name — a family name

do_get_serial

def do_get_serial(self) -> int

Returns the current serial number of fontmap.

The serial number is initialized to an small number larger than zero when a new fontmap is created and is increased whenever the fontmap is changed. It may wrap, but will never have the value 0. Since it can wrap, never compare it with "less than", always use "not equals".

The fontmap can only be changed using backend-specific API, like changing fontmap resolution.

This can be used to automatically detect changes to a PangoFontMap, like in PangoContext.

do_list_families

def do_list_families(self) -> list[FontFamily]

List all families for a fontmap.

Note that the returned families are not in any particular order.

PangoFontMap also implemented the Gio.ListModel interface for enumerating families.

do_load_font

def do_load_font(self, context: Context, desc: FontDescription) -> Font | None

Load the font in the fontmap that is the closest match for desc.

Parameters:

  • context — the PangoContext the font will be used with
  • desc — a PangoFontDescription describing the font to load

do_load_fontset

def do_load_fontset(self, context: Context, desc: FontDescription, language: Language) -> Fontset | None

Load a set of fonts in the fontmap that can be used to render a font matching desc.

Parameters:

  • context — the PangoContext the font will be used with
  • desc — a PangoFontDescription describing the font to load
  • language — a PangoLanguage the fonts will be used for

Properties

item_type

item_type: type | GObject.Type  # read-only

The type of items contained in this list.

n_items

n_items: int  # read-only

The number of items contained in this list.