Method summary
- __init__(self, size, *args, **kw)
- add_path(self, path)
- arc(self, x, y, radius, start_angle, end_angle, cw = False)
- begin_page(self)
- begin_path(self)
- clear(self, color = (1, 1, 1))
- clear_clip_path(self)
- clear_rect(self)
- clip(self)
- clip_to_rect(self, x, y, width, height)
- close_path(self, tag = None)
- concat_ctm(self, transform)
- curve_to(self, x_ctrl1, y_ctrl1, x_ctrl2, y_ctrl2, x_to, y_to)
- draw_image(self, img, rect = None)
- draw_path(self, mode = constants.FILL_STROKE)
- end_page(self)
- even_odd_clip(self)
- fill_rect(self)
- fill_rects(self)
- flush(self)
- get_ctm(self)
- get_full_text_extent(self, textstring)
- get_path_bounding_box(self)
- get_path_current_point(self)
- get_text_extent(self, textstring)
- get_text_matrix(self)
- get_text_position(self)
- height(self)
- is_path_empty(self)
- line_set(self, starts, ends)
- line_to(self, x, y)
- linear_gradient(self, x1, y1, x2, y2, stops, spreadMethod = 'pad', transforms = None, units = 'userSpaceOnUse')
- lines(self, points)
- move_to(self, x, y)
- radial_gradient(self, cx, cy, r, stops, fx = None, fy = None, spreadMethod = 'pad', transforms = None, units = 'userSpaceOnUse')
- rect(self, x, y, sx, sy)
- render_component(self, component, container_coords = False)
- restore_state(self)
- rotate_ctm(self, angle)
- save_state(self)
- scale_ctm(self, sx, sy)
- select_font(self, face_name, size = 12, style = 'regular', encoding = None)
- set_alpha(self, alpha)
- set_antialias(self, value)
- set_character_spacing(self, spacing)
- set_fill_color(self, color)
- set_flatness(self, flatness)
- set_font(self, font)
- set_font_size(self, size)
- set_line_cap(self, style)
- set_line_dash(self, pattern, phase = 0)
- set_line_join(self, style)
- set_line_width(self, width)
- set_miter_limit(self, limit)
- set_stroke_color(self, color)
- set_text_drawing_mode(self, mode)
- set_text_matrix(self, ttm)
- set_text_position(self, x, y)
- show_glyphs(self)
- show_glyphs_at_point(self)
- show_text(self, text)
- show_text_at_point(self, text, x, y)
- stroke_rect(self)
- stroke_rect_with_width(self)
- synchronize(self)
- translate_ctm(self, tx, ty)
- width(self)
Methods
- __init__(self, size, *args, **kw)
- add_path(self, path)
Draw a compiled path into this gc. In this case, a compiled path is a Cairo.Path
- arc(self, x, y, radius, start_angle, end_angle, cw = False)
Draw a circular arc.
If there is a current path and the current point is not the initial point of the arc, a line will be drawn to the start of the arc. If there is no current path, then no line will be drawn.
Parameters
- x : float
- X-value of the center of the arc.
- y : float
- Y-value of the center of the arc.
- radius : float
- The radius of the arc.
- start_angle : float
- The angle, in radians, that the starting point makes with respect to the positive X-axis from the center point.
- end_angle : float
- The angles, in radians, that the final point makes with respect to the positive X-axis from the center point.
- cw : bool, optional
- Whether the arc should be drawn clockwise or not.
- begin_page(self)
Creates a new page within the graphics context.
Currently this is a NOP for all implementations. The PDF backend should probably implement it, but the ReportLab Canvas uses the showPage() method to handle both begin_page and end_page issues.
- begin_path(self)
Clears the current drawing path and begin a new one.
- clear(self, color = (1, 1, 1))
- clear_clip_path(self)
- clear_rect(self)
- clip(self)
Should this use clip or clip_preserve
- clip_to_rect(self, x, y, width, height)
Sets the clipping path to the intersection of the current clipping path with the area defined by the specified rectangle
- close_path(self, tag = None)
Closes the path of the current subpath.
Currently starts a new subpath -- is this what we want? ... Cairo starts a new subpath automatically.
- concat_ctm(self, transform)
Concatenates the transform to current coordinate transform matrix.
Parameters
- transform : affine_matrix
- the transform matrix to concatenate with the current coordinate matrix.
- curve_to(self, x_ctrl1, y_ctrl1, x_ctrl2, y_ctrl2, x_to, y_to)
Draw a cubic bezier curve from the current point.
Parameters
- x_ctrl1 : float
- X-value of the first control point.
- y_ctrl1 : float
- Y-value of the first control point.
- x_ctrl2 : float
- X-value of the second control point.
- y_ctrl2 : float
- Y-value of the second control point.
- x_to : float
- X-value of the ending point of the curve.
- y_to : float
- Y-value of the ending point of the curve.
- draw_image(self, img, rect = None)
img is either a N*M*3 or N*M*4 numpy array, or a Kiva image
rect - what is this? assume it's a tuple (x,y, w, h) Only works with numpy arrays. What is a "Kiva Image" anyway? Not Yet Tested.
- draw_path(self, mode = constants.FILL_STROKE)
Walks through all the drawing subpaths and draw each element.
Each subpath is drawn separately.
Parameters
- mode
Specifies how the subpaths are drawn. The default is FILL_STROKE. The following are valid values.
- FILL
- Paint the path using the nonzero winding rule to determine the regions for painting.
- EOF_FILL
- Paint the path using the even-odd fill rule.
- STROKE
- Draw the outline of the path with the current width, end caps, etc settings.
- FILL_STROKE
- First fill the path using the nonzero winding rule, then stroke the path.
- EOF_FILL_STROKE
- First fill the path using the even-odd fill method, then stroke the path.
- end_page(self)
Ends drawing in the current page of the graphics context.
Currently this is a NOP for all implementations. The PDF backend should probably implement it, but the ReportLab Canvas uses the showPage() method to handle both begin_page and end_page issues.
- even_odd_clip(self)
- fill_rect(self)
- fill_rects(self)
- flush(self)
Sends all drawing data to the destination device.
Currently this is a NOP for wxPython.
- get_ctm(self)
Returns the current coordinate transform matrix as a list of matrix elements
- get_full_text_extent(self, textstring)
How does this differ from 'get_text_extent' ???
This just calls get_text_extent, for the time being.
- get_path_bounding_box(self)
cairo.Context.path_extents not yet implemented on my cairo version. It's in new ones though.
What should this method return?
- get_path_current_point(self)
Returns the current point from the graphics context.
- Note:
- Currently the current_point is only affected by move_to, line_to, and lines. It should also be affected by text operations. I'm not sure how rect and rects and friends should affect it -- will find out on Mac.
- get_text_extent(self, textstring)
returns the width and height of the rendered text
- get_text_matrix(self)
- get_text_position(self)
- height(self)
- is_path_empty(self)
Tests to see whether the current drawing path is empty
What does 'empty' mean???
- line_set(self, starts, ends)
Adds a set of disjoint lines as a new subpath.
Parameters
- starts
- an Nx2 array of x,y pairs
- ends
- an Nx2 array of x,y pairs
Starts and ends should have the same length. The current point is moved to the last point in 'ends'.
N.B. Cairo cannot make disjointed lines as a single subpath, thus each line forms it's own subpath
- line_to(self, x, y)
Adds a line from the current point to the given point (x,y).
The current point is moved to (x,y).
What should happen if move_to hasn't been called? Should it always begin at 0,0 or raise an error?
- Notes:
- See note in move_to about the current_point.
- linear_gradient(self, x1, y1, x2, y2, stops, spreadMethod = 'pad', transforms = None, units = 'userSpaceOnUse')
- lines(self, points)
Adds a series of lines as a new subpath.
Parameters
- points
- an Nx2 array of x,y pairs
The current_point is moved to the last point in 'points'
- move_to(self, x, y)
Starts a new drawing subpath and place the current point at (x,y).
- Notes:
- Not sure how to treat state.current_point. Should it be the value of the point before or after the matrix transformation? It looks like before in the PDF specs.
- radial_gradient(self, cx, cy, r, stops, fx = None, fy = None, spreadMethod = 'pad', transforms = None, units = 'userSpaceOnUse')
- rect(self, x, y, sx, sy)
Adds a rectangle as a new subpath.
- render_component(self, component, container_coords = False)
Renders the given component.
Parameters
- component : Component
- The component to be rendered.
- container_coords : Boolean
- Whether to use coordinates of the component's container
Description
If container_coords is False, then the (0,0) coordinate of this graphics context corresponds to the lower-left corner of the component's outer_bounds. If container_coords is True, then the method draws the component as it appears inside its container, i.e., it treats (0,0) of the graphics context as the lower-left corner of the container's outer bounds.
- restore_state(self)
Restores the previous graphics state.
- rotate_ctm(self, angle)
Rotates the coordinate space for drawing by the given angle.
Parameters
- angle : float
- the angle, in radians, to rotate the coordinate system
- save_state(self)
Saves the current graphic's context state.
Always pair this with a restore_state().
- scale_ctm(self, sx, sy)
Sets the coordinate system scale to the given values, (sx,sy).
Parameters
- sx : float
- The new scale factor for the x axis
- sy : float
- The new scale factor for the y axis
- select_font(self, face_name, size = 12, style = 'regular', encoding = None)
Selects a new font for drawing text.
Parameters
- face_name
- The name of a font. E.g.: "Times New Roman" !! Need to specify a way to check for all the types size The font size in points.
- style
- One of "regular", "bold", "italic", "bold italic"
- encoding
A 4 letter encoding name. Common ones are:
- "unic" -- unicode
- "armn" -- apple roman
- "symb" -- symbol
Not all fonts support all encodings. If none is specified, fonts that have unicode encodings default to unicode. Symbol is the second choice. If neither are available, the encoding defaults to the first one returned in the FreeType charmap list for the font face.
- set_alpha(self, alpha)
- set_antialias(self, value)
Sets/Unsets anti-aliasing for bitmap graphics context.
Ignored on most platforms.
- set_character_spacing(self, spacing)
Sets the amount of additional spacing between text characters.
Parameters
- spacing : float
- units of space extra space to add between text coordinates. It is specified in text coordinate system.
Notes
- I'm assuming this is horizontal spacing?
- Not implemented in wxPython, or cairo (for the time being)
- set_fill_color(self, color)
set_fill_color takes a sequences of rgb or rgba values between 0.0 and 1.0
- set_flatness(self, flatness)
Not implemented
It is device dependent and therefore not recommended by the PDF documentation.
flatness determines how accurately lines are rendered. Setting it to values less than one will result in more accurate drawings, but they take longer. It defaults to None
- set_font(self, font)
Set the font for the current graphics context.
A device-specific font object. In this case, a cairo FontFace object. It's not clear how this can be used right now.
- set_font_size(self, size)
Sets the size of the font.
The size is specified in user space coordinates.
- set_line_cap(self, style)
Specifies the style of endings to put on line ends.
Parameters
- style : cap_style
- The line cap style to use. Available styles are CAP_ROUND, CAP_BUTT, CAP_SQUARE.
- set_line_dash(self, pattern, phase = 0)
Sets the line dash pattern and phase for line painting.
Parameters
- pattern : float array
- An array of floating point values specifing the lengths of on/off painting pattern for lines.
- phase : float
- Specifies how many units into dash pattern to start. phase defaults to 0.
- set_line_join(self, style)
Sets the style for joining lines in a drawing.
Parameters
- style : join_style
- The line joining style. The available styles are JOIN_ROUND, JOIN_BEVEL, JOIN_MITER.
- set_line_width(self, width)
Sets the line width for drawing
Parameters
- width : float
- The new width for lines in user space units.
- set_miter_limit(self, limit)
Specifies limits on line lengths for mitering line joins.
If line_join is set to miter joins, the limit specifies which line joins should actually be mitered. If lines are not mitered, they are joined with a bevel. The line width is divided by the length of the miter. If the result is greater than the limit, the bevel style is used.
This is not implemented on most platforms.
Parameters
- limit : float
- limit for mitering joins. defaults to 1.0. (XXX is this the correct default?)
- set_stroke_color(self, color)
set_stroke_color takes a sequences of rgb or rgba values between 0.0 and 1.0
- set_text_drawing_mode(self, mode)
Specifies whether text is drawn filled or outlined or both.
Parameters
- mode
determines how text is drawn to the screen. If a CLIP flag is set, the font outline is added to the clipping path. Possible values:
- TEXT_FILL
- fill the text
- TEXT_STROKE
- paint the outline
- TEXT_FILL_STROKE
- fill and outline
- TEXT_INVISIBLE
- paint it invisibly ??
- TEXT_FILL_CLIP
- fill and add outline clipping path
- TEXT_STROKE_CLIP
- outline and add outline to clipping path
- TEXT_FILL_STROKE_CLIP
- fill, outline, and add to clipping path
- TEXT_CLIP
- add text outline to clipping path
- Note:
- wxPython currently ignores all but the INVISIBLE flag.
- set_text_matrix(self, ttm)
- set_text_position(self, x, y)
- show_glyphs(self)
- show_glyphs_at_point(self)
- show_text(self, text)
Draws text on the device at the current text position. Leaves the current point unchanged.
- show_text_at_point(self, text, x, y)
- stroke_rect(self)
How does this affect the current path?
- stroke_rect_with_width(self)
- synchronize(self)
Prepares drawing data to be updated on a destination device.
Currently this is a NOP for all implementations.
- translate_ctm(self, tx, ty)
Translates the coordinate system by the value given by (tx,ty)
Parameters
- tx : float
- The distance to move in the x direction
- ty : float
- The distance to move in the y direction
- width(self)