:right-sidebar: True GlyphString =================================================================== .. currentmodule:: gi.repository.Pango .. class:: GlyphString(**kwargs) :no-contents-entry: 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 ------------ .. rst-class:: interim-class .. class:: GlyphString :no-index: .. classmethod:: new() -> ~gi.repository.Pango.GlyphString Create a new ``PangoGlyphString``\. Methods ------- .. rst-class:: interim-class .. class:: GlyphString :no-index: .. method:: extents(font: ~gi.repository.Pango.Font) -> ~typing.Tuple[~gi.repository.Pango.Rectangle, ~gi.repository.Pango.Rectangle] Compute the logical and ink extents of a glyph string. See the documentation for :obj:`~gi.repository.Pango.Font.get_glyph_extents` for details about the interpretation of the rectangles. Examples of logical (red) and ink (green) rects: .. image:: https://docs.gtk.org/Pango/rects1.png .. image:: https://docs.gtk.org/Pango/rects2.png :param font: a ``PangoFont`` .. method:: extents_range(start: int, end: int, font: ~gi.repository.Pango.Font) -> ~typing.Tuple[~gi.repository.Pango.Rectangle, ~gi.repository.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). :param start: start index :param end: end index (the range is the set of bytes with indices such that start <= index < end) :param font: a ``PangoFont`` .. method:: free() -> None Free a glyph string and associated storage. .. method:: get_logical_widths(text: str, length: int, embedding_level: int, logical_widths: list[int]) -> None 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 :obj:`~gi.repository.Pango.GlyphItem.get_logical_widths`\. :param text: the text corresponding to the glyphs :param length: the length of ``text``\, in bytes :param embedding_level: the embedding level of the string :param logical_widths: an array whose length is the number of characters in text (equal to ``g_utf8_strlen (text, length)`` unless text has ``NUL`` bytes) to be filled in with the resulting character widths. .. method:: get_width() -> int Computes the logical width of the glyph string. This can also be computed using :obj:`~gi.repository.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 ``glyphs``\. .. versionadded:: 1.14 .. method:: index_to_x(text: str, length: int, analysis: ~gi.repository.Pango.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. .. image:: https://docs.gtk.org/Pango/glyphstring-positions-light.png :param text: the text for the run :param length: the number of bytes (not characters) in ``text``\. :param analysis: the analysis information return from :obj:`~gi.repository.Pango.itemize` :param index_: the byte index within ``text`` :param trailing: whether we should compute the result for the beginning (:const:`False`) or end (:const:`True`) of the character. .. method:: index_to_x_full(text: str, length: int, analysis: ~gi.repository.Pango.Analysis, attrs: ~gi.repository.Pango.LogAttr | None, index_: int, trailing: bool) -> int Converts from character position to x position. This variant of :obj:`~gi.repository.Pango.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. .. versionadded:: 1.50 :param text: the text for the run :param length: the number of bytes (not characters) in ``text``\. :param analysis: the analysis information return from :obj:`~gi.repository.Pango.itemize` :param attrs: ``PangoLogAttr`` array for ``text`` :param index_: the byte index within ``text`` :param trailing: whether we should compute the result for the beginning (:const:`False`) or end (:const:`True`) of the character. .. method:: set_size(new_len: int) -> None Resize a glyph string to the given length. :param new_len: the new length of the string .. method:: x_to_index(text: str, length: int, analysis: ~gi.repository.Pango.Analysis, x_pos: int) -> ~typing.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. :param text: the text for the run :param length: the number of bytes (not characters) in text. :param analysis: the analysis information return from :obj:`~gi.repository.Pango.itemize` :param x_pos: the x offset (in Pango units) Fields ------ .. rst-class:: interim-class .. class:: GlyphString :no-index: .. attribute:: glyphs Array of glyph information .. attribute:: log_clusters Logical cluster info, indexed by the byte index within the text corresponding to the glyph string .. attribute:: num_glyphs Number of glyphs in this glyph string .. attribute:: space