Functions
- context_get_font_options(context: Context) FontOptions | None
Retrieves any font rendering options previously set with
context_set_font_options
.This function does not report options that are derived from the target surface by
update_context
.Added in version 1.10.
- Parameters:
context – a
PangoContext
, from a pangocairo font map- Returns:
the font options previously set on the context, or
None
if no options have been set. This value is owned by the context and must not be modified or freed.
- context_get_resolution(context: Context) float
Gets the resolution for the context.
Added in version 1.10.
- Parameters:
context – a
PangoContext
, from a pangocairo font map- Returns:
the resolution in “dots per inch”. A negative value will be returned if no resolution has previously been set.
- context_set_font_options(context: Context, options: FontOptions | None = None) None
Sets the font options used when rendering text with this context.
These options override any options that
update_context
derives from the target surface.Added in version 1.10.
- Parameters:
context – a
PangoContext
, from a pangocairo font mapoptions – a
cairo_font_options_t
, orNone
to unset any previously set options. A copy is made.
- context_set_resolution(context: 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).Added in version 1.10.
- Parameters:
context – a
PangoContext
, from a pangocairo font mapdpi – 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.
- context_set_shape_renderer(context: Context, func: Callable[[...], None] | None = None, *data: Any) None
Sets callback function for context to use for rendering attributes of type
%PANGO_ATTR_SHAPE
.See
PangoCairoShapeRendererFunc
for details.Added in version 1.18.
- Parameters:
context – a
PangoContext
, from a pangocairo font mapfunc – Callback function for rendering attributes of type
``%PANGO_ATTR_SHAPE``
, orNone
to disable shape rendering.data – User data that will be passed to
func
.
- create_context(cr: Context) 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
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 withcr
and do not need to accessPangoContext
directly, you can usecreate_layout
instead.Added in version 1.22.
- Parameters:
cr – a Cairo context
- Returns:
the newly created
PangoContext
- create_layout(cr: Context) 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
get_size
or drawing with functions likeshow_layout
. If you change the transformation or target surface forcr
, you need to callupdate_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.Added in version 1.10.
- Parameters:
cr – a Cairo context
- Returns:
the newly created
PangoLayout
- error_underline_path(cr: 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.
Added in version 1.14.
- Parameters:
cr – a Cairo context
x – The X coordinate of one corner of the rectangle
y – The Y coordinate of one corner of the rectangle
width – Non-negative width of the rectangle
height – Non-negative height of the rectangle
- glyph_string_path(cr: Context, font: Font, glyphs: 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.
Added in version 1.10.
- Parameters:
cr – a Cairo context
font – a
PangoFont
from aPangoCairoFontMap
glyphs – a
PangoGlyphString
- layout_line_path(cr: Context, line: 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.
Added in version 1.10.
- Parameters:
cr – a Cairo context
line – a
PangoLayoutLine
- layout_path(cr: Context, layout: 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.Added in version 1.10.
- Parameters:
cr – a Cairo context
layout – a Pango layout
- show_error_underline(cr: 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.
Added in version 1.14.
- Parameters:
cr – a Cairo context
x – The X coordinate of one corner of the rectangle
y – The Y coordinate of one corner of the rectangle
width – Non-negative width of the rectangle
height – Non-negative height of the rectangle
- show_glyph_item(cr: Context, text: str, glyph_item: 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
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 byglyph_item->item->offset
.Added in version 1.22.
- Parameters:
cr – a Cairo context
text – the UTF-8 text that
glyph_item
refers toglyph_item – a
PangoGlyphItem
- show_glyph_string(cr: Context, font: Font, glyphs: 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.
Added in version 1.10.
- Parameters:
cr – a Cairo context
font – a
PangoFont
from aPangoCairoFontMap
glyphs – a
PangoGlyphString
- show_layout(cr: Context, layout: 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.Added in version 1.10.
- Parameters:
cr – a Cairo context
layout – a Pango layout
- show_layout_line(cr: Context, line: 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.
Added in version 1.10.
- Parameters:
cr – a Cairo context
line – a
PangoLayoutLine
- update_context(cr: Context, context: 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
context_changed
on those layouts.Added in version 1.10.
- Parameters:
cr – a Cairo context
context – a
PangoContext
, from a pangocairo font map
- update_layout(cr: Context, layout: Layout) None
Updates the private
PangoContext
of aPangoLayout
created withcreate_layout
to match the current transformation and target surface of a Cairo context.Added in version 1.10.
- Parameters:
cr – a Cairo context
layout – a
PangoLayout
, fromcreate_layout