Skip to content

Pango.FontMetrics

record (struct)

A PangoFontMetrics structure holds the overall metric information for a font.

The information in a PangoFontMetrics structure may be restricted to a script. The fields of this structure are private to implementations of a font backend. See the documentation of the corresponding getters for documentation of their meaning.

For an overview of the most important metrics, see:

<picture> <source srcset="fontmetrics-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Font metrics" src="fontmetrics-light.png"> </picture>

Methods

get_approximate_char_width

def get_approximate_char_width(self) -> int

Gets the approximate character width for a font metrics structure.

This is merely a representative value useful, for example, for determining the initial size for a window. Actual characters in text will be wider and narrower than this.

get_approximate_digit_width

def get_approximate_digit_width(self) -> int

Gets the approximate digit width for a font metrics structure.

This is merely a representative value useful, for example, for determining the initial size for a window. Actual digits in text can be wider or narrower than this, though this value is generally somewhat more accurate than the result of FontMetrics.get_approximate_char_width for digits.

get_ascent

def get_ascent(self) -> int

Gets the ascent from a font metrics structure.

The ascent is the distance from the baseline to the logical top of a line of text. (The logical top may be above or below the top of the actual drawn ink. It is necessary to lay out the text to figure where the ink will be.)

get_descent

def get_descent(self) -> int

Gets the descent from a font metrics structure.

The descent is the distance from the baseline to the logical bottom of a line of text. (The logical bottom may be above or below the bottom of the actual drawn ink. It is necessary to lay out the text to figure where the ink will be.)

get_height

def get_height(self) -> int

Gets the line height from a font metrics structure.

The line height is the recommended distance between successive baselines in wrapped text using this font.

If the line height is not available, 0 is returned.

get_strikethrough_position

def get_strikethrough_position(self) -> int

Gets the suggested position to draw the strikethrough.

The value returned is the distance above the baseline of the top of the strikethrough.

get_strikethrough_thickness

def get_strikethrough_thickness(self) -> int

Gets the suggested thickness to draw for the strikethrough.

get_underline_position

def get_underline_position(self) -> int

Gets the suggested position to draw the underline.

The value returned is the distance above the baseline of the top of the underline. Since most fonts have underline positions beneath the baseline, this value is typically negative.

get_underline_thickness

def get_underline_thickness(self) -> int

Gets the suggested thickness to draw for the underline.

ref

def ref(self) -> FontMetrics | None

Increase the reference count of a font metrics structure by one.

unref

def unref(self) -> None

Decrease the reference count of a font metrics structure by one.

If the result is zero, frees the structure and any associated memory.

Properties

ref_count

ref_count: int  # read/write

ascent

ascent: int  # read/write

descent

descent: int  # read/write

height

height: int  # read/write

approximate_char_width

approximate_char_width: int  # read/write

approximate_digit_width

approximate_digit_width: int  # read/write

underline_position

underline_position: int  # read/write

underline_thickness

underline_thickness: int  # read/write

strikethrough_position

strikethrough_position: int  # read/write

strikethrough_thickness

strikethrough_thickness: int  # read/write