Module pyemf :: Class EMF
[frames | no frames]

Class EMF


Reference page of the public API for enhanced metafile creation. See pyemf for an overview / mini tutorial.
Method Summary
    Creating Metafiles
  __init__(self, width, height, density, units, description, verbose)
Create an EMF structure in memory.
Boolean load(self, filename)
Read an existing EMF file.
Boolean save(self, filename)
Write the EMF to disk.
    Drawing Parameters
int GetStockObject(self, obj)
Retrieve the handle for a predefined graphics object.
int SelectObject(self, handle)
Make the given graphics object current.
int DeleteObject(self, handle)
Delete the given graphics object.
int CreatePen(self, style, width, color)
Create a pen, used to draw lines and path outlines.
int CreateSolidBrush(self, color)
Create a solid brush used to fill polygons.
int CreateHatchBrush(self, hatch, color)
Create a hatched brush used to fill polygons.
int SetBkColor(self, color)
Set the background color used for any transparent regions in fills or hatched brushes.
int SetBkMode(self, mode)
Set the background mode for interaction between transparent areas in the region to be drawn and the existing background.
int SetPolyFillMode(self, mode)
Set the polygon fill mode.
    Drawing Primitives
  SetPixel(self, x, y, color)
Set the pixel to the given color.
int Polyline(self, points)
Draw a sequence of connected lines.
int PolyPolyline(self, polylines)
Draw multiple polylines.
int Polygon(self, points)
Draw a closed figure bounded by straight line segments.
int PolyPolygon(self, polygons)
Draw multiple polygons.
int Rectangle(self, left, top, right, bottom)
Draw a rectangle using the current pen.
int RoundRect(self, left, top, right, bottom, cornerwidth, cornerheight)
Draw a rectangle with rounded corners using the current pen.
int Ellipse(self, left, top, right, bottom)
Draw an ellipse using the current pen.
int Arc(self, left, top, right, bottom, xstart, ystart, xend, yend)
Draw an arc of an ellipse.
int Chord(self, left, top, right, bottom, xstart, ystart, xend, yend)
Draw a chord of an ellipse.
int Pie(self, left, top, right, bottom, xstart, ystart, xend, yend)
Draw a pie slice of an ellipse.
int PolyBezier(self, points)
Draw cubic Bezier curves using the list of points as both endpoints and control points.
    Path Primatives
int BeginPath(self)
Begin defining a path.
int EndPath(self)
End the path definition.
int MoveTo(self, x, y)
Move the current point to the given position and implicitly begin a new figure or path.
int LineTo(self, x, y)
Draw a straight line using the current pen from the current point to the given position.
int PolylineTo(self, points)
Draw a sequence of connected lines starting from the current position and update the position to the final point in the list.
int ArcTo(self, left, top, right, bottom, xstart, ystart, xend, yend)
Draw an arc and update the current position.
int PolyBezierTo(self, points)
Draw cubic Bezier curves, as described in PolyBezier, but in addition draw a line from the previous position to the start of the curve.
int CloseFigure(self)
Close a currently open path, which connects the current position to the starting position of a figure.
int FillPath(self)
Close any currently open path and fills it using the currently selected brush and polygon fill mode.
int StrokePath(self)
Close any currently open path and outlines it using the currently selected pen.
int StrokeAndFillPath(self)
Close any currently open path, outlines it using the currently selected pen, and fills it using the current brush.
    Clipping
int SelectClipPath(self, mode)
Use the current path as the clipping path.
    Text
int CreateFont(self, height, width, escapement, orientation, weight, italic, underline, strike_out, charset, out_precision, clip_precision, quality, pitch_family, name)
Create a new font object.
int SetTextAlign(self, alignment)
Set the subsequent alignment of drawn text.
int SetTextColor(self, color)
Set the text foreground color.
int TextOut(self, x, y, text)
Draw a string of text at the given position using the current FONT and other text attributes.
    Coordinate System Transformation
int SaveDC(self)
Saves the current state of the graphics mode (such as line and fill styles, font, clipping path, drawing mode and any transformations) to a stack.
int RestoreDC(self, stackid)
Restores the state of the graphics mode to a stack.
boolean SetWorldTransform(self, m11, m12, m21, m22, dx, dy)
Set the world coordinate to logical coordinate linear transform for subsequent operations.
boolean ModifyWorldTransform(self, mode, m11, m12, m21, m22, dx, dy)
Change the current linear transform.
    **Experimental** -- Viewport Manipulation
