Functions ========= .. currentmodule:: gi.repository.Pango .. function:: attr_allow_breaks_new(allow_breaks: bool) -> ~gi.repository.Pango.Attribute Create a new allow-breaks attribute. If breaks are disabled, the range will be kept in a single run, as far as possible. .. versionadded:: 1.44 :param allow_breaks: :const:`True` if we line breaks are allowed :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_background_alpha_new(alpha: int) -> ~gi.repository.Pango.Attribute Create a new background alpha attribute. .. versionadded:: 1.38 :param alpha: the alpha value, between 1 and 65536 :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_background_new(red: int, green: int, blue: int) -> ~gi.repository.Pango.Attribute Create a new background color attribute. :param red: the red value (ranging from 0 to 65535) :param green: the green value :param blue: the blue value :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_baseline_shift_new(shift: int) -> ~gi.repository.Pango.Attribute Create a new baseline displacement attribute. The effect of this attribute is to shift the baseline of a run, relative to the run of preceding run. .. image:: https://docs.gtk.org/Pango/baseline-shift-light.png .. versionadded:: 1.50 :param shift: either a ``PangoBaselineShift`` enumeration value or an absolute value (> 1024) in Pango units, relative to the baseline of the previous run. Positive values displace the text upwards. :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_break(text: str, length: int, attr_list: ~gi.repository.Pango.AttrList, offset: int, attrs: list[~gi.repository.Pango.LogAttr]) -> None Apply customization from attributes to the breaks in ``attrs``\. The line breaks are assumed to have been produced by :obj:`~gi.repository.Pango.default_break` and :obj:`~gi.repository.Pango.tailor_break`\. .. versionadded:: 1.50 :param text: text to break. Must be valid UTF-8 :param length: length of text in bytes (may be -1 if ``text`` is nul-terminated) :param attr_list: ``PangoAttrList`` to apply :param offset: Byte offset of ``text`` from the beginning of the paragraph :param attrs: array with one ``PangoLogAttr`` per character in ``text``\, plus one extra, to be filled in .. function:: attr_fallback_new(enable_fallback: bool) -> ~gi.repository.Pango.Attribute Create a new font fallback attribute. If fallback is disabled, characters will only be used from the closest matching font on the system. No fallback will be done to other fonts on the system that might contain the characters in the text. .. versionadded:: 1.4 :param enable_fallback: :const:`True` if we should fall back on other fonts for characters the active font is missing :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_family_new(family: str) -> ~gi.repository.Pango.Attribute Create a new font family attribute. :param family: the family or comma-separated list of families :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_font_desc_new(desc: ~gi.repository.Pango.FontDescription) -> ~gi.repository.Pango.Attribute :param desc: .. function:: attr_font_features_new(features: str) -> ~gi.repository.Pango.Attribute :param features: .. function:: attr_font_scale_new(scale: ~gi.repository.Pango.FontScale) -> ~gi.repository.Pango.Attribute Create a new font scale attribute. The effect of this attribute is to change the font size of a run, relative to the size of preceding run. .. versionadded:: 1.50 :param scale: a ``PangoFontScale`` value, which indicates font size change relative to the size of the previous run. :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_foreground_alpha_new(alpha: int) -> ~gi.repository.Pango.Attribute Create a new foreground alpha attribute. .. versionadded:: 1.38 :param alpha: the alpha value, between 1 and 65536 :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_foreground_new(red: int, green: int, blue: int) -> ~gi.repository.Pango.Attribute Create a new foreground color attribute. :param red: the red value (ranging from 0 to 65535) :param green: the green value :param blue: the blue value :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_gravity_hint_new(hint: ~gi.repository.Pango.GravityHint) -> ~gi.repository.Pango.Attribute Create a new gravity hint attribute. .. versionadded:: 1.16 :param hint: the gravity hint value :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_gravity_new(gravity: ~gi.repository.Pango.Gravity) -> ~gi.repository.Pango.Attribute Create a new gravity attribute. .. versionadded:: 1.16 :param gravity: the gravity value; should not be :const:`~gi.repository.Pango.Gravity.AUTO` :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_insert_hyphens_new(insert_hyphens: bool) -> ~gi.repository.Pango.Attribute Create a new insert-hyphens attribute. Pango will insert hyphens when breaking lines in the middle of a word. This attribute can be used to suppress the hyphen. .. versionadded:: 1.44 :param insert_hyphens: :const:`True` if hyphens should be inserted :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_language_new(language: ~gi.repository.Pango.Language) -> ~gi.repository.Pango.Attribute :param language: .. function:: attr_letter_spacing_new(letter_spacing: int) -> ~gi.repository.Pango.Attribute Create a new letter-spacing attribute. .. versionadded:: 1.6 :param letter_spacing: amount of extra space to add between graphemes of the text, in Pango units :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_line_height_new(factor: float) -> ~gi.repository.Pango.Attribute Modify the height of logical line extents by a factor. This affects the values returned by :obj:`~gi.repository.Pango.LayoutLine.get_extents`\, :obj:`~gi.repository.Pango.LayoutLine.get_pixel_extents` and :obj:`~gi.repository.Pango.LayoutIter.get_line_extents`\. .. versionadded:: 1.50 :param factor: the scaling factor to apply to the logical height .. function:: attr_line_height_new_absolute(height: int) -> ~gi.repository.Pango.Attribute Override the height of logical line extents to be ``height``\. This affects the values returned by :obj:`~gi.repository.Pango.LayoutLine.get_extents`\, :obj:`~gi.repository.Pango.LayoutLine.get_pixel_extents` and :obj:`~gi.repository.Pango.LayoutIter.get_line_extents`\. .. versionadded:: 1.50 :param height: the line height, in :const:`~gi.repository.Pango.SCALE`-ths of a point .. function:: attr_list_from_string(text: str) -> ~gi.repository.Pango.AttrList | None :param text: .. function:: attr_overline_color_new(red: int, green: int, blue: int) -> ~gi.repository.Pango.Attribute Create a new overline color attribute. This attribute modifies the color of overlines. If not set, overlines will use the foreground color. .. versionadded:: 1.46 :param red: the red value (ranging from 0 to 65535) :param green: the green value :param blue: the blue value :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_overline_new(overline: ~gi.repository.Pango.Overline) -> ~gi.repository.Pango.Attribute Create a new overline-style attribute. .. versionadded:: 1.46 :param overline: the overline style :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_rise_new(rise: int) -> ~gi.repository.Pango.Attribute Create a new baseline displacement attribute. :param rise: the amount that the text should be displaced vertically, in Pango units. Positive values displace the text upwards. :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_scale_new(scale_factor: float) -> ~gi.repository.Pango.Attribute Create a new font size scale attribute. The base font for the affected text will have its size multiplied by ``scale_factor``\. :param scale_factor: factor to scale the font :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_sentence_new() -> ~gi.repository.Pango.Attribute Marks the range of the attribute as a single sentence. Note that this may require adjustments to word and sentence classification around the range. .. versionadded:: 1.50 :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_shape_new(ink_rect: ~gi.repository.Pango.Rectangle, logical_rect: ~gi.repository.Pango.Rectangle) -> ~gi.repository.Pango.Attribute :param ink_rect: :param logical_rect: .. function:: attr_shape_new_with_data(ink_rect: ~gi.repository.Pango.Rectangle, logical_rect: ~gi.repository.Pango.Rectangle, data: ~typing.Any = None, copy_func: ~typing.Callable[[~typing.Any], ~typing.Any | None] | None = None) -> ~gi.repository.Pango.Attribute :param ink_rect: :param logical_rect: :param data: :param copy_func: .. function:: attr_show_new(flags: ~gi.repository.Pango.ShowFlags) -> ~gi.repository.Pango.Attribute Create a new attribute that influences how invisible characters are rendered. .. versionadded:: 1.44 :param flags: ``PangoShowFlags`` to apply :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_size_new(size: int) -> ~gi.repository.Pango.Attribute :param size: .. function:: attr_size_new_absolute(size: int) -> ~gi.repository.Pango.Attribute :param size: .. function:: attr_stretch_new(stretch: ~gi.repository.Pango.Stretch) -> ~gi.repository.Pango.Attribute Create a new font stretch attribute. :param stretch: the stretch :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_strikethrough_color_new(red: int, green: int, blue: int) -> ~gi.repository.Pango.Attribute Create a new strikethrough color attribute. This attribute modifies the color of strikethrough lines. If not set, strikethrough lines will use the foreground color. .. versionadded:: 1.8 :param red: the red value (ranging from 0 to 65535) :param green: the green value :param blue: the blue value :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_strikethrough_new(strikethrough: bool) -> ~gi.repository.Pango.Attribute Create a new strike-through attribute. :param strikethrough: :const:`True` if the text should be struck-through :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_style_new(style: ~gi.repository.Pango.Style) -> ~gi.repository.Pango.Attribute Create a new font slant style attribute. :param style: the slant style :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_text_transform_new(transform: ~gi.repository.Pango.TextTransform) -> ~gi.repository.Pango.Attribute Create a new attribute that influences how characters are transformed during shaping. .. versionadded:: 1.50 :param transform: ``PangoTextTransform`` to apply :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_type_get_name(type: ~gi.repository.Pango.AttrType) -> str | None :param type: .. function:: attr_type_register(name: str) -> ~gi.repository.Pango.AttrType :param name: .. function:: attr_underline_color_new(red: int, green: int, blue: int) -> ~gi.repository.Pango.Attribute Create a new underline color attribute. This attribute modifies the color of underlines. If not set, underlines will use the foreground color. .. versionadded:: 1.8 :param red: the red value (ranging from 0 to 65535) :param green: the green value :param blue: the blue value :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_underline_new(underline: ~gi.repository.Pango.Underline) -> ~gi.repository.Pango.Attribute Create a new underline-style attribute. :param underline: the underline style :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_variant_new(variant: ~gi.repository.Pango.Variant) -> ~gi.repository.Pango.Attribute Create a new font variant attribute (normal or small caps). :param variant: the variant :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy`\. .. function:: attr_weight_new(weight: ~gi.repository.Pango.Weight) -> ~gi.repository.Pango.Attribute Create a new font weight attribute. :param weight: the weight :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: attr_word_new() -> ~gi.repository.Pango.Attribute Marks the range of the attribute as a single word. Note that this may require adjustments to word and sentence classification around the range. .. versionadded:: 1.50 :return: the newly allocated ``PangoAttribute``\, which should be freed with :obj:`~gi.repository.Pango.Attribute.destroy` .. function:: bidi_type_for_unichar(ch: str) -> ~gi.repository.Pango.BidiType :param ch: .. function:: break_(text: str, length: int, analysis: ~gi.repository.Pango.Analysis, attrs: list[~gi.repository.Pango.LogAttr]) -> None :param text: :param length: :param analysis: :param attrs: .. function:: default_break(text: str, length: int, analysis: ~gi.repository.Pango.Analysis | None, attrs: ~gi.repository.Pango.LogAttr, attrs_len: int) -> None This is the default break algorithm. It applies rules from the `Unicode Line Breaking Algorithm `__ without language-specific tailoring, therefore the ``analyis`` argument is unused and can be :const:`None`. See :obj:`~gi.repository.Pango.tailor_break` for language-specific breaks. See :obj:`~gi.repository.Pango.attr_break` for attribute-based customization. :param text: text to break. Must be valid UTF-8 :param length: length of text in bytes (may be -1 if ``text`` is nul-terminated) :param analysis: a ``PangoAnalysis`` structure for the ``text`` :param attrs: logical attributes to fill in :param attrs_len: size of the array passed as ``attrs`` .. function:: extents_to_pixels(inclusive: ~gi.repository.Pango.Rectangle | None = None, nearest: ~gi.repository.Pango.Rectangle | None = None) -> None Converts extents from Pango units to device units. The conversion is done by dividing by the :const:`~gi.repository.Pango.SCALE` factor and performing rounding. The ``inclusive`` rectangle is converted by flooring the x/y coordinates and extending width/height, such that the final rectangle completely includes the original rectangle. The ``nearest`` rectangle is converted by rounding the coordinates of the rectangle to the nearest device unit (pixel). The rule to which argument to use is: if you want the resulting device-space rectangle to completely contain the original rectangle, pass it in as ``inclusive``\. If you want two touching-but-not-overlapping rectangles stay touching-but-not-overlapping after rounding to device units, pass them in as ``nearest``\. .. versionadded:: 1.16 :param inclusive: rectangle to round to pixels inclusively :param nearest: rectangle to round to nearest pixels .. function:: find_base_dir(text: str, length: int) -> ~gi.repository.Pango.Direction Searches a string the first character that has a strong direction, according to the Unicode bidirectional algorithm. .. versionadded:: 1.4 :param text: the text to process. Must be valid UTF-8 :param length: length of ``text`` in bytes (may be -1 if ``text`` is nul-terminated) :return: The direction corresponding to the first strong character. If no such character is found, then :const:`~gi.repository.Pango.Direction.NEUTRAL` is returned. .. function:: find_paragraph_boundary(text: str, length: int) -> ~typing.Tuple[int, int] Locates a paragraph boundary in ``text``\. A boundary is caused by delimiter characters, such as a newline, carriage return, carriage return-newline pair, or Unicode paragraph separator character. The index of the run of delimiters is returned in ``paragraph_delimiter_index``\. The index of the start of the next paragraph (index after all delimiters) is stored n ``next_paragraph_start``\. If no delimiters are found, both ``paragraph_delimiter_index`` and ``next_paragraph_start`` are filled with the length of ``text`` (an index one off the end). :param text: UTF-8 text :param length: length of ``text`` in bytes, or -1 if nul-terminated .. function:: font_description_from_string(str: str) -> ~gi.repository.Pango.FontDescription :param str: .. function:: get_log_attrs(text: str, length: int, level: int, language: ~gi.repository.Pango.Language, attrs: list[~gi.repository.Pango.LogAttr]) -> None Computes a ``PangoLogAttr`` for each character in ``text``\. The ``attrs`` array must have one ``PangoLogAttr`` for each position in ``text``\; if ``text`` contains N characters, it has N+1 positions, including the last position at the end of the text. ``text`` should be an entire paragraph; logical attributes can't be computed without context (for example you need to see spaces on either side of a word to know the word is a word). :param text: text to process. Must be valid UTF-8 :param length: length in bytes of ``text`` :param level: embedding level, or -1 if unknown :param language: language tag :param attrs: array with one ``PangoLogAttr`` per character in ``text``\, plus one extra, to be filled in .. function:: get_mirror_char(ch: str, mirrored_ch: str) -> bool Returns the mirrored character of a Unicode character. Mirror characters are determined by the Unicode mirrored property. .. deprecated:: 1.30 Use :obj:`~gi.repository.GLib.unichar_get_mirror_char` instead; the docs for that function provide full details. :param ch: a Unicode character :param mirrored_ch: location to store the mirrored character :return: :const:`True` if ``ch`` has a mirrored character and ``mirrored_ch`` is filled in, :const:`False` otherwise .. function:: gravity_get_for_matrix(matrix: ~gi.repository.Pango.Matrix | None = None) -> ~gi.repository.Pango.Gravity :param matrix: .. function:: gravity_get_for_script(script: ~gi.repository.Pango.Script, base_gravity: ~gi.repository.Pango.Gravity, hint: ~gi.repository.Pango.GravityHint) -> ~gi.repository.Pango.Gravity :param script: :param base_gravity: :param hint: .. function:: gravity_get_for_script_and_width(script: ~gi.repository.Pango.Script, wide: bool, base_gravity: ~gi.repository.Pango.Gravity, hint: ~gi.repository.Pango.GravityHint) -> ~gi.repository.Pango.Gravity :param script: :param wide: :param base_gravity: :param hint: .. function:: gravity_to_rotation(gravity: ~gi.repository.Pango.Gravity) -> float :param gravity: .. function:: is_zero_width(ch: str) -> bool Checks if a character that should not be normally rendered. This includes all Unicode characters with "ZERO WIDTH" in their name, as well as *bidi* formatting characters, and a few other ones. This is totally different from :obj:`~gi.repository.GLib.unichar_iszerowidth` and is at best misnamed. .. versionadded:: 1.10 :param ch: a Unicode character :return: :const:`True` if ``ch`` is a zero-width character, :const:`False` otherwise .. function:: itemize(context: ~gi.repository.Pango.Context, text: str, start_index: int, length: int, attrs: ~gi.repository.Pango.AttrList, cached_iter: ~gi.repository.Pango.AttrIterator | None = None) -> list[~gi.repository.Pango.Item] Breaks a piece of text into segments with consistent directional level and font. Each byte of ``text`` will be contained in exactly one of the items in the returned list; the generated list of items will be in logical order (the start offsets of the items are ascending). ``cached_iter`` should be an iterator over ``attrs`` currently positioned at a range before or containing ``start_index``\; ``cached_iter`` will be advanced to the range covering the position just after ``start_index`` + ``length``\. (i.e. if itemizing in a loop, just keep passing in the same ``cached_iter``\). :param context: a structure holding information that affects the itemization process. :param text: the text to itemize. Must be valid UTF-8 :param start_index: first byte in ``text`` to process :param length: the number of bytes (not characters) to process after ``start_index``\. This must be >= 0. :param attrs: the set of attributes that apply to ``text``\. :param cached_iter: Cached attribute iterator :return: a ``GList`` of :obj:`~gi.repository.Pango.Item` structures. The items should be freed using :obj:`~gi.repository.Pango.Item.free` in combination with :obj:`~gi.repository.GLib.List.free_full`\. .. function:: itemize_with_base_dir(context: ~gi.repository.Pango.Context, base_dir: ~gi.repository.Pango.Direction, text: str, start_index: int, length: int, attrs: ~gi.repository.Pango.AttrList, cached_iter: ~gi.repository.Pango.AttrIterator | None = None) -> list[~gi.repository.Pango.Item] Like ``pango_itemize()``\, but with an explicitly specified base direction. The base direction is used when computing bidirectional levels. :obj:`~gi.repository.Pango.itemize` gets the base direction from the ``PangoContext`` (see :obj:`~gi.repository.Pango.Context.set_base_dir`\). .. versionadded:: 1.4 :param context: a structure holding information that affects the itemization process. :param base_dir: base direction to use for bidirectional processing :param text: the text to itemize. :param start_index: first byte in ``text`` to process :param length: the number of bytes (not characters) to process after ``start_index``\. This must be >= 0. :param attrs: the set of attributes that apply to ``text``\. :param cached_iter: Cached attribute iterator :return: a ``GList`` of :obj:`~gi.repository.Pango.Item` structures. The items should be freed using :obj:`~gi.repository.Pango.Item.free` probably in combination with :obj:`~gi.repository.GLib.List.free_full`\. .. function:: language_from_string(language: str | None = None) -> ~gi.repository.Pango.Language | None :param language: .. function:: language_get_default() -> ~gi.repository.Pango.Language .. function:: language_get_preferred() -> list[~gi.repository.Pango.Language] | None .. function:: layout_deserialize_error_quark() -> int .. function:: log2vis_get_embedding_levels(text: str, length: int, pbase_dir: ~gi.repository.Pango.Direction) -> int Return the bidirectional embedding levels of the input paragraph. The bidirectional embedding levels are defined by the `Unicode Bidirectional Algorithm `__\. If the input base direction is a weak direction, the direction of the characters in the text will determine the final resolved direction. .. versionadded:: 1.4 :param text: the text to itemize. :param length: the number of bytes (not characters) to process, or -1 if ``text`` is nul-terminated and the length should be calculated. :param pbase_dir: input base direction, and output resolved direction. :return: a newly allocated array of embedding levels, one item per character (not byte), that should be freed using :obj:`~gi.repository.GLib.free`\. .. function:: markup_parser_finish(context: ~gi.repository.GLib.MarkupParseContext) -> ~typing.Tuple[bool, ~gi.repository.Pango.AttrList, str, str] Finishes parsing markup. After feeding a Pango markup parser some data with :obj:`~gi.repository.GLib.MarkupParseContext.parse`\, use this function to get the list of attributes and text out of the markup. This function will not free ``context``\, use :obj:`~gi.repository.GLib.MarkupParseContext.free` to do so. .. versionadded:: 1.31.0 :param context: A valid parse context that was returned from :obj:`~gi.repository.Pango.markup_parser_new` :return: :const:`False` if ``error`` is set, otherwise :const:`True` .. function:: markup_parser_new(accel_marker: str) -> ~gi.repository.GLib.MarkupParseContext Incrementally parses marked-up text to create a plain-text string and an attribute list. See the `Pango Markup `__ docs for details about the supported markup. If ``accel_marker`` is nonzero, the given character will mark the character following it as an accelerator. For example, ``accel_marker`` might be an ampersand or underscore. All characters marked as an accelerator will receive a :const:`~gi.repository.Pango.Underline.LOW` attribute, and the first character so marked will be returned in ``accel_char``\, when calling :obj:`~gi.repository.Pango.markup_parser_finish`\. Two ``accel_marker`` characters following each other produce a single literal ``accel_marker`` character. To feed markup to the parser, use :obj:`~gi.repository.GLib.MarkupParseContext.parse` on the returned :obj:`~gi.repository.GLib.MarkupParseContext`\. When done with feeding markup to the parser, use :obj:`~gi.repository.Pango.markup_parser_finish` to get the data out of it, and then use :obj:`~gi.repository.GLib.MarkupParseContext.free` to free it. This function is designed for applications that read Pango markup from streams. To simply parse a string containing Pango markup, the :obj:`~gi.repository.Pango.parse_markup` API is recommended instead. .. versionadded:: 1.31.0 :param accel_marker: character that precedes an accelerator, or 0 for none :return: a ``GMarkupParseContext`` that should be destroyed with :obj:`~gi.repository.GLib.MarkupParseContext.free`\. .. function:: parse_enum(type: ~gobject.GType, str: str | None, warn: bool) -> ~typing.Tuple[bool, int, str] Parses an enum type and stores the result in ``value``\. If ``str`` does not match the nick name of any of the possible values for the enum and is not an integer, :const:`False` is returned, a warning is issued if ``warn`` is :const:`True`, and a string representing the list of possible values is stored in ``possible_values``\. The list is slash-separated, eg. "none/start/middle/end". If failed and ``possible_values`` is not :const:`None`, returned string should be freed using :func:`~gi.repository.GLib.free`. .. versionadded:: 1.16 .. deprecated:: 1.38 Please do not use it in newly written code :param type: enum type to parse, eg. %PANGO_TYPE_ELLIPSIZE_MODE :param str: string to parse :param warn: if :const:`True`, issue a :func:`~gi.repository.GLib.warning` on bad input :return: :const:`True` if ``str`` was successfully parsed .. function:: parse_markup(markup_text: str, length: int, accel_marker: str) -> ~typing.Tuple[bool, ~gi.repository.Pango.AttrList, str, str] Parses marked-up text to create a plain-text string and an attribute list. See the `Pango Markup `__ docs for details about the supported markup. If ``accel_marker`` is nonzero, the given character will mark the character following it as an accelerator. For example, ``accel_marker`` might be an ampersand or underscore. All characters marked as an accelerator will receive a :const:`~gi.repository.Pango.Underline.LOW` attribute, and the first character so marked will be returned in ``accel_char``\. Two ``accel_marker`` characters following each other produce a single literal ``accel_marker`` character. To parse a stream of pango markup incrementally, use :obj:`~gi.repository.Pango.markup_parser_new`\. If any error happens, none of the output arguments are touched except for ``error``\. :param markup_text: markup to parse (see the `Pango Markup `__ docs) :param length: length of ``markup_text``\, or -1 if nul-terminated :param accel_marker: character that precedes an accelerator, or 0 for none :return: :const:`False` if ``error`` is set, otherwise :const:`True` .. function:: parse_stretch(str: str, warn: bool) -> ~typing.Tuple[bool, ~gi.repository.Pango.Stretch] Parses a font stretch. The allowed values are "ultra_condensed", "extra_condensed", "condensed", "semi_condensed", "normal", "semi_expanded", "expanded", "extra_expanded" and "ultra_expanded". Case variations are ignored and the '_' characters may be omitted. :param str: a string to parse. :param warn: if :const:`True`, issue a :func:`~gi.repository.GLib.warning` on bad input. :return: :const:`True` if ``str`` was successfully parsed. .. function:: parse_style(str: str, warn: bool) -> ~typing.Tuple[bool, ~gi.repository.Pango.Style] Parses a font style. The allowed values are "normal", "italic" and "oblique", case variations being ignored. :param str: a string to parse. :param warn: if :const:`True`, issue a :func:`~gi.repository.GLib.warning` on bad input. :return: :const:`True` if ``str`` was successfully parsed. .. function:: parse_variant(str: str, warn: bool) -> ~typing.Tuple[bool, ~gi.repository.Pango.Variant] Parses a font variant. The allowed values are "normal", "small-caps", "all-small-caps", "petite-caps", "all-petite-caps", "unicase" and "title-caps", case variations being ignored. :param str: a string to parse. :param warn: if :const:`True`, issue a :func:`~gi.repository.GLib.warning` on bad input. :return: :const:`True` if ``str`` was successfully parsed. .. function:: parse_weight(str: str, warn: bool) -> ~typing.Tuple[bool, ~gi.repository.Pango.Weight] Parses a font weight. The allowed values are "heavy", "ultrabold", "bold", "normal", "light", "ultraleight" and integers. Case variations are ignored. :param str: a string to parse. :param warn: if :const:`True`, issue a :func:`~gi.repository.GLib.warning` on bad input. :return: :const:`True` if ``str`` was successfully parsed. .. function:: quantize_line_geometry(thickness: int, position: int) -> ~typing.Tuple[int, int] Quantizes the thickness and position of a line to whole device pixels. This is typically used for underline or strikethrough. The purpose of this function is to avoid such lines looking blurry. Care is taken to make sure ``thickness`` is at least one pixel when this function returns, but returned ``position`` may become zero as a result of rounding. .. versionadded:: 1.12 :param thickness: pointer to the thickness of a line, in Pango units :param position: corresponding position .. function:: read_line(stream: ~typing.Any, str: ~gi.repository.GLib.String) -> int Reads an entire line from a file into a buffer. Lines may be delimited with '\n', '\r', '\n\r', or '\r\n'. The delimiter is not written into the buffer. Text after a '#' character is treated as a comment and skipped. '\' can be used to escape a # character. '\' proceeding a line delimiter combines adjacent lines. A '\' proceeding any other character is ignored and written into the output buffer unmodified. .. deprecated:: 1.38 Please do not use it in newly written code :param stream: a stdio stream :param str: ``GString`` buffer into which to write the result :return: 0 if the stream was already at an %EOF character, otherwise the number of lines read (this is useful for maintaining a line number counter which doesn't combine lines with '\') .. function:: reorder_items(items: list[~gi.repository.Pango.Item]) -> list[~gi.repository.Pango.Item] Reorder items from logical order to visual order. The visual order is determined from the associated directional levels of the items. The original list is unmodified. (Please open a bug if you use this function. It is not a particularly convenient interface, and the code is duplicated elsewhere in Pango for that reason.) :param items: a ``GList`` of ``PangoItem`` in logical order. :return: a ``GList`` of ``PangoItem`` structures in visual order. .. function:: scan_int(pos: str) -> ~typing.Tuple[bool, str, int] Scans an integer. Leading white space is skipped. .. deprecated:: 1.38 Please do not use it in newly written code :param pos: in/out string position :return: :const:`False` if a parse error occurred .. function:: scan_string(pos: str, out: ~gi.repository.GLib.String) -> ~typing.Tuple[bool, str] Scans a string into a ``GString`` buffer. The string may either be a sequence of non-white-space characters, or a quoted string with '"'. Instead a quoted string, '\"' represents a literal quote. Leading white space outside of quotes is skipped. .. deprecated:: 1.38 Please do not use it in newly written code :param pos: in/out string position :param out: a ``GString`` into which to write the result :return: :const:`False` if a parse error occurred .. function:: scan_word(pos: str, out: ~gi.repository.GLib.String) -> ~typing.Tuple[bool, str] Scans a word into a ``GString`` buffer. A word consists of [A-Za-z_] followed by zero or more [A-Za-z_0-9]. Leading white space is skipped. .. deprecated:: 1.38 Please do not use it in newly written code :param pos: in/out string position :param out: a ``GString`` into which to write the result :return: :const:`False` if a parse error occurred .. function:: script_for_unichar(ch: str) -> ~gi.repository.Pango.Script :param ch: .. function:: script_get_sample_language(script: ~gi.repository.Pango.Script) -> ~gi.repository.Pango.Language | None :param script: .. function:: shape(text: str, length: int, analysis: ~gi.repository.Pango.Analysis, glyphs: ~gi.repository.Pango.GlyphString) -> None Convert the characters in ``text`` into glyphs. Given a segment of text and the corresponding ``PangoAnalysis`` structure returned from :obj:`~gi.repository.Pango.itemize`\, convert the characters into glyphs. You may also pass in only a substring of the item from :obj:`~gi.repository.Pango.itemize`\. It is recommended that you use :obj:`~gi.repository.Pango.shape_full` instead, since that API allows for shaping interaction happening across text item boundaries. Some aspects of hyphen insertion and text transformation (in particular, capitalization) require log attrs, and thus can only be handled by :obj:`~gi.repository.Pango.shape_item`\. Note that the extra attributes in the ``analyis`` that is returned from :obj:`~gi.repository.Pango.itemize` have indices that are relative to the entire paragraph, so you need to subtract the item offset from their indices before calling :obj:`~gi.repository.Pango.shape`\. :param text: the text to process :param length: the length (in bytes) of ``text`` :param analysis: ``PangoAnalysis`` structure from :obj:`~gi.repository.Pango.itemize` :param glyphs: glyph string in which to store results .. function:: shape_full(item_text: str, item_length: int, paragraph_text: str | None, paragraph_length: int, analysis: ~gi.repository.Pango.Analysis, glyphs: ~gi.repository.Pango.GlyphString) -> None Convert the characters in ``text`` into glyphs. Given a segment of text and the corresponding ``PangoAnalysis`` structure returned from :obj:`~gi.repository.Pango.itemize`\, convert the characters into glyphs. You may also pass in only a substring of the item from :obj:`~gi.repository.Pango.itemize`\. This is similar to :obj:`~gi.repository.Pango.shape`\, except it also can optionally take the full paragraph text as input, which will then be used to perform certain cross-item shaping interactions. If you have access to the broader text of which ``item_text`` is part of, provide the broader text as ``paragraph_text``\. If ``paragraph_text`` is :const:`None`, item text is used instead. Some aspects of hyphen insertion and text transformation (in particular, capitalization) require log attrs, and thus can only be handled by :obj:`~gi.repository.Pango.shape_item`\. Note that the extra attributes in the ``analyis`` that is returned from :obj:`~gi.repository.Pango.itemize` have indices that are relative to the entire paragraph, so you do not pass the full paragraph text as ``paragraph_text``\, you need to subtract the item offset from their indices before calling :obj:`~gi.repository.Pango.shape_full`\. .. versionadded:: 1.32 :param item_text: valid UTF-8 text to shape. :param item_length: the length (in bytes) of ``item_text``\. -1 means nul-terminated text. :param paragraph_text: text of the paragraph (see details). :param paragraph_length: the length (in bytes) of ``paragraph_text``\. -1 means nul-terminated text. :param analysis: ``PangoAnalysis`` structure from :obj:`~gi.repository.Pango.itemize`\. :param glyphs: glyph string in which to store results. .. function:: shape_item(item: ~gi.repository.Pango.Item, paragraph_text: str | None, paragraph_length: int, log_attrs: ~gi.repository.Pango.LogAttr | None, glyphs: ~gi.repository.Pango.GlyphString, flags: ~gi.repository.Pango.ShapeFlags) -> None Convert the characters in ``item`` into glyphs. This is similar to :obj:`~gi.repository.Pango.shape_with_flags`\, except it takes a ``PangoItem`` instead of separate ``item_text`` and ``analysis`` arguments. It also takes ``log_attrs``\, which are needed for implementing some aspects of hyphen insertion and text transforms (in particular, capitalization). Note that the extra attributes in the ``analyis`` that is returned from :obj:`~gi.repository.Pango.itemize` have indices that are relative to the entire paragraph, so you do not pass the full paragraph text as ``paragraph_text``\, you need to subtract the item offset from their indices before calling :obj:`~gi.repository.Pango.shape_with_flags`\. .. versionadded:: 1.50 :param item: ``PangoItem`` to shape :param paragraph_text: text of the paragraph (see details). :param paragraph_length: the length (in bytes) of ``paragraph_text``\. -1 means nul-terminated text. :param log_attrs: array of ``PangoLogAttr`` for ``item`` :param glyphs: glyph string in which to store results :param flags: flags influencing the shaping process .. function:: shape_with_flags(item_text: str, item_length: int, paragraph_text: str | None, paragraph_length: int, analysis: ~gi.repository.Pango.Analysis, glyphs: ~gi.repository.Pango.GlyphString, flags: ~gi.repository.Pango.ShapeFlags) -> None Convert the characters in ``text`` into glyphs. Given a segment of text and the corresponding ``PangoAnalysis`` structure returned from :obj:`~gi.repository.Pango.itemize`\, convert the characters into glyphs. You may also pass in only a substring of the item from :obj:`~gi.repository.Pango.itemize`\. This is similar to :obj:`~gi.repository.Pango.shape_full`\, except it also takes flags that can influence the shaping process. Some aspects of hyphen insertion and text transformation (in particular, capitalization) require log attrs, and thus can only be handled by :obj:`~gi.repository.Pango.shape_item`\. Note that the extra attributes in the ``analyis`` that is returned from :obj:`~gi.repository.Pango.itemize` have indices that are relative to the entire paragraph, so you do not pass the full paragraph text as ``paragraph_text``\, you need to subtract the item offset from their indices before calling :obj:`~gi.repository.Pango.shape_with_flags`\. .. versionadded:: 1.44 :param item_text: valid UTF-8 text to shape :param item_length: the length (in bytes) of ``item_text``\. -1 means nul-terminated text. :param paragraph_text: text of the paragraph (see details). :param paragraph_length: the length (in bytes) of ``paragraph_text``\. -1 means nul-terminated text. :param analysis: ``PangoAnalysis`` structure from :obj:`~gi.repository.Pango.itemize` :param glyphs: glyph string in which to store results :param flags: flags influencing the shaping process .. function:: skip_space(pos: str) -> ~typing.Tuple[bool, str] Skips 0 or more characters of white space. .. deprecated:: 1.38 Please do not use it in newly written code :param pos: in/out string position :return: :const:`False` if skipping the white space leaves the position at a '\0' character. .. function:: split_file_list(str: str) -> list[str] Splits a %G_SEARCHPATH_SEPARATOR-separated list of files, stripping white space and substituting ~/ with $HOME/. .. deprecated:: 1.38 Please do not use it in newly written code :param str: a %G_SEARCHPATH_SEPARATOR separated list of filenames :return: a list of strings to be freed with :func:`~gi.repository.GLib.strfreev` .. function:: tab_array_from_string(text: str) -> ~gi.repository.Pango.TabArray | None :param text: .. function:: tailor_break(text: str, length: int, analysis: ~gi.repository.Pango.Analysis, offset: int, attrs: list[~gi.repository.Pango.LogAttr]) -> None Apply language-specific tailoring to the breaks in ``attrs``\. The line breaks are assumed to have been produced by :obj:`~gi.repository.Pango.default_break`\. If ``offset`` is not -1, it is used to apply attributes from ``analysis`` that are relevant to line breaking. Note that it is better to pass -1 for ``offset`` and use :obj:`~gi.repository.Pango.attr_break` to apply attributes to the whole paragraph. .. versionadded:: 1.44 :param text: text to process. Must be valid UTF-8 :param length: length in bytes of ``text`` :param analysis: ``PangoAnalysis`` for ``text`` :param offset: Byte offset of ``text`` from the beginning of the paragraph, or -1 to ignore attributes from ``analysis`` :param attrs: array with one ``PangoLogAttr`` per character in ``text``\, plus one extra, to be filled in .. function:: trim_string(str: str) -> str Trims leading and trailing whitespace from a string. .. deprecated:: 1.38 Please do not use it in newly written code :param str: a string :return: A newly-allocated string that must be freed with :func:`~gi.repository.GLib.free` .. function:: unichar_direction(ch: str) -> ~gi.repository.Pango.Direction Determines the inherent direction of a character. The inherent direction is either ``PANGO_DIRECTION_LTR``\, ``PANGO_DIRECTION_RTL``\, or ``PANGO_DIRECTION_NEUTRAL``\. This function is useful to categorize characters into left-to-right letters, right-to-left letters, and everything else. If full Unicode bidirectional type of a character is needed, :obj:`~gi.repository.Pango.BidiType.for_unichar` can be used instead. :param ch: a Unicode character :return: the direction of the character. .. function:: units_from_double(d: float) -> int Converts a floating-point number to Pango units. The conversion is done by multiplying ``d`` by :const:`~gi.repository.Pango.SCALE` and rounding the result to nearest integer. .. versionadded:: 1.16 :param d: double floating-point value :return: the value in Pango units. .. function:: units_to_double(i: int) -> float Converts a number in Pango units to floating-point. The conversion is done by dividing ``i`` by :const:`~gi.repository.Pango.SCALE`. .. versionadded:: 1.16 :param i: value in Pango units :return: the double value. .. function:: version() -> int Returns the encoded version of Pango available at run-time. This is similar to the macro %PANGO_VERSION except that the macro returns the encoded version available at compile-time. A version number can be encoded into an integer using :func:`~gi.repository.Pango.VERSION_ENCODE`. .. versionadded:: 1.16 :return: The encoded version of Pango library available at run time. .. function:: version_check(required_major: int, required_minor: int, required_micro: int) -> str | None Checks that the Pango library in use is compatible with the given version. Generally you would pass in the constants :const:`~gi.repository.Pango.VERSION_MAJOR`, :const:`~gi.repository.Pango.VERSION_MINOR`, :const:`~gi.repository.Pango.VERSION_MICRO` as the three arguments to this function; that produces a check that the library in use at run-time is compatible with the version of Pango the application or module was compiled against. Compatibility is defined by two things: first the version of the running library is newer than the version ``required_major``\.required_minor.``required_micro``\. Second the running library must be binary compatible with the version ``required_major``\.required_minor.``required_micro`` (same major version.) For compile-time version checking use :func:`~gi.repository.Pango.VERSION_CHECK`. .. versionadded:: 1.16 :param required_major: the required major version :param required_minor: the required minor version :param required_micro: the required major version :return: :const:`None` if the Pango library is compatible with the given version, or a string describing the version mismatch. The returned string is owned by Pango and should not be modified or freed. .. function:: version_string() -> str Returns the version of Pango available at run-time. This is similar to the macro :const:`~gi.repository.Pango.VERSION_STRING` except that the macro returns the version available at compile-time. .. versionadded:: 1.16 :return: A string containing the version of Pango library available at run time. The returned string is owned by Pango and should not be modified or freed.