pyemf3 icon indicating copy to clipboard operation
pyemf3 copied to clipboard

Pure Python Enhanced Metafile Library

pyemf3 is an updated version of pyemf with support for Python 3.3+

Original author: Rob McMullen Updater to Python 3: Jeremy Sanders

ABSTRACT

pyemf3 is a pure python module that provides bindings for an ECMA-234 compliant vector graphics library. ECMA-234 is the published interface for the Windows GDI used in the Microsoft windows environment and, more importantly, natively supported by the OpenOffice suite of tools.

http://www.ecma-international.org/publications/standards/Ecma-234.htm

PREREQUISITES

python3 (tested with python 3.10)

QUICK INSTALL

python3 setup.py install

FEATURES

Most of the drawing methods of ECMA-234 are supported by pyemf3.

Supported

Drawing parameters: GetStockObject, SelectObject, DeleteObject, CreatePen, CreateSolidBrush, CreateHatchBrush, SetBkColor, SetBkMode, SetPolyFillMode

Drawing primitives: SetPixel, Polyline, Polygon, Rectangle, RoundRect, Ellipse, Arc, Chord, Pie, PolyBezier

Path primitives: BeginPath, EndPath, MoveTo, LineTo, PolylineTo, ArcTo, PolyBezierTo, CloseFigure, FillPath, StrokePath, StrokeAndFillPath

Clipping: SelectClipPath

Text: CreateFont, SetTextAlign, SetTextColor, TextOut

Coordinate system transformation: SaveDC, RestoreDC, SetWorldTransform, ModifyWorldTransform

Experimental

Window/Viewport commands: SetMapMode, SetViewportOrgEx, GetViewportOrgEx, SetViewportExtEx, ScaleViewportExtEx, GetViewportExtEx, SetWindowOrgEx, GetWindowOrgEx, SetWindowExtEx, ScaleWindowExtEx, GetWindowExtEx

Unsupported

Palettes Bitmaps Text metrics

DOCUMENTATION

The most current documentation is always available on the web at $url/api/index.html

Or, in the source distribution, the directory website/api/ contains a copy of the api documentation for version $version. Simply point your web browser at the index.html within that directory.

EXAMPLES

Creating an EMF

Here's a simple program (available as test-1.py in the distribution) that connects opposite corners of an 8in by 6in rectangle with lines:

#!/usr/bin/env python3

import pyemf3

width=8 height=6 dpi=300

emf=pyemf3.EMF(width,height,dpi) thin=emf.CreatePen(pyemf.PS_SOLID,1,(0x01,0x02,0x03)) emf.SelectObject(thin) emf.Polyline([(0,0),(widthdpi,heightdpi)]) emf.Polyline([(0,heightdpi),(widthdpi,0)]) emf.save("test-1.emf")

Other tests

There are many other tests included in the examples/ directory in the source distribution. After installing the pyemf3 library, you should be able to run them like this:

$ cd examples $ python test-drawing1.py

and examine the output file 'test-drawing1.emf' by loading it in OpenOffice Impress.

Also included in the examples directory is the program 'test--run-all.py' that will run all the tests.