Pango.GlyphString

Fields

Name Type Access Description
glyphs [Pango.GlyphInfo] r/w array of glyph information for the glyph string.
log_clusters int r/w logical cluster info, indexed by the byte index within the text corresponding to the glyph string.
num_glyphs int r/w number of the glyphs in this glyph string.
space int r  

Methods

class new ()
  copy ()
  extents (font)
  extents_range (start, end, font)
  free ()
  get_logical_widths (text, length, embedding_level, logical_widths)
  get_width ()
  index_to_x (text, length, analysis, index_, trailing)
  set_size (new_len)
  x_to_index (text, length, analysis, x_pos)

Details

class Pango.GlyphString

The Pango.GlyphString structure 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.

classmethod new()[source]
Returns:the newly allocated Pango.GlyphString, which should be freed with Pango.GlyphString.free().
Return type:Pango.GlyphString

Create a new Pango.GlyphString.

copy()[source]
Returns:the newly allocated Pango.GlyphString, which should be freed with Pango.GlyphString.free(), or None if self was None.
Return type:Pango.GlyphString or None

Copy a glyph string and associated storage.

extents(font)[source]
Parameters:font (Pango.Font) – a Pango.Font
Returns:
ink_rect:rectangle used to store the extents of the glyph string as drawn or None to indicate that the result is not needed.
logical_rect:rectangle used to store the logical extents of the glyph string or None to indicate that the result is not needed.
Return type:(ink_rect: Pango.Rectangle, logical_rect: Pango.Rectangle)

Compute the logical and ink extents of a glyph string. See the documentation for Pango.Font.get_glyph_extents() for details about the interpretation of the rectangles.

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

extents_range(start, end, font)[source]
Parameters:
  • start (int) – start index
  • end (int) – end index (the range is the set of bytes with indices such that start <= index < end)
  • font (Pango.Font) – a Pango.Font
Returns:

ink_rect:rectangle used to store the extents of the glyph string range as drawn or None to indicate that the result is not needed.
logical_rect:rectangle used to store the logical extents of the glyph string range or None to indicate that the result is not needed.

Return type:

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

free()[source]

Free a glyph string and associated storage.

get_logical_widths(text, length, embedding_level, logical_widths)[source]
Parameters:
  • text (str) – the text corresponding to the glyphs
  • length (int) – the length of text, in bytes
  • embedding_level (int) – the embedding level of the string
  • logical_widths ([int]) – an array whose length is the number of characters in text (equal to GLib.utf8_strlen (text, length) unless text has NUL bytes) to be filled in with the resulting character widths.

Given a Pango.GlyphString resulting from Pango.shape() and the corresponding text, determine the screen 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 Pango.GlyphItem.get_logical_widths().

get_width()[source]
Returns:the logical width of the glyph string.
Return type:int

Computes the logical width of the glyph string as can also be computed using Pango.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 self.

New in version 1.14.

index_to_x(text, length, analysis, index_, trailing)[source]
Parameters:
  • text (str) – the text for the run
  • length (int) – the number of bytes (not characters) in text.
  • analysis (Pango.Analysis) – the analysis information return from Pango.itemize()
  • index (int) – the byte index within text
  • trailing (bool) – whether we should compute the result for the beginning (False) or end (True) of the character.
Returns:

location to store result

Return type:

x_pos: int

Converts from character position to x position. (X position is measured from the left edge of the run). Character positions are computed by dividing up each cluster into equal portions.

set_size(new_len)[source]
Parameters:new_len (int) – the new length of the string.

Resize a glyph string to the given length.

x_to_index(text, length, analysis, x_pos)[source]
Parameters:
  • text (str) – the text for the run
  • length (int) – the number of bytes (not characters) in text.
  • analysis (Pango.Analysis) – the analysis information return from Pango.itemize()
  • x_pos (int) – the x offset (in Pango units)
Returns:

index_:location to store calculated byte index within text
trailing:location to store a boolean indicating whether the user clicked on the leading or trailing edge of the character.

Return type:

(index_: int, trailing: 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.