int SetMapMode(self, mode)
Set the window mapping mode.
2-tuple (x,y) if successful, or None if unsuccessful SetViewportOrgEx(self, xv, yv)
Set the origin of the viewport, which translates the origin of the coordinate system by (xv,yv).
2-tuple (x,y) GetViewportOrgEx(self)
Get the origin of the viewport.
2-tuple (x,y) if successful, or None if unsuccessful SetWindowOrgEx(self, xw, yw)
Set the origin of the window, which translates the origin of the coordinate system by (-xw,-yw).
2-tuple (x,y) GetWindowOrgEx(self)
Get the origin of the window.
2-tuple (width,height) if successful, or None if unsuccessful SetViewportExtEx(self, x, y)
Set the dimensions of the viewport in device units.
2-tuple (width,height) if successful, or None if unsuccessful ScaleViewportExtEx(self, x_num, x_den, y_num, y_den)
Scale the dimensions of the viewport.
2-tuple (width,height) GetViewportExtEx(self)
Get the dimensions of the viewport in device units (i.e.
2-tuple (width,height) if successful, or None if unsuccessful SetWindowExtEx(self, x, y)
Set the dimensions of the window.
2-tuple (width,height) if successful, or None if unsuccessful ScaleWindowExtEx(self, x_num, x_den, y_num, y_den)
Scale the dimensions of the window.
2-tuple (width,height) GetWindowExtEx(self)
Get the dimensions of the window in logical units (integer numbers of pixels).

Method Details

__init__(self, width=6.0, height=4.0, density=300, units='in', description='pyemf.sf.net', verbose=False)
(Constructor)

Create an EMF structure in memory. The size of the resulting image is specified in either inches or millimeters depending on the value of units. Width and height are floating point values, but density must be an integer because this becomes the basis for the coordinate system in the image. Density is the number of individually addressible pixels per unit measurement (dots per inch or dots per millimeter, depending on the units system) in the image. A consequence of this is that each pixel is specified by a pair of integer coordinates.
Parameters:
width - width of EMF image in inches or millimeters
           (type=float)
height - height of EMF image in inches or millimeters
           (type=float)
density - dots (pixels) per unit measurement
           (type=int)
units - string indicating the unit measurement, one of:
  • 'in'
  • 'mm'

           (type=string)
description - optional string to specify a description of the image
           (type=string)

load(self, filename=None)

Read an existing EMF file. If any records exist in the current object, they will be overwritten by the records from this file.
Parameters:
filename - filename to load
           (type=string)
Returns:
True for success, False for failure.
           (type=Boolean)

save(self, filename=None)

Write the EMF to disk.
Parameters:
filename - filename to write
           (type=string)
Returns:
True for success, False for failure.
           (type=Boolean)

GetStockObject(self, obj)

Retrieve the handle for a predefined graphics object. Stock objects include (at least) the following:
  • WHITE_BRUSH
  • LTGRAY_BRUSH
  • GRAY_BRUSH
  • DKGRAY_BRUSH
  • BLACK_BRUSH
  • NULL_BRUSH
  • HOLLOW_BRUSH
  • WHITE_PEN
  • BLACK_PEN
  • NULL_PEN
  • OEM_FIXED_FONT
  • ANSI_FIXED_FONT
  • ANSI_VAR_FONT
  • SYSTEM_FONT
  • DEVICE_DEFAULT_FONT
  • DEFAULT_PALETTE
  • SYSTEM_FIXED_FONT
  • DEFAULT_GUI_FONT
Parameters:
obj - number of stock object.
           (type=int)
Returns:
handle of stock graphics object.
           (type=int)

SelectObject(self, handle)

Make the given graphics object current.
Parameters:
handle - handle of graphics object to make current.
           (type=int)
Returns:
the handle of the current graphics object which obj replaces.
           (type=int)

DeleteObject(self, handle)

Delete the given graphics object. Note that, now, only those contexts into which the object has been selected get a delete object records.
Parameters:
handle - handle of graphics object to delete.
           (type=int)
Returns:
true if the object was successfully deleted.
           (type=int)

CreatePen(self, style, width, color)

Create a pen, used to draw lines and path outlines.
Parameters:
style - the style of the new pen, one of:
  • PS_SOLID
  • PS_DASH
  • PS_DOT
  • PS_DASHDOT
  • PS_DASHDOTDOT
  • PS_NULL
  • PS_INSIDEFRAME
  • PS_USERSTYLE
  • PS_ALTERNATE

           (type=int)
width - the width of the new pen.
           (type=int)
color - (r,g,b) tuple or the packed integer color of the new pen.
           (type=int)
Returns:
handle to the new pen graphics object.
           (type=int)

CreateSolidBrush(self, color)

Create a solid brush used to fill polygons.
Parameters:
color - the color of the solid brush.
           (type=int)
Returns:
handle to brush graphics object.
           (type=int)

CreateHatchBrush(self, hatch, color)

Create a hatched brush used to fill polygons.

Note: Currently appears unsupported in OpenOffice.
Parameters:
hatch - integer representing type of fill:
  • HS_HORIZONTAL
  • HS_VERTICAL
  • HS_FDIAGONAL
  • HS_BDIAGONAL
  • HS_CROSS
  • HS_DIAGCROSS

           (type=int)
color - the color of the 'on' pixels of the brush.
           (type=int)
Returns:
handle to brush graphics object.
           (type=int)

SetBkColor(self, color)

Set the background color used for any transparent regions in fills or hatched brushes.

Note: Currently appears sporadically supported in OpenOffice.
Parameters:
color - background color.
           (type=int)
Returns:
previous background color.
           (type=int)

SetBkMode(self, mode)

Set the background mode for interaction between transparent areas in the region to be drawn and the existing background.

The choices for mode are:
  • TRANSPARENT
  • OPAQUE
Note: Currently appears sporadically supported in OpenOffice.
Parameters:
mode - background mode.
           (type=int)
Returns:
previous background mode.
           (type=int)

SetPolyFillMode(self, mode)

Set the polygon fill mode. Generally these modes produce different results only when the edges of the polygons overlap other edges.
Parameters:
mode - fill mode with the following options:
  • ALTERNATE - fills area between odd and even numbered sides
  • WINDING - fills all area as long as a point is between any two sides

           (type=int)
Returns:
previous fill mode.
           (type=int)

SetPixel(self, x, y, color)

Set the pixel to the given color.
Parameters:
x - the horizontal position.
           (type=int)
y - the vertical position.
           (type=int)
color - the color to set the pixel.
           (type=int or (r,g,b) tuple)

Polyline(self, points)

Draw a sequence of connected lines.
Parameters:
points - list of x,y tuples
           (type=tuple)
Returns:
true if polyline is successfully rendered.
           (type=int)

PolyPolyline(self, polylines)

Draw multiple polylines. The polylines argument is a list of lists, where each inner list represents a single polyline. Each polyline is described by a list of x,y tuples as in Polyline. For example:
 lines=[[(100,100),(200,100)],
        [(300,100),(400,100)]]
 emf.PolyPolyline(lines)
draws two lines, one from 100,100 to 200,100, and another from 300,100 to 400,100.
Parameters:
polylines - list of lines, where each line is a list of x,y tuples
           (type=list)
Returns:
true if polypolyline is successfully rendered.
           (type=int)

Polygon(self, points)

Draw a closed figure bounded by straight line segments. A polygon is defined by a list of points that define the endpoints for a series of connected straight line segments. The end of the last line segment is automatically connected to the beginning of the first line segment, the border is drawn with the current pen, and the interior is filled with the current brush. See SetPolyFillMode for the fill effects when an overlapping polygon is defined.
Parameters:
points - list of x,y tuples
           (type=tuple)
Returns:
true if polygon is successfully rendered.
           (type=int)

PolyPolygon(self, polygons)

Draw multiple polygons. The polygons argument is a list of lists, where each inner list represents a single polygon. Each polygon is described by a list of x,y tuples as in Polygon. For example:
 lines=[[(100,100),(200,100),(200,200),(100,200)],
        [(300,100),(400,100),(400,200),(300,200)]]
 emf.PolyPolygon(lines)

draws two squares.

Note: Currently partially supported in OpenOffice. The line width is ignored and the polygon border is not closed (the final point is not connected to the starting point in each polygon).
Parameters:
polygons - list of polygons, where each polygon is a list of x,y tuples
           (type=list)
Returns:
true if polypolygon is successfully rendered.
           (type=int)

Rectangle(self, left, top, right, bottom)

Draw a rectangle using the current pen.
Parameters:
left - x position of left side of ellipse bounding box.
           (type=int)
top - y position of top side of ellipse bounding box.
           (type=int)
right - x position of right edge of ellipse bounding box.
           (type=int)
bottom - y position of bottom edge of ellipse bounding box.
           (type=int)
Returns:
true if rectangle was successfully rendered.
           (type=int)

RoundRect(self, left, top, right, bottom, cornerwidth, cornerheight)

Draw a rectangle with rounded corners using the current pen.
Parameters:
left - x position of left side of ellipse bounding box.
           (type=int)
top - y position of top side of ellipse bounding box.
           (type=int)
right - x position of right edge of ellipse bounding box.
           (type=int)
bottom - y position of bottom edge of ellipse bounding box.
           (type=int)
cornerwidth - width of the ellipse that defines the roundness of the corner.
           (type=int)
cornerheight - height of ellipse
           (type=int)
Returns:
true if rectangle was successfully rendered.
           (type=int)

Ellipse(self, left, top, right, bottom)

Draw an ellipse using the current pen.
Parameters:
left - x position of left side of ellipse bounding box.
           (type=int)
top - y position of top side of ellipse bounding box.
           (type=int)
right - x position of right edge of ellipse bounding box.
           (type=int)
bottom - y position of bottom edge of ellipse bounding box.
           (type=int)
Returns:
true if rectangle was successfully rendered.
           (type=int)

Arc(self, left, top, right, bottom, xstart, ystart, xend, yend)

Draw an arc of an ellipse. The ellipse is specified by its bounding rectange and two lines from its center to indicate the start and end angles. left, top, right, bottom describe the bounding rectangle of the ellipse. The start point given by xstart,ystert defines a ray from the center of the ellipse through the point and out to infinity. The point at which this ray intersects the ellipse is the starting point of the arc. Similarly, the infinite radial ray from the center through the end point defines the end point of the ellipse. The arc is drawn in a counterclockwise direction, and if the start and end rays are coincident, a complete ellipse is drawn.
Parameters:
left - x position of left edge of arc box.
           (type=int)
top - y position of top edge of arc box.
           (type=int)
right - x position of right edge of arc box.
           (type=int)
bottom - y position bottom edge of arc box.
           (type=int)
xstart - x position of arc start.
           (type=int)
ystart - y position of arc start.
           (type=int)
xend - x position of arc end.
           (type=int)
yend - y position of arc end.
           (type=int)
Returns:
true if arc was successfully rendered.
           (type=int)

Chord(self, left, top, right, bottom, xstart, ystart, xend, yend)

Draw a chord of an ellipse. A chord is a closed region bounded by an arc and the [straight] line between the two points that define the arc start and end. The arc start and end points are defined as in Arc.
Parameters:
left - x position of left edge of arc box.
           (type=int)
top - y position of top edge of arc box.
           (type=int)
right - x position of right edge of arc box.
           (type=int)
bottom - y position bottom edge of arc box.
           (type=int)
xstart - x position of arc start.
           (type=int)
ystart - y position of arc start.
           (type=int)
xend - x position of arc end.
           (type=int)
yend - y position of arc end.
           (type=int)
Returns:
true if arc was successfully rendered.
           (type=int)

Pie(self, left, top, right, bottom, xstart, ystart, xend, yend)

Draw a pie slice of an ellipse. The ellipse is specified as in Arc, and it is filled with the current brush.
Parameters:
left - x position of left edge of arc box.
           (type=int)
top - y position of top edge of arc box.
           (type=int)
right - x position of right edge of arc box.
           (type=int)
bottom - y position bottom edge of arc box.
           (type=int)
xstart - x position of arc start.
           (type=int)
ystart - y position of arc start.
           (type=int)
xend - x position of arc end.
           (type=int)
yend - y position of arc end.
           (type=int)
Returns:
true if arc was successfully rendered.
           (type=int)

PolyBezier(self, points)

Draw cubic Bezier curves using the list of points as both endpoints and control points. The first point is used as the starting point, the second and thrird points are control points, and the fourth point is the end point of the first curve. Subsequent curves need three points each: two control points and an end point, as the ending point of the previous curve is used as the starting point for the next curve.
Parameters:
points - list of x,y tuples that are either end points or control points
           (type=tuple)
Returns:
true if bezier curve was successfully rendered.
           (type=int)

BeginPath(self)

Begin defining a path. Any previous unclosed paths are discarded.
Returns:
true if successful.
           (type=int)

EndPath(self)

End the path definition.
Returns:
true if successful.
           (type=int)

MoveTo(self, x, y)

Move the current point to the given position and implicitly begin a new figure or path.
Parameters:
x - new x position.
           (type=int)
y - new y position.
           (type=int)
Returns:
true if position successfully changed (can this fail?)
           (type=int)

LineTo(self, x, y)

Draw a straight line using the current pen from the current point to the given position.
Parameters:
x - x position of line end.
           (type=int)
y - y position of line end.
           (type=int)
Returns:
true if line is drawn (can this fail?)
           (type=int)

PolylineTo(self, points)

Draw a sequence of connected lines starting from the current position and update the position to the final point in the list.
Parameters:
points - list of x,y tuples
           (type=tuple)
Returns:
true if polyline is successfully rendered.
           (type=int)

ArcTo(self, left, top, right, bottom, xstart, ystart, xend, yend)

Draw an arc and update the current position. The arc is drawn as described in Arc, but in addition the start of the arc will be connected to the previous position and the current position is updated to the end of the arc so subsequent path operations such as LineTo, PolylineTo, etc. will connect to the end.

Note: Currently appears unsupported in OpenOffice.
Parameters:
left - x position of left edge of arc box.
           (type=int)
top - y position of top edge of arc box.
           (type=int)
right - x position of right edge of arc box.
           (type=int)
bottom - y position bottom edge of arc box.
           (type=int)
xstart - x position of arc start.
           (type=int)
ystart - y position of arc start.
           (type=int)
xend - x position of arc end.
           (type=int)
yend - y position of arc end.
           (type=int)
Returns:
true if arc was successfully rendered.
           (type=int)

PolyBezierTo(self, points)

Draw cubic Bezier curves, as described in PolyBezier, but in addition draw a line from the previous position to the start of the curve. If the arc is successfully rendered, the current position is updated so that subsequent path operations such as LineTo, PolylineTo, etc. will follow from the end of the curve.
Parameters:
points - list of x,y tuples that are either end points or control points
           (type=tuple)
Returns:
true if bezier curve was successfully rendered.
           (type=int)

CloseFigure(self)

Close a currently open path, which connects the current position to the starting position of a figure. Usually the starting position is the most recent call to MoveTo after BeginPath.
Returns:
true if successful
           (type=int)

FillPath(self)

Close any currently open path and fills it using the currently selected brush and polygon fill mode.
Returns:
true if successful.
           (type=int)

StrokePath(self)

Close any currently open path and outlines it using the currently selected pen.
Returns:
true if successful.
           (type=int)

StrokeAndFillPath(self)

Close any currently open path, outlines it using the currently selected pen, and fills it using the current brush. Same as stroking and filling using both the FillPath and StrokePath options, except that the pixels that would be in the overlap region to be both stroked and filled are optimized to be only stroked.

Note: Supported in OpenOffice 2.*, unsupported in OpenOffice 1.*.
Returns:
true if successful.
           (type=int)

SelectClipPath(self, mode=5)

Use the current path as the clipping path. The current path must be a closed path (i.e. with CloseFigure and EndPath)

Note: Currently unsupported in OpenOffice -- it apparently uses the bounding rectangle of the path as the clip area, not the path itself.
Parameters:
mode - one of the following values that specifies how to modify the clipping path
  • RGN_AND: the new clipping path becomes the intersection of the old path and the current path
  • RGN_OR: the new clipping path becomes the union of the old path and the current path
  • RGN_XOR: the new clipping path becomes the union of the old path and the current path minus the intersection of the old and current path
  • RGN_DIFF: the new clipping path becomes the old path where any overlapping region of the current path is removed
  • RGN_COPY: the new clipping path is set to the current path and the old path is thrown away
Returns:
true if successful.
           (type=int)

CreateFont(self, height, width=0, escapement=0, orientation=0, weight=400, italic=0, underline=0, strike_out=0, charset=0, out_precision=0, clip_precision=0, quality=0, pitch_family='DEFAULT_PITCH|FF_DONTCARE', name='Times New Roman')

Create a new font object. Presumably, when rendering the EMF the system tries to find a reasonable approximation to all the requested attributes.
Parameters:
height - specified one of two ways:
  • if height>0: locate the font using the specified height as the typical cell height
  • if height<0: use the absolute value of the height as the typical glyph height.

           (type=int)
width - typical glyph width. If zero, the typical aspect ratio of the font is used.
           (type=int)
escapement - angle, in degrees*10, of rendered string rotation. Note that escapement and orientation must be the same.
           (type=int)
orientation - angle, in degrees*10, of rendered string rotation. Note that escapement and orientation must be the same.
           (type=int)
weight - weight has (at least) the following values:
  • FW_DONTCARE
  • FW_THIN
  • FW_EXTRALIGHT
  • FW_ULTRALIGHT
  • FW_LIGHT
  • FW_NORMAL
  • FW_REGULAR
  • FW_MEDIUM
  • FW_SEMIBOLD
  • FW_DEMIBOLD
  • FW_BOLD
  • FW_EXTRABOLD
  • FW_ULTRABOLD
  • FW_HEAVY
  • FW_BLACK

           (type=int)
italic - non-zero means try to find an italic version of the face.
           (type=int)
underline - non-zero means to underline the glyphs.
           (type=int)
strike_out - non-zero means to strike-out the glyphs.
           (type=int)
charset - select the character set from the following list:
  • ANSI_CHARSET
  • DEFAULT_CHARSET
  • SYMBOL_CHARSET
  • SHIFTJIS_CHARSET
  • HANGEUL_CHARSET
  • HANGUL_CHARSET
  • GB2312_CHARSET
  • CHINESEBIG5_CHARSET
  • GREEK_CHARSET
  • TURKISH_CHARSET
  • HEBREW_CHARSET
  • ARABIC_CHARSET
  • BALTIC_CHARSET
  • RUSSIAN_CHARSET
  • EE_CHARSET
  • EASTEUROPE_CHARSET
  • THAI_CHARSET
  • JOHAB_CHARSET
  • MAC_CHARSET
  • OEM_CHARSET

           (type=int)
out_precision - the precision of the face may have on of the following values:
  • OUT_DEFAULT_PRECIS
  • OUT_STRING_PRECIS
  • OUT_CHARACTER_PRECIS
  • OUT_STROKE_PRECIS
  • OUT_TT_PRECIS
  • OUT_DEVICE_PRECIS
  • OUT_RASTER_PRECIS
  • OUT_TT_ONLY_PRECIS
  • OUT_OUTLINE_PRECIS

           (type=int)
clip_precision - the precision of glyph clipping may have one of the following values:
  • CLIP_DEFAULT_PRECIS
  • CLIP_CHARACTER_PRECIS
  • CLIP_STROKE_PRECIS
  • CLIP_MASK
  • CLIP_LH_ANGLES
  • CLIP_TT_ALWAYS
  • CLIP_EMBEDDED

           (type=int)
quality - (subjective) quality of the font. Choose from the following values:
  • DEFAULT_QUALITY
  • DRAFT_QUALITY
  • PROOF_QUALITY
  • NONANTIALIASED_QUALITY
  • ANTIALIASED_QUALITY

           (type=int)
pitch_family - the pitch and family of the font face if the named font can't be found. Combine the pitch and style using a binary or.
  • Pitch:
    • DEFAULT_PITCH
    • FIXED_PITCH
    • VARIABLE_PITCH
    • MONO_FONT
  • Style:
    • FF_DONTCARE
    • FF_ROMAN
    • FF_SWISS
    • FF_MODERN
    • FF_SCRIPT
    • FF_DECORATIVE

           (type=int)
name - ASCII string containing the name of the font face.
           (type=string)
Returns:
handle of font.
           (type=int)

SetTextAlign(self, alignment)

Set the subsequent alignment of drawn text. You can also pass a flag indicating whether or not to update the current point to the end of the text. Alignment may have the (sum of) values:
  • TA_NOUPDATECP
  • TA_UPDATECP
  • TA_LEFT
  • TA_RIGHT
  • TA_CENTER
  • TA_TOP
  • TA_BOTTOM
  • TA_BASELINE
  • TA_RTLREADING
Parameters:
alignment - new text alignment.
           (type=int)
Returns:
previous text alignment value.
           (type=int)

SetTextColor(self, color)

Set the text foreground color.
Parameters:
color - text foreground color.
           (type=int)
Returns:
previous text foreground color.
           (type=int)

TextOut(self, x, y, text)

Draw a string of text at the given position using the current FONT and other text attributes.
Parameters:
x - x position of text.
           (type=int)
y - y position of text.
           (type=int)
text - ASCII text string to render.
           (type=string)
Returns:
true of string successfully drawn.
           (type=int)

SaveDC(self)

Saves the current state of the graphics mode (such as line and fill styles, font, clipping path, drawing mode and any transformations) to a stack. This state can be restored by RestoreDC.

Note: Currently unsupported in OpenOffice -- it apparently uses the bounding rectangle of the path as the clip area, not the path itself.
Returns:
value of the saved state.
           (type=int)

RestoreDC(self, stackid)

Restores the state of the graphics mode to a stack. The stackid parameter is either a value returned by SaveDC, or if negative, is the number of states relative to the top of the save stack. For example, stackid == -1 is the most recently saved state.

Note: If the retrieved state is not at the top of the stack, any saved states above it are thrown away.

Note: Currently unsupported in OpenOffice -- it apparently uses the bounding rectangle of the path as the clip area, not the path itself.
Parameters:
stackid - stack id number from SaveDC or negative number for relative stack location
           (type=int)
Returns:
nonzero for success
           (type=int)

SetWorldTransform(self, m11=1.0, m12=0.0, m21=0.0, m22=1.0, dx=0.0, dy=0.0)

Set the world coordinate to logical coordinate linear transform for subsequent operations. With this matrix operation, you can translate, rotate, scale, shear, or a combination of all four. The matrix operation is defined as follows where (x,y) are the original coordinates and (x',y') are the transformed coordinates:
| x |   | m11 m12 0 |   | x' |
| y | * | m21 m22 0 | = | y' |
| 0 |   | dx  dy  1 |   | 0  |
or, the same thing defined as a system of linear equations:
x' = x*m11 + y*m21 + dx
y' = x*m12 + y*m22 + dy

http://msdn.microsoft.com/library/en-us/gdi/cordspac_0inn.asp says that the offsets are in device coordinates, not pixel coordinates.

Note: Currently partially supported in OpenOffice.
Parameters:
m11 - matrix entry
           (type=float)
m12 - matrix entry
           (type=float)
m21 - matrix entry
           (type=float)
m22 - matrix entry
           (type=float)
dx - x shift
           (type=float)
dy - y shift
           (type=float)
Returns:
status
           (type=boolean)

ModifyWorldTransform(self, mode, m11=1.0, m12=0.0, m21=0.0, m22=1.0, dx=0.0, dy=0.0)

Change the current linear transform. See SetWorldTransform for a description of the matrix parameters. The new transform may be modified in one of three ways, set by the mode parameter:
  • MWT_IDENTITY: reset the transform to the identity matrix (the matrix parameters are ignored).
  • MWT_LEFTMULTIPLY: multiply the matrix represented by these parameters by the current world transform to get the new transform.
  • MWT_RIGHTMULTIPLY: multiply the current world tranform by the matrix represented here to get the new transform.

The reason that there are two different multiplication types is that matrix multiplication is not commutative, which means the order of multiplication makes a difference.

Note: The parameter order was changed from GDI standard so that I could make the matrix parameters optional in the case of MWT_IDENTITY.

Note: Currently appears unsupported in OpenOffice.
Parameters:
mode - MWT_IDENTITY, MWT_LEFTMULTIPLY, or MWT_RIGHTMULTIPLY
           (type=int)
m11 - matrix entry
           (type=float)
m12 - matrix entry
           (type=float)
m21 - matrix entry
           (type=float)
m22 - matrix entry
           (type=float)
dx - x shift
           (type=float)
dy - y shift
           (type=float)
Returns:
status
           (type=boolean)

SetMapMode(self, mode)

Set the window mapping mode. This is the mapping between pixels in page space to pixels in device space. Page space is the coordinate system that is used for all the drawing commands -- it is how pixels are identified and figures are placed in the metafile. They are integer units.

Device space is the coordinate system of the final output, measured in physical dimensions such as mm, inches, or twips. It is this coordinate system that provides the scaling that makes metafiles into a scalable graphics format.
  • MM_TEXT: each unit in page space is mapped to one pixel
  • MM_LOMETRIC: 1 page unit = .1 mm in device space
  • MM_HIMETRIC: 1 page unit = .01 mm in device space
  • MM_LOENGLISH: 1 page unit = .01 inch in device space
  • MM_HIENGLISH: 1 page unit = .001 inch in device space
  • MM_TWIPS: 1 page unit = 1/20 point (or 1/1440 inch)
  • MM_ISOTROPIC: 1 page unit = user defined ratio, but axes equally scaled
  • MM_ANISOTROPIC: 1 page unit = user defined ratio, axes may be independently scaled
Parameters:
mode - window mapping mode.
           (type=int)
Returns:
previous window mapping mode, or zero if error.
           (type=int)

SetViewportOrgEx(self, xv, yv)

Set the origin of the viewport, which translates the origin of the coordinate system by (xv,yv). A pixel drawn at (x,y) in the new coordinate system will be displayed at (x+xv,y+yv) in terms of the previous coordinate system.

Contrast this with SetWindowOrgEx, which seems to be the opposite translation. So, if in addition, the window origin is set to (xw,yw) using SetWindowOrgEx, a pixel drawn at (x,y) will be displayed at (x-xw+xv,y-yw+yv) in terms of the original coordinate system.
Parameters:
xv - new x position of the viewport origin.
           (type=int)
yv - new y position of the viewport origin.
           (type=int)
Returns:
previous viewport origin
           (type=2-tuple (x,y) if successful, or None if unsuccessful)

GetViewportOrgEx(self)

Get the origin of the viewport.
Returns:
returns the current viewport origin.
           (type=2-tuple (x,y))

SetWindowOrgEx(self, xw, yw)

Set the origin of the window, which translates the origin of the coordinate system by (-xw,-yw). A pixel drawn at (x,y) in the new coordinate system will be displayed at (x-xw,y-yw) in terms of the previous coordinate system.

Contrast this with SetViewportOrgEx, which seems to be the opposite translation. So, if in addition, the viewport origin is set to (xv,yv) using SetViewportOrgEx, a pixel drawn at (x,y) will be displayed at (x-xw+xv,y-yw+yv) in terms of the original coordinate system.
Parameters:
xw - new x position of the window origin.
           (type=int)
yw - new y position of the window origin.
           (type=int)
Returns:
previous window origin
           (type=2-tuple (x,y) if successful, or None if unsuccessful)

GetWindowOrgEx(self)

Get the origin of the window.
Returns:
returns the current window origin.
           (type=2-tuple (x,y))

SetViewportExtEx(self, x, y)

Set the dimensions of the viewport in device units. Device units are physical dimensions, in millimeters. The total extent is equal to the width is millimeters multiplied by the density of pixels per millimeter in that dimension.

Note: this is only usable when SetMapMode has been set to MM_ISOTROPIC or MM_ANISOTROPIC.
Parameters:
x - new width of the viewport.
           (type=int)
y - new height of the viewport.
           (type=int)
Returns:
returns the previous size of the viewport.
           (type=2-tuple (width,height) if successful, or None if unsuccessful)

ScaleViewportExtEx(self, x_num, x_den, y_num, y_den)

Scale the dimensions of the viewport.
Parameters:
x_num - numerator of x scale
           (type=int)
x_den - denominator of x scale
           (type=int)
y_num - numerator of y scale
           (type=int)
y_den - denominator of y scale
           (type=int)
Returns:
returns the previous size of the viewport.
           (type=2-tuple (width,height) if successful, or None if unsuccessful)

GetViewportExtEx(self)

Get the dimensions of the viewport in device units (i.e. physical dimensions).
Returns:
returns the size of the viewport.
           (type=2-tuple (width,height))

SetWindowExtEx(self, x, y)

Set the dimensions of the window. Window size is measured in integer numbers of pixels (logical units).

Note: this is only usable when SetMapMode has been set to MM_ISOTROPIC or MM_ANISOTROPIC.
Parameters:
x - new width of the window.
           (type=int)
y - new height of the window.
           (type=int)
Returns:
returns the previous size of the window.
           (type=2-tuple (width,height) if successful, or None if unsuccessful)

ScaleWindowExtEx(self, x_num, x_den, y_num, y_den)

Scale the dimensions of the window.
Parameters:
x_num - numerator of x scale
           (type=int)
x_den - denominator of x scale
           (type=int)
y_num - numerator of y scale
           (type=int)
y_den - denominator of y scale
           (type=int)
Returns:
returns the previous size of the window.
           (type=2-tuple (width,height) if successful, or None if unsuccessful)

GetWindowExtEx(self)

Get the dimensions of the window in logical units (integer numbers of pixels).
Returns:
returns the size of the window.
           (type=2-tuple (width,height))

Generated by Epydoc 2.1 on Sun Jan 1 09:25:22 2006 http://epydoc.sf.net