2.5.2. Cairo Wrappers (layout.cairo_utils)

Cairo support.

Cairo uses a coordinate system where y increases from the bottom of the page upwards. Layout assumes the opposite coordinate system. So the context will be reversed in the y direction, and then text will need to be reversed back.

class layout.cairo_utils.CairoOutput(cairo_context)

Bases: layout.datatypes.output.OutputTarget

An output adapter for Cairo.

Assumes the Cairo context has already been reversed in the y-direction (i.e. so y increases downwards from the top of the page).

clip_rect(x, y, w, h)

Clip further output to this rect.

draw_image(img_filename, x, y, w, h)

Draws the given image.

draw_line(x0, y0, x1, y1, *, stroke, stroke_width=1, stroke_dash=None)

Draws the given line.

draw_polygon(*pts, close_path=True, stroke=None, stroke_width=1, stroke_dash=None, fill=None) → None

Draws the given polygon.

draw_rect(x, y, w, h, *, stroke=None, stroke_width=1, stroke_dash=None, fill=None)

Draws the given rectangle.

draw_text(text, x, y, *, font_name, font_size, fill)

Draws the given text at x,y.

end_page()

Complete the previous page and prepare to begin a new page.

rotate(degrees)

Rotate the current rendering context.

scale(x, y)

Scale the current rendering context.

text_width(text, *, font_name, font_size)

The width of the given text string.

translate(x, y)

Translate the current rendering context.

layout.cairo_utils.render_to_cairo_context(cairo_context, papersize_tuple, layout)

Renders the given layout manager on a page of the given context.

Assumes the given context has not yet been reversed in the y-direction (i.e. it is still the default for Cairo, where y increases up from the bottom of the page). This method performs the reversal and resets it before it returns.

layout.cairo_utils.render_to_cairo_document(output_filename, papersize_tuple, layout)

Create and save a document with contents of the given layout manager.