Pango.Renderer

g GObject.Object GObject.Object Pango.Renderer Pango.Renderer GObject.Object->Pango.Renderer

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

activate ()

deactivate ()

draw_error_underline (x, y, width, height)

draw_glyph (font, glyph, x, y)

draw_glyph_item (text, glyph_item, x, y)

draw_glyphs (font, glyphs, x, y)

draw_layout (layout, x, y)

draw_layout_line (line, x, y)

draw_rectangle (part, x, y, width, height)

draw_trapezoid (part, y1_, x11, x21, y2, x12, x22)

get_alpha (part)

get_color (part)

get_layout ()

get_layout_line ()

get_matrix ()

part_changed (part)

set_alpha (part, alpha)

set_color (part, color)

set_matrix (matrix)

Virtual Methods

Inherited:

GObject.Object (7)

do_begin ()

do_draw_error_underline (x, y, width, height)

do_draw_glyph (font, glyph, x, y)

do_draw_glyph_item (text, glyph_item, x, y)

do_draw_glyphs (font, glyphs, x, y)

do_draw_rectangle (part, x, y, width, height)

do_draw_shape (attr, x, y)

do_draw_trapezoid (part, y1_, x11, x21, y2, x12, x22)

do_end ()

do_part_changed (part)

do_prepare_run (run)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

active_count

int

r

matrix

Pango.Matrix

r

the current transformation matrix for the Renderer; may be None, which should be treated the same as the identity matrix.

parent_instance

GObject.Object

r

strikethrough

bool

r

underline

Pango.Underline

r

Class Details

class Pango.Renderer(**kwargs)
Bases:

GObject.Object

Abstract:

Yes

Structure:

Pango.RendererClass

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.

New in version 1.8.

activate()[source]

Does initial setup before rendering operations on self.

[method`Pango`.Renderer.deactivate] should be called when done drawing. Calls such as [method`Pango`.Renderer.draw_layout] automatically activate the layout before drawing on it.

Calls to [method`Pango`.Renderer.activate] and [method`Pango`.Renderer.deactivate] can be nested and the renderer will only be initialized and deinitialized once.

New in version 1.8.

deactivate()[source]

Cleans up after rendering operations on self.

See docs for [method`Pango`.Renderer.activate].

New in version 1.8.

draw_error_underline(x, y, width, height)[source]
Parameters:
  • x (int) – X coordinate of underline, in Pango units in user coordinate system

  • y (int) – Y coordinate of underline, in Pango units in user coordinate system

  • width (int) – width of underline, in Pango units in user coordinate system

  • height (int) – height of underline, in Pango units in user coordinate system

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 self is already active. Use [method`Pango`.Renderer.activate] to activate a renderer.

New in version 1.8.

draw_glyph(font, glyph, x, y)[source]
Parameters:
  • font (Pango.Font) – a PangoFont

  • glyph (int) – the glyph index of a single glyph

  • x (float) – X coordinate of left edge of baseline of glyph

  • y (float) – Y coordinate of left edge of baseline of glyph

Draws a single glyph with coordinates in device space.

New in version 1.8.

draw_glyph_item(text, glyph_item, x, y)[source]
Parameters:
  • text (str or None) – the UTF-8 text that glyph_item refers to

  • glyph_item (Pango.GlyphItem) – a PangoGlyphItem

  • x (int) – X position of left edge of baseline, in user space coordinates in Pango units

  • y (int) – Y position of left edge of baseline, in user space coordinates in Pango units

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 Pango.Renderer.draw_layout_line() or Pango.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 [method`Pango`.Renderer.draw_glyphs].

The default implementation of this method simply falls back to [method`Pango`.Renderer.draw_glyphs].

New in version 1.22.

draw_glyphs(font, glyphs, x, y)[source]
Parameters:
  • font (Pango.Font) – a PangoFont

  • glyphs (Pango.GlyphString) – a PangoGlyphString

  • x (int) – X position of left edge of baseline, in user space coordinates in Pango units.

  • y (int) – Y position of left edge of baseline, in user space coordinates in Pango units.

Draws the glyphs in glyphs with the specified PangoRenderer.

