Canvas

class plutoprint.Canvas[source]

An abstract base class that provides an interface for drawing graphics on a canvas.

__enter__() AnyCanvas[source]

Enters a runtime context related to this object. Used to support the context management protocol.

Returns:

The canvas instance.

__exit__(*exc_info: Any) None[source]

Exits the runtime context related to this object. Used to support the context management protocol.

Parameters:

exc_info – Exception information.

flush() None[source]

Flushes any pending drawing operations.

finish() None[source]

Finishes all drawing operations and cleans up the canvas.

translate(tx: float, ty: float) None[source]

Moves the canvas and its origin to a different point.

Parameters:
  • tx – The translation offset in the x-direction.

  • ty – The translation offset in the y-direction.

scale(sx: float, sy: float) None[source]

Scales the canvas units by the specified factors.

Parameters:
  • sx – The scaling factor in the x-direction.

  • sy – The scaling factor in the y-direction.

rotate(angle: float) None[source]

Rotates the canvas around the current origin.

Parameters:

angle – The rotation angle in radians.

transform(a: float, b: float, c: float, d: float, e: float, f: float) None[source]

Multiplies the current transformation matrix with the specified matrix.

Parameters:
  • a – The horizontal scaling factor.

  • b – The horizontal skewing factor.

  • c – The vertical skewing factor.

  • d – The vertical scaling factor.

  • e – The horizontal translation offset.

  • f – The vertical translation offset.

set_matrix(a: float, b: float, c: float, d: float, e: float, f: float) None[source]

Resets the transformation matrix to the specified matrix.

Parameters:
  • a – The horizontal scaling factor.

  • b – The horizontal skewing factor.

  • c – The vertical skewing factor.

  • d – The vertical scaling factor.

  • e – The horizontal translation offset.

  • f – The vertical translation offset.

reset_matrix() None[source]

Resets the current transformation to the identity matrix.

clip_rect(x: float, y: float, width: float, height: float) None[source]

Intersects the current clip with the specified rectangle.

Parameters:
  • x – The x-coordinate of the top-left corner of the rectangle.

  • y – The y-coordinate of the top-left corner of the rectangle.

  • width – The width of the rectangle.

  • height – The height of the rectangle.

clear_surface(red: float, green: float, blue: float, alpha: float = 1.0) None[source]

Clears the canvas surface with the specified color.

Parameters:
  • red – The red component of the color.

  • green – The green component of the color.

  • blue – The blue component of the color.

  • alpha – The alpha component of the color.

save_state() None[source]

Saves the current state of the canvas.

restore_state() None[source]

Restores the most recently saved state of the canvas.

class plutoprint.AnyCanvas

A type variable that represents any subclass of Canvas.

alias of TypeVar(‘AnyCanvas’, bound=Canvas)