Functions ========= .. currentmodule:: gi.repository.PangoCairo .. function:: context_get_font_options(context: ~gi.repository.Pango.Context) -> ~gi.repository.cairo.FontOptions | None Retrieves any font rendering options previously set with :obj:`~gi.repository.PangoCairo.context_set_font_options`\. This function does not report options that are derived from the target surface by :obj:`~gi.repository.PangoCairo.update_context`\. .. versionadded:: 1.10 :param context: a ``PangoContext``\, from a pangocairo font map :return: the font options previously set on the context, or :const:`None` if no options have been set. This value is owned by the context and must not be modified or freed. .. function:: context_get_resolution(context: ~gi.repository.Pango.Context) -> float Gets the resolution for the context. See :obj:`~gi.repository.PangoCairo.context_set_resolution` .. versionadded:: 1.10 :param context: a ``PangoContext``\, from a pangocairo font map :return: the resolution in "dots per inch". A negative value will be returned if no resolution has previously been set. .. function:: context_set_font_options(context: ~gi.repository.Pango.Context, options: ~gi.repository.cairo.FontOptions | None = None) -> None Sets the font options used when rendering text with this context. These options override any options that :obj:`~gi.repository.PangoCairo.update_context` derives from the target surface. .. versionadded:: 1.10 :param context: a ``PangoContext``\, from a pangocairo font map :param options: a ``cairo_font_options_t``\, or :const:`None` to unset any previously set options. A copy is made. .. function:: context_set_resolution(context: ~gi.repository.Pango.Context, dpi: float) -> None Sets the resolution for the context. This is a scale factor between points specified in a ``PangoFontDescription`` and Cairo units. The default value is 96, meaning that a 10 point font will be 13 units high. (10 * 96. / 72. = 13.3). .. versionadded:: 1.10 :param context: a ``PangoContext``\, from a pangocairo font map :param dpi: the resolution in "dots per inch". (Physical inches aren't actually involved; the terminology is conventional.) A 0 or negative value means to use the resolution from the font map. .. function:: context_set_shape_renderer(context: ~gi.repository.Pango.Context, func: ~typing.Callable[[~gi.repository.cairo.Context, ~gi.repository.Pango.AttrShape, bool, ~typing.Any], None] | None = None, data: ~typing.Any = None) -> None Sets callback function for context to use for rendering attributes of type %PANGO_ATTR_SHAPE. See ``PangoCairoShapeRendererFunc`` for details. .. versionadded:: 1.18 :param context: a ``PangoContext``\, from a pangocairo font map :param func: Callback function for rendering attributes of type %PANGO_ATTR_SHAPE, or :const:`None` to disable shape rendering. :param data: User data that will be passed to ``func``\. .. function:: create_context(cr: ~gi.repository.cairo.Context) -> ~gi.repository.Pango.Context Creates a context object set up to match the current transformation and target surface of the Cairo context. This context can then be used to create a layout using :obj:`~gi.repository.Pango.Layout.new`\. This function is a convenience function that creates a context using the default font map, then updates it to ``cr``\. If you just need to create a layout for use with ``cr`` and do not need to access ``PangoContext`` directly, you can use :obj:`~gi.repository.PangoCairo.create_layout` instead. .. versionadded:: 1.22 :param cr: a Cairo context :return: the newly created ``PangoContext`` .. function:: create_layout(cr: ~gi.repository.cairo.Context) -> ~gi.repository.Pango.Layout Creates a layout object set up to match the current transformation and target surface of the Cairo context. This layout can then be used for text measurement with functions like :obj:`~gi.repository.Pango.Layout.get_size` or drawing with functions like :obj:`~gi.repository.PangoCairo.show_layout`\. If you change the transformation or target surface for ``cr``\, you need to call :obj:`~gi.repository.PangoCairo.update_layout`\. This function is the most convenient way to use Cairo with Pango, however it is slightly inefficient since it creates a separate ``PangoContext`` object for each layout. This might matter in an application that was laying out large amounts of text. .. versionadded:: 1.10 :param cr: a Cairo context :return: the newly created ``PangoLayout`` .. function:: error_underline_path(cr: ~gi.repository.cairo.Context, x: float, y: float, width: float, height: float) -> None Add a squiggly line to the current path in the specified cairo context that approximately covers the given rectangle in the style of an underline used to indicate a spelling error. The width of the underline is rounded to an integer number of up/down segments and the resulting rectangle is centered in the original rectangle. .. versionadded:: 1.14 :param cr: a Cairo context :param x: The X coordinate of one corner of the rectangle :param y: The Y coordinate of one corner of the rectangle :param width: Non-negative width of the rectangle :param height: Non-negative height of the rectangle .. function:: font_map_get_default() -> ~gi.repository.Pango.FontMap .. function:: font_map_new() -> ~gi.repository.Pango.FontMap .. function:: font_map_new_for_font_type(fonttype: ~gi.repository.cairo.FontType) -> ~gi.repository.Pango.FontMap | None :param fonttype: .. function:: glyph_string_path(cr: ~gi.repository.cairo.Context, font: ~gi.repository.Pango.Font, glyphs: ~gi.repository.Pango.GlyphString) -> None Adds the glyphs in ``glyphs`` to the current path in the specified cairo context. The origin of the glyphs (the left edge of the baseline) will be at the current point of the cairo context. .. versionadded:: 1.10 :param cr: a Cairo context :param font: a ``PangoFont`` from a ``PangoCairoFontMap`` :param glyphs: a ``PangoGlyphString`` .. function:: layout_line_path(cr: ~gi.repository.cairo.Context, line: ~gi.repository.Pango.LayoutLine) -> None Adds the text in ``PangoLayoutLine`` to the current path in the specified cairo context. The origin of the glyphs (the left edge of the line) will be at the current point of the cairo context. .. versionadded:: 1.10 :param cr: a Cairo context :param line: a ``PangoLayoutLine`` .. function:: layout_path(cr: ~gi.repository.cairo.Context, layout: ~gi.repository.Pango.Layout) -> None Adds the text in a ``PangoLayout`` to the current path in the specified cairo context. The top-left corner of the ``PangoLayout`` will be at the current point of the cairo context. .. versionadded:: 1.10 :param cr: a Cairo context :param layout: a Pango layout .. function:: show_error_underline(cr: ~gi.repository.cairo.Context, x: float, y: float, width: float, height: float) -> None Draw a squiggly line in the specified cairo context that approximately covers the given rectangle in the style of an underline used to indicate a spelling error. The width of the underline is rounded to an integer number of up/down segments and the resulting rectangle is centered in the original rectangle. .. versionadded:: 1.14 :param cr: a Cairo context :param x: The X coordinate of one corner of the rectangle :param y: The Y coordinate of one corner of the rectangle :param width: Non-negative width of the rectangle :param height: Non-negative height of the rectangle .. function:: show_glyph_item(cr: ~gi.repository.cairo.Context, text: str, glyph_item: ~gi.repository.Pango.GlyphItem) -> None Draws the glyphs in ``glyph_item`` in the specified cairo context, embedding the text associated with the glyphs in the output if the output format supports it (PDF for example), otherwise it acts similar to :obj:`~gi.repository.PangoCairo.show_glyph_string`\. The origin of the glyphs (the left edge of the baseline) will be drawn at the current point of the cairo context. Note that ``text`` is the start of the text for layout, which is then indexed by ``glyph_item->item->offset``\. .. versionadded:: 1.22 :param cr: a Cairo context :param text: the UTF-8 text that ``glyph_item`` refers to :param glyph_item: a ``PangoGlyphItem`` .. function:: show_glyph_string(cr: ~gi.repository.cairo.Context, font: ~gi.repository.Pango.Font, glyphs: ~gi.repository.Pango.GlyphString) -> None Draws the glyphs in ``glyphs`` in the specified cairo context. The origin of the glyphs (the left edge of the baseline) will be drawn at the current point of the cairo context. .. versionadded:: 1.10 :param cr: a Cairo context :param font: a ``PangoFont`` from a ``PangoCairoFontMap`` :param glyphs: a ``PangoGlyphString`` .. function:: show_layout(cr: ~gi.repository.cairo.Context, layout: ~gi.repository.Pango.Layout) -> None Draws a ``PangoLayout`` in the specified cairo context. The top-left corner of the ``PangoLayout`` will be drawn at the current point of the cairo context. .. versionadded:: 1.10 :param cr: a Cairo context :param layout: a Pango layout .. function:: show_layout_line(cr: ~gi.repository.cairo.Context, line: ~gi.repository.Pango.LayoutLine) -> None Draws a ``PangoLayoutLine`` in the specified cairo context. The origin of the glyphs (the left edge of the line) will be drawn at the current point of the cairo context. .. versionadded:: 1.10 :param cr: a Cairo context :param line: a ``PangoLayoutLine`` .. function:: update_context(cr: ~gi.repository.cairo.Context, context: ~gi.repository.Pango.Context) -> None Updates a ``PangoContext`` previously created for use with Cairo to match the current transformation and target surface of a Cairo context. If any layouts have been created for the context, it's necessary to call :obj:`~gi.repository.Pango.Layout.context_changed` on those layouts. .. versionadded:: 1.10 :param cr: a Cairo context :param context: a ``PangoContext``\, from a pangocairo font map .. function:: update_layout(cr: ~gi.repository.cairo.Context, layout: ~gi.repository.Pango.Layout) -> None Updates the private ``PangoContext`` of a ``PangoLayout`` created with :obj:`~gi.repository.PangoCairo.create_layout` to match the current transformation and target surface of a Cairo context. .. versionadded:: 1.10 :param cr: a Cairo context :param layout: a ``PangoLayout``\, from :obj:`~gi.repository.PangoCairo.create_layout`