Skip to content

Pango.GlyphString

record (struct)

A PangoGlyphString is used to store strings of glyphs with geometry and visual attribute information.

The storage for the glyph information is owned by the structure which simplifies memory management.

Constructors

new

@classmethod
def new(cls) -> GlyphString

Create a new PangoGlyphString.

Methods

copy

def copy(self) -> GlyphString | None

Copy a glyph string and associated storage.

extents

def extents(self, font: Font) -> tuple[Rectangle, Rectangle]

Compute the logical and ink extents of a glyph string.

See the documentation for Font.get_glyph_extents for details about the interpretation of the rectangles.

Examples of logical (red) and ink (green) rects:

Parameters:

  • font — a PangoFont

extents_range

def extents_range(self, start: int, end: int, font: Font) -> tuple[Rectangle, Rectangle]

Computes the extents of a sub-portion of a glyph string.

The extents are relative to the start of the glyph string range (the origin of their coordinate system is at the start of the range, not at the start of the entire glyph string).

Parameters:

  • start — start index
  • end — end index (the range is the set of bytes with indices such that start <= index < end)
  • font — a PangoFont

free

def free(self) -> None

Free a glyph string and associated storage.

get_logical_widths

def get_logical_widths(self, text: str, length: int, embedding_level: int) -> list[int]

Given a PangoGlyphString and corresponding text, determine the width corresponding to each character.

When multiple characters compose a single cluster, the width of the entire cluster is divided equally among the characters.

See also GlyphItem.get_logical_widths.

Parameters:

  • text — the text corresponding to the glyphs
  • length — the length of text, in bytes
  • embedding_level — the embedding level of the string

get_width

def get_width(self) -> int

Computes the logical width of the glyph string.

This can also be computed using GlyphString.extents. However, since this only computes the width, it's much faster. This is in fact only a convenience function that computes the sum of geometry.width for each glyph in the glyphs.

index_to_x

def index_to_x(self, text: str, length: int, analysis: Analysis, index_: int, trailing: bool) -> int

Converts from character position to x position.

The X position is measured from the left edge of the run. Character positions are obtained using font metrics for ligatures where available, and computed by dividing up each cluster into equal portions, otherwise.

<picture> <source srcset="glyphstring-positions-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Glyph positions" src="glyphstring-positions-light.png"> </picture>

Parameters:

  • text — the text for the run
  • length — the number of bytes (not characters) in text.
  • analysis — the analysis information return from itemize
  • index_ — the byte index within text
  • trailing — whether we should compute the result for the beginning (False) or end (True) of the character.

index_to_x_full

def index_to_x_full(self, text: str, length: int, analysis: Analysis, attrs: LogAttr | None, index_: int, trailing: bool) -> int

Converts from character position to x position.

This variant of GlyphString.index_to_x additionally accepts a PangoLogAttr array. The grapheme boundary information in it can be used to disambiguate positioning inside some complex clusters.

Parameters:

  • text — the text for the run
  • length — the number of bytes (not characters) in text.
  • analysis — the analysis information return from itemize
  • attrsPangoLogAttr array for text
  • index_ — the byte index within text
  • trailing — whether we should compute the result for the beginning (False) or end (True) of the character.

set_size

def set_size(self, new_len: int) -> None

Resize a glyph string to the given length.

Parameters:

  • new_len — the new length of the string

x_to_index

def x_to_index(self, text: str, length: int, analysis: Analysis, x_pos: int) -> tuple[int, int]

Convert from x offset to character position.

Character positions are computed by dividing up each cluster into equal portions. In scripts where positioning within a cluster is not allowed (such as Thai), the returned value may not be a valid cursor position; the caller must combine the result with the logical attributes for the text to compute the valid cursor position.

Parameters:

  • text — the text for the run
  • length — the number of bytes (not characters) in text.
  • analysis — the analysis information return from itemize
  • x_pos — the x offset (in Pango units)

Properties

num_glyphs

num_glyphs: int  # read/write

glyphs

glyphs: list[GlyphInfo]  # read/write

log_clusters

log_clusters: int  # read/write

space

space: int  # read/write