Windows Metafiles

a guide for non-windows programmers

Windows Metafiles (wmf) files are common in the windows world. Basically they are a recording of the windows gdi (graphic) calls. They consist of a list of calls to such graphic primitives as LineTo, Polygon, Rectangle, etc. And as such as inherently a vector based format.

There are three basic kinds,

O'Reilly's File Format handbook has a description of the headers of these files, and some other info on them

While this information is very useful, it lacks an explanation of each of the records that can exist in a metafile, for the development of libwmf it was required to understand each of the metafile records. To this end the wine source was a great aid. As was the basic help files of MS's Visual C compiler. In most cases just looking at the definition of an equivalent windows api call allows you to know what the parameters of each metafile record mean.

First you must know that the arguments to each api call are stored in reverse order in the actual disk dump that is a metafile record.
So in the case of a Rectangle call which from wine has the api

BOOL32 Rectangle
(
	HDC32 hdc,
	INT32 left,
	INT32 top,
	INT32 right,
	INT32 bottom
);

Now wine uses the win32 api, so in 16 bit wmf files left,top,right and bottom are all 16 bit values, not 32, and also they are stored in reverse order in the parameter list of wmf record, so the layout on disk for a RECTANGLE entry is

|32bit size of total record|0x041B |bottom|right|top|left|
Got that ?, so all the other records are the same.

There are complications when you start into the more complex operands such as BITBLT, and CREATEPATTERNBRUSH as they appear to get converted into DIBBITBLT and DIBCREATEPATTERNBRUSH when used in conjunction with a metafile

There are other complications in many of the other operands, my particular favorite is one I found in DIBBITBLT.

I've created a list of all the known operands that can be used in 16 bit metafiles, as listed in wine's wingdi.h (and windows of course). The list attempts to document all the calls in terms of the layout of the operands' parameters as dumped to file, some of them are definitely correct, and some have been pieced together by the wine developers, and one of two ive put together myself from mucking around with a hexeditor and wmf files that i've created under windows. So if you know them to be incorrect or have any information that you think would help, please do send that information to me

This information is primarily intended for developers to create alternative bindings to the libwmf library which is a wmf library for non-windows machines that I've written, it takes care of most of the housecleaning and handling of wmf files. All new bindings should have to implement is handlers for the calls as listed in the (as yes non-existant) libwmf developer's documentation.
For that reason this list also shows what operands are supported in the various existing bindings for libwmf, which currently are one for X, and one for gd which is a graphic library for creating gif files. So as it stands any X program can display wmf files using the included X binding to libwmf, and there exists a wmftogif program which can create gif's from wmf files without requiring windows. libwmf was developed to allow my other project mswordview, a msword converter to extract wmf files in a unix-friendly format. Bindings that are missing that would be useful are eps and fig, to name two.

Enough already, here is the the known world's most complete wmf documentation to date

The Windows Metafile (wmf) Operand Documentation by Caolán McNamara