:right-sidebar: True Context =================================================================== .. currentmodule:: gi.repository.Pango .. class:: Context(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` A ``PangoContext`` stores global information used to control the itemization process. The information stored by ``PangoContext`` includes the fontmap used to look up fonts, and default values such as the default language, default gravity, or default font. To obtain a ``PangoContext``\, use :obj:`~gi.repository.Pango.FontMap.create_context`\. Constructors ------------ .. rst-class:: interim-class .. class:: Context :no-index: .. classmethod:: new() -> ~gi.repository.Pango.Context Creates a new ``PangoContext`` initialized to default values. This function is not particularly useful as it should always be followed by a :obj:`~gi.repository.Pango.Context.set_font_map` call, and the function :obj:`~gi.repository.Pango.FontMap.create_context` does these two steps together and hence users are recommended to use that. If you are using Pango as part of a higher-level system, that system may have it's own way of create a ``PangoContext``\. For instance, the GTK toolkit has, among others, ``gtk_widget_get_pango_context()``\. Use those instead. Methods ------- .. rst-class:: interim-class .. class:: Context :no-index: .. method:: changed() -> None Forces a change in the context, which will cause any ``PangoLayout`` using this context to re-layout. This function is only useful when implementing a new backend for Pango, something applications won't do. Backends should call this function if they have attached extra data to the context and such data is changed. .. versionadded:: 1.32.4 .. method:: get_base_dir() -> ~gi.repository.Pango.Direction Retrieves the base direction for the context. See :obj:`~gi.repository.Pango.Context.set_base_dir`\. .. method:: get_base_gravity() -> ~gi.repository.Pango.Gravity Retrieves the base gravity for the context. See :obj:`~gi.repository.Pango.Context.set_base_gravity`\. .. versionadded:: 1.16 .. method:: get_font_description() -> ~gi.repository.Pango.FontDescription | None Retrieve the default font description for the context. .. method:: get_font_map() -> ~gi.repository.Pango.FontMap | None Gets the ``PangoFontMap`` used to look up fonts for this context. .. versionadded:: 1.6 .. method:: get_gravity() -> ~gi.repository.Pango.Gravity Retrieves the gravity for the context. This is similar to :obj:`~gi.repository.Pango.Context.get_base_gravity`\, except for when the base gravity is :const:`~gi.repository.Pango.Gravity.AUTO` for which :obj:`~gi.repository.Pango.Gravity.get_for_matrix` is used to return the gravity from the current context matrix. .. versionadded:: 1.16 .. method:: get_gravity_hint() -> ~gi.repository.Pango.GravityHint Retrieves the gravity hint for the context. See :obj:`~gi.repository.Pango.Context.set_gravity_hint` for details. .. versionadded:: 1.16 .. method:: get_language() -> ~gi.repository.Pango.Language Retrieves the global language tag for the context. .. method:: get_matrix() -> ~gi.repository.Pango.Matrix | None Gets the transformation matrix that will be applied when rendering with this context. See :obj:`~gi.repository.Pango.Context.set_matrix`\. .. versionadded:: 1.6 .. method:: get_metrics(desc: ~gi.repository.Pango.FontDescription | None = None, language: ~gi.repository.Pango.Language | None = None) -> ~gi.repository.Pango.FontMetrics Get overall metric information for a particular font description. Since the metrics may be substantially different for different scripts, a language tag can be provided to indicate that the metrics should be retrieved that correspond to the script(s) used by that language. The ``PangoFontDescription`` is interpreted in the same way as by :obj:`~gi.repository.Pango.itemize`\, and the family name may be a comma separated list of names. If characters from multiple of these families would be used to render the string, then the returned fonts would be a composite of the metrics for the fonts loaded for the individual families. :param desc: a ``PangoFontDescription`` structure. :const:`None` means that the font description from the context will be used. :param language: language tag used to determine which script to get the metrics for. :const:`None` means that the language tag from the context will be used. If no language tag is set on the context, metrics for the default language (as determined by :obj:`~gi.repository.Pango.Language.get_default` will be returned. .. method:: get_round_glyph_positions() -> bool Returns whether font rendering with this context should round glyph positions and widths. .. versionadded:: 1.44 .. method:: get_serial() -> int Returns the current serial number of ``context``\. The serial number is initialized to an small number larger than zero when a new context is created and is increased whenever the context is changed using any of the setter functions, or the ``PangoFontMap`` it uses to find fonts has changed. The serial may wrap, but will never have the value 0. Since it can wrap, never compare it with "less than", always use "not equals". This can be used to automatically detect changes to a ``PangoContext``\, and is only useful when implementing objects that need update when their ``PangoContext`` changes, like ``PangoLayout``\. .. versionadded:: 1.32.4 .. method:: list_families() -> list[~gi.repository.Pango.FontFamily] List all families for a context. .. method:: load_font(desc: ~gi.repository.Pango.FontDescription) -> ~gi.repository.Pango.Font | None Loads the font in one of the fontmaps in the context that is the closest match for ``desc``\. :param desc: a ``PangoFontDescription`` describing the font to load .. method:: load_fontset(desc: ~gi.repository.Pango.FontDescription, language: ~gi.repository.Pango.Language) -> ~gi.repository.Pango.Fontset | None Load a set of fonts in the context that can be used to render a font matching ``desc``\. :param desc: a ``PangoFontDescription`` describing the fonts to load :param language: a ``PangoLanguage`` the fonts will be used for .. method:: set_base_dir(direction: ~gi.repository.Pango.Direction) -> None Sets the base direction for the context. The base direction is used in applying the Unicode bidirectional algorithm; if the ``direction`` is :const:`~gi.repository.Pango.Direction.LTR` or :const:`~gi.repository.Pango.Direction.RTL`, then the value will be used as the paragraph direction in the Unicode bidirectional algorithm. A value of :const:`~gi.repository.Pango.Direction.WEAK_LTR` or :const:`~gi.repository.Pango.Direction.WEAK_RTL` is used only for paragraphs that do not contain any strong characters themselves. :param direction: the new base direction .. method:: set_base_gravity(gravity: ~gi.repository.Pango.Gravity) -> None Sets the base gravity for the context. The base gravity is used in laying vertical text out. .. versionadded:: 1.16 :param gravity: the new base gravity .. method:: set_font_description(desc: ~gi.repository.Pango.FontDescription | None = None) -> None Set the default font description for the context :param desc: the new pango font description .. method:: set_font_map(font_map: ~gi.repository.Pango.FontMap | None = None) -> None Sets the font map to be searched when fonts are looked-up in this context. This is only for internal use by Pango backends, a ``PangoContext`` obtained via one of the recommended methods should already have a suitable font map. :param font_map: the ``PangoFontMap`` to set. .. method:: set_gravity_hint(hint: ~gi.repository.Pango.GravityHint) -> None Sets the gravity hint for the context. The gravity hint is used in laying vertical text out, and is only relevant if gravity of the context as returned by :obj:`~gi.repository.Pango.Context.get_gravity` is set to :const:`~gi.repository.Pango.Gravity.EAST` or :const:`~gi.repository.Pango.Gravity.WEST`. .. versionadded:: 1.16 :param hint: the new gravity hint .. method:: set_language(language: ~gi.repository.Pango.Language | None = None) -> None Sets the global language tag for the context. The default language for the locale of the running process can be found using :obj:`~gi.repository.Pango.Language.get_default`\. :param language: the new language tag. .. method:: set_matrix(matrix: ~gi.repository.Pango.Matrix | None = None) -> None Sets the transformation matrix that will be applied when rendering with this context. Note that reported metrics are in the user space coordinates before the application of the matrix, not device-space coordinates after the application of the matrix. So, they don't scale with the matrix, though they may change slightly for different matrices, depending on how the text is fit to the pixel grid. .. versionadded:: 1.6 :param matrix: a ``PangoMatrix``\, or :const:`None` to unset any existing matrix. (No matrix set is the same as setting the identity matrix.) .. method:: set_round_glyph_positions(round_positions: bool) -> None Sets whether font rendering with this context should round glyph positions and widths to integral positions, in device units. This is useful when the renderer can't handle subpixel positioning of glyphs. The default value is to round glyph positions, to remain compatible with previous Pango behavior. .. versionadded:: 1.44 :param round_positions: whether to round glyph positions