New in version 1.8.

draw_layout(layout, x, y)[source]
Parameters:
  • layout (Pango.Layout) – a PangoLayout

  • x (int) – X position of left edge of baseline, in user space coordinates in Pango units.

  • y (int) – Y position of left edge of baseline, in user space coordinates in Pango units.

Draws layout with the specified PangoRenderer.

This is equivalent to drawing the lines of the layout, at their respective positions relative to x, y.

New in version 1.8.

draw_layout_line(line, x, y)[source]
Parameters:
  • line (Pango.LayoutLine) – a PangoLayoutLine

  • x (int) – X position of left edge of baseline, in user space coordinates in Pango units.

  • y (int) – Y position of left edge of baseline, in user space coordinates in Pango units.

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.

New in version 1.8.

draw_rectangle(part, x, y, width, height)[source]
Parameters:
  • part (Pango.RenderPart) – type of object this rectangle is part of

  • x (int) – X position at which to draw rectangle, in user space coordinates in Pango units

  • y (int) – Y position at which to draw rectangle, in user space coordinates in Pango units

  • width (int) – width of rectangle in Pango units

  • height (int) – height of rectangle in Pango units

Draws an axis-aligned rectangle in user space coordinates with the specified PangoRenderer.

This should be called while self is already active. Use [method`Pango`.Renderer.activate] to activate a renderer.

New in version 1.8.

draw_trapezoid(part, y1_, x11, x21, y2, x12, x22)[source]
Parameters:
  • part (Pango.RenderPart) – type of object this trapezoid is part of

  • y1 (float) – Y coordinate of top of trapezoid

  • x11 (float) – X coordinate of left end of top of trapezoid

  • x21 (float) – X coordinate of right end of top of trapezoid

  • y2 (float) – Y coordinate of bottom of trapezoid

  • x12 (float) – X coordinate of left end of bottom of trapezoid

  • x22 (float) – X coordinate of right end of bottom of trapezoid

Draws a trapezoid with the parallel sides aligned with the X axis using the given PangoRenderer; coordinates are in device space.

New in version 1.8.

get_alpha(part)[source]
Parameters:

part (Pango.RenderPart) – the part to get the alpha for

Returns:

the alpha for the specified part, or 0 if it hasn’t been set and should be inherited from the environment.

Return type:

int

Gets the current alpha for the specified part.

New in version 1.38.

get_color(part)[source]
Parameters:

part (Pango.RenderPart) – the part to get the color for

Returns:

the color for the specified part, or None if it hasn’t been set and should be inherited from the environment.

Return type:

Pango.Color or None

Gets the current rendering color for the specified part.

New in version 1.8.

get_layout()[source]
Returns:

the layout, or None if no layout is being rendered using self at this time.

Return type:

Pango.Layout or None

Gets the layout currently being rendered using self.

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.

New in version 1.20.

get_layout_line()[source]
Returns:

the layout line, or None if no layout line is being rendered using self at this time.

Return type:

Pango.LayoutLine or None

Gets the layout line currently being rendered using self.

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.

New in version 1.20.

get_matrix()[source]
Returns:

the matrix, or None if no matrix has been set (which is the same as the identity matrix). The returned matrix is owned by Pango and must not be modified or freed.

Return type:

Pango.Matrix or None

Gets the transformation matrix that will be applied when rendering.

See [method`Pango`.Renderer.set_matrix].

New in version 1.8.

part_changed(part)[source]
Parameters:

part (Pango.RenderPart) – the part for which rendering has 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

`` pango_renderer_part_changed (render, PANGO_RENDER_PART_UNDERLINE); ``

When the stipple changes or underlines with different stipples might be joined together. Pango automatically calls this for changes to colors. (See [method`Pango`.Renderer.set_color])

New in version 1.8.

set_alpha(part, alpha)[source]
Parameters:
  • part (Pango.RenderPart) – the part to set the alpha for

  • alpha (int) – an alpha value between 1 and 65536, or 0 to unset the 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.

New in version 1.38.

set_color(part, color)[source]
Parameters:

Sets the color for part of the rendering.

Also see [method`Pango`.Renderer.set_alpha].

New in version 1.8.

set_matrix(matrix)[source]
Parameters:

matrix (Pango.Matrix or None) – a PangoMatrix, or None to unset any existing matrix (No matrix set is the same as setting the identity matrix.)

Sets the transformation matrix that will be applied when rendering.

New in version 1.8.

do_begin() virtual

Do renderer-specific initialization before drawing

do_draw_error_underline(x, y, width, height) virtual
Parameters:
  • x (int) – X coordinate of underline, in Pango units in user coordinate system

  • y (int) – Y coordinate of underline, in Pango units in user coordinate system

  • width (int) – width of underline, in Pango units in user coordinate system

  • height (int) – height of underline, in Pango units in user coordinate system

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 [method`Pango`.Renderer.activate] to activate a renderer.

New in version 1.8.

do_draw_glyph(font, glyph, x, y) virtual
Parameters:
  • font (Pango.Font) – a PangoFont

  • glyph (int) – the glyph index of a single glyph

  • x (float) – X coordinate of left edge of baseline of glyph

  • y (float) – Y coordinate of left edge of baseline of glyph

Draws a single glyph with coordinates in device space.

New in version 1.8.

do_draw_glyph_item(text, glyph_item, x, y) virtual
Parameters:
  • text (str or None) – the UTF-8 text that glyph_item refers to

  • glyph_item (Pango.GlyphItem) – a PangoGlyphItem

  • x (int) – X position of left edge of baseline, in user space coordinates in Pango units

  • y (int) – Y position of left edge of baseline, in user space coordinates in Pango units

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 Pango.Renderer.draw_layout_line() or Pango.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 [method`Pango`.Renderer.draw_glyphs].

The default implementation of this method simply falls back to [method`Pango`.Renderer.draw_glyphs].

New in version 1.22.

do_draw_glyphs(font, glyphs, x, y) virtual
Parameters:
  • font (Pango.Font) – a PangoFont

  • glyphs (Pango.GlyphString) – a PangoGlyphString

  • x (int) – X position of left edge of baseline, in user space coordinates in Pango units.

  • y (int) – Y position of left edge of baseline, in user space coordinates in Pango units.

Draws the glyphs in glyphs with the specified PangoRenderer.

New in version 1.8.

do_draw_rectangle(part, x, y, width, height) virtual
Parameters:
  • part (Pango.RenderPart) – type of object this rectangle is part of

  • x (int) – X position at which to draw rectangle, in user space coordinates in Pango units

  • y (int) – Y position at which to draw rectangle, in user space coordinates in Pango units

  • width (int) – width of rectangle in Pango units

  • height (int) – height of rectangle in Pango units

Draws an axis-aligned rectangle in user space coordinates with the specified PangoRenderer.

This should be called while renderer is already active. Use [method`Pango`.Renderer.activate] to activate a renderer.

New in version 1.8.

do_draw_shape(attr, x, y) virtual
Parameters:

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(part, y1_, x11, x21, y2, x12, x22) virtual
Parameters:
  • part (Pango.RenderPart) – type of object this trapezoid is part of

  • y1 (float) – Y coordinate of top of trapezoid

  • x11 (float) – X coordinate of left end of top of trapezoid

  • x21 (float) – X coordinate of right end of top of trapezoid

  • y2 (float) – Y coordinate of bottom of trapezoid

  • x12 (float) – X coordinate of left end of bottom of trapezoid

  • x22 (float) – X coordinate of right end of bottom of trapezoid

Draws a trapezoid with the parallel sides aligned with the X axis using the given PangoRenderer; coordinates are in device space.

New in version 1.8.

do_end() virtual

Do renderer-specific cleanup after drawing

do_part_changed(part) virtual
Parameters:

part (Pango.RenderPart) – the part for which rendering has 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

`` pango_renderer_part_changed (render, PANGO_RENDER_PART_UNDERLINE); ``

When the stipple changes or underlines with different stipples might be joined together. Pango automatically calls this for changes to colors. (See [method`Pango`.Renderer.set_color])

New in version 1.8.

do_prepare_run(run) virtual
Parameters:

run (Pango.GlyphItem) –

updates the renderer for a new run