Pango.Renderer¶
class — extends GObject.Object
PangoRenderer is a base class for objects that can render text
provided as PangoGlyphString or PangoLayout.
By subclassing PangoRenderer and overriding operations such as
draw_glyphs and draw_rectangle, renderers for particular font
backends and destinations can be created.
Methods¶
activate¶
Does initial setup before rendering operations on renderer.
Renderer.deactivate should be called when done drawing.
Calls such as Renderer.draw_layout automatically
activate the layout before drawing on it.
Calls to Renderer.activate and
Renderer.deactivate can be nested and the
renderer will only be initialized and deinitialized once.
deactivate¶
Cleans up after rendering operations on renderer.
See docs for Renderer.activate.
draw_error_underline¶
Draw a squiggly line 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.
This should be called while renderer is already active.
Use Renderer.activate to activate a renderer.
Parameters:
x— X coordinate of underline, in Pango units in user coordinate systemy— Y coordinate of underline, in Pango units in user coordinate systemwidth— width of underline, in Pango units in user coordinate systemheight— height of underline, in Pango units in user coordinate system
draw_glyph¶
Draws a single glyph with coordinates in device space.
Parameters:
font— aPangoFontglyph— the glyph index of a single glyphx— X coordinate of left edge of baseline of glyphy— Y coordinate of left edge of baseline of glyph
draw_glyph_item¶
Draws the glyphs in glyph_item with the specified PangoRenderer,
embedding the text associated with the glyphs in the output if the
output format supports it.
This is useful for rendering text in PDF.
Note that this method does not handle attributes in glyph_item.
If you want colors, shapes and lines handled automatically according
to those attributes, you need to use Renderer.draw_layout_line
or Renderer.draw_layout.
Note that text is the start of the text for layout, which is then
indexed by glyph_item->item->offset.
If text is None, this simply calls Renderer.draw_glyphs.
The default implementation of this method simply falls back to
Renderer.draw_glyphs.
Parameters:
text— the UTF-8 text thatglyph_itemrefers toglyph_item— aPangoGlyphItemx— X position of left edge of baseline, in user space coordinates in Pango unitsy— Y position of left edge of baseline, in user space coordinates in Pango units
draw_glyphs¶
Draws the glyphs in glyphs with the specified PangoRenderer.
Parameters:
font— aPangoFontglyphs— aPangoGlyphStringx— X position of left edge of baseline, in user space coordinates in Pango units.y— Y position of left edge of baseline, in user space coordinates in Pango units.
draw_layout¶
Draws layout with the specified PangoRenderer.
This is equivalent to drawing the lines of the layout, at their
respective positions relative to x, y.
Parameters:
layout— aPangoLayoutx— X position of left edge of baseline, in user space coordinates in Pango units.y— Y position of left edge of baseline, in user space coordinates in Pango units.
draw_layout_line¶
Draws line with the specified PangoRenderer.
This draws the glyph items that make up the line, as well as shapes, backgrounds and lines that are specified by the attributes of those items.
Parameters:
line— aPangoLayoutLinex— X position of left edge of baseline, in user space coordinates in Pango units.y— Y position of left edge of baseline, in user space coordinates in Pango units.
draw_rectangle¶
Draws an axis-aligned rectangle in user space coordinates with the
specified PangoRenderer.
This should be called while renderer is already active.
Use Renderer.activate to activate a renderer.
Parameters:
part— type of object this rectangle is part ofx— X position at which to draw rectangle, in user space coordinates in Pango unitsy— Y position at which to draw rectangle, in user space coordinates in Pango unitswidth— width of rectangle in Pango unitsheight— height of rectangle in Pango units
draw_trapezoid¶
def draw_trapezoid(self, part: RenderPart | int, y1_: float, x11: float, x21: float, y2: float, x12: float, x22: float) -> None
Draws a trapezoid with the parallel sides aligned with the X axis
using the given PangoRenderer; coordinates are in device space.
Parameters:
part— type of object this trapezoid is part ofy1_— Y coordinate of top of trapezoidx11— X coordinate of left end of top of trapezoidx21— X coordinate of right end of top of trapezoidy2— Y coordinate of bottom of trapezoidx12— X coordinate of left end of bottom of trapezoidx22— X coordinate of right end of bottom of trapezoid
get_alpha¶
Gets the current alpha for the specified part.
Parameters:
part— the part to get the alpha for
get_color¶
Gets the current rendering color for the specified part.
Parameters:
part— the part to get the color for
get_layout¶
Gets the layout currently being rendered using renderer.
Calling this function only makes sense from inside a subclass's methods, like in its draw_shape vfunc, for example.
The returned layout should not be modified while still being rendered.
get_layout_line¶
Gets the layout line currently being rendered using renderer.
Calling this function only makes sense from inside a subclass's methods, like in its draw_shape vfunc, for example.
The returned layout line should not be modified while still being rendered.
get_matrix¶
Gets the transformation matrix that will be applied when rendering.
See Renderer.set_matrix.
part_changed¶
Informs Pango that the way that the rendering is done
for part has changed.
This should be called if the rendering changes in a way that would
prevent multiple pieces being joined together into one drawing call.
For instance, if a subclass of PangoRenderer was to add a stipple
option for drawing underlines, it needs to call
When the stipple changes or underlines with different stipples
might be joined together. Pango automatically calls this for
changes to colors. (See Renderer.set_color)
Parameters:
part— the part for which rendering has changed.
set_alpha¶
Sets the alpha for part of the rendering.
Note that the alpha may only be used if a color is
specified for part as well.
Parameters:
part— the part to set the alpha foralpha— an alpha value between 1 and 65536, or 0 to unset the alpha
set_color¶
Sets the color for part of the rendering.
Also see Renderer.set_alpha.
Parameters:
part— the part to change the color ofcolor— the new color orNoneto unset the current color
set_matrix¶
Sets the transformation matrix that will be applied when rendering.
Parameters:
matrix— aPangoMatrix, orNoneto unset any existing matrix (No matrix set is the same as setting the identity matrix.)
Virtual methods¶
do_begin¶
Do renderer-specific initialization before drawing
do_draw_error_underline¶
Draw a squiggly line 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.
This should be called while renderer is already active.
Use Renderer.activate to activate a renderer.
Parameters:
x— X coordinate of underline, in Pango units in user coordinate systemy— Y coordinate of underline, in Pango units in user coordinate systemwidth— width of underline, in Pango units in user coordinate systemheight— height of underline, in Pango units in user coordinate system
do_draw_glyph¶
Draws a single glyph with coordinates in device space.
Parameters:
font— aPangoFontglyph— the glyph index of a single glyphx— X coordinate of left edge of baseline of glyphy— Y coordinate of left edge of baseline of glyph
do_draw_glyph_item¶
Draws the glyphs in glyph_item with the specified PangoRenderer,
embedding the text associated with the glyphs in the output if the
output format supports it.
This is useful for rendering text in PDF.
Note that this method does not handle attributes in glyph_item.
If you want colors, shapes and lines handled automatically according
to those attributes, you need to use Renderer.draw_layout_line
or Renderer.draw_layout.
Note that text is the start of the text for layout, which is then
indexed by glyph_item->item->offset.
If text is None, this simply calls Renderer.draw_glyphs.
The default implementation of this method simply falls back to
Renderer.draw_glyphs.
Parameters:
text— the UTF-8 text thatglyph_itemrefers toglyph_item— aPangoGlyphItemx— X position of left edge of baseline, in user space coordinates in Pango unitsy— Y position of left edge of baseline, in user space coordinates in Pango units
do_draw_glyphs¶
Draws the glyphs in glyphs with the specified PangoRenderer.
Parameters:
font— aPangoFontglyphs— aPangoGlyphStringx— X position of left edge of baseline, in user space coordinates in Pango units.y— Y position of left edge of baseline, in user space coordinates in Pango units.
do_draw_rectangle¶
def do_draw_rectangle(self, part: RenderPart | int, x: int, y: int, width: int, height: int) -> None
Draws an axis-aligned rectangle in user space coordinates with the
specified PangoRenderer.
This should be called while renderer is already active.
Use Renderer.activate to activate a renderer.
Parameters:
part— type of object this rectangle is part ofx— X position at which to draw rectangle, in user space coordinates in Pango unitsy— Y position at which to draw rectangle, in user space coordinates in Pango unitswidth— width of rectangle in Pango unitsheight— height of rectangle in Pango units
do_draw_shape¶
draw content for a glyph shaped with PangoAttrShape
x, y are the coordinates of the left edge of the baseline,
in user coordinates.
do_draw_trapezoid¶
def do_draw_trapezoid(self, part: RenderPart | int, y1_: float, x11: float, x21: float, y2: float, x12: float, x22: float) -> None
Draws a trapezoid with the parallel sides aligned with the X axis
using the given PangoRenderer; coordinates are in device space.
Parameters:
part— type of object this trapezoid is part ofy1_— Y coordinate of top of trapezoidx11— X coordinate of left end of top of trapezoidx21— X coordinate of right end of top of trapezoidy2— Y coordinate of bottom of trapezoidx12— X coordinate of left end of bottom of trapezoidx22— X coordinate of right end of bottom of trapezoid
do_end¶
Do renderer-specific cleanup after drawing
do_part_changed¶
Informs Pango that the way that the rendering is done
for part has changed.
This should be called if the rendering changes in a way that would
prevent multiple pieces being joined together into one drawing call.
For instance, if a subclass of PangoRenderer was to add a stipple
option for drawing underlines, it needs to call
When the stipple changes or underlines with different stipples
might be joined together. Pango automatically calls this for
changes to colors. (See Renderer.set_color)
Parameters:
part— the part for which rendering has changed.
do_prepare_run¶
updates the renderer for a new run