A WMF file starts with one or two headers. Many files, such as clip art, begin with a 22-byte placeable header. The 18-byte metafile header comes next, or first in a file that has no placeable header. Records follow. All numbers in a WMF file are little-endian.
00000000 D7 CD C6 9A 00 00 00 00 00 00 40 01 F0 00 A0 05
00000010 00 00 00 00 01 53 01 00 09 00 00 03 7C 00 00 00
Placeable header (META_PLACEABLE)
Aldus added this header so that a program can place the picture on a page at a known size. It is not a real record: it has no size or function fields, and a Windows program that plays metafiles directly must skip it. When present it comes immediately before the metafile header.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | Key | Always 0x9AC6CDD7 (bytes D7 CD C6 9A). |
| 4 | 2 | u16 | HWmf | Handle of the metafile in memory. 0x0000 on disk. |
| 6 | 2 | s16 | Left | Bounding box left, in logical units. |
| 8 | 2 | s16 | Top | Bounding box top. |
| 10 | 2 | s16 | Right | Bounding box right. |
| 12 | 2 | s16 | Bottom | Bounding box bottom. |
| 14 | 2 | u16 | Inch | Logical units per inch. By convention a picture is recorded at 1440 (twips); 720 draws it at twice its normal size and 2880 at half. |
| 16 | 4 | u32 | Reserved | Unused, 0x00000000. |
| 20 | 2 | u16 | Checksum | Exclusive OR of the ten 16-bit words before it, starting from zero. |
Picture size in inches is (Right − Left) / Inch by
(Bottom − Top) / Inch.
Metafile header (META_HEADER)
The first record of every metafile. It is the one record with no record size or function number of its own, and it describes the file as a whole. Sizes are counted in 16-bit words, not bytes.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 2 | u16 | Type | Where the metafile lives. See MetafileType below. |
| 2 | 2 | u16 | HeaderSize | Size of this header in 16-bit words, normally 9. |
| 4 | 2 | u16 | Version | See MetafileVersion below. |
| 6 | 2 | u16 | SizeLow | Low word of the total size of the metafile in 16-bit words. |
| 8 | 2 | u16 | SizeHigh | High word of the same size. |
| 10 | 2 | u16 | NumberOfObjects | How many graphics objects (pens, brushes, fonts, palettes, regions) the metafile defines. This fixes the size of the object table. |
| 12 | 4 | u32 | MaxRecord | Size of the largest record, in 16-bit words. |
| 16 | 2 | u16 | NumberOfMembers | Not used, 0x0000. |
MetafileType
| Value | Name | Meaning |
|---|---|---|
0x0001 | MEMORYMETAFILE | The metafile is held in memory. |
0x0002 | DISKMETAFILE | The metafile is stored on disk. |
MetafileVersion
| Value | Name | Meaning |
|---|---|---|
0x0100 | METAVERSION100 | Metafile without device-independent bitmaps. |
0x0300 | METAVERSION300 | Metafile with device-independent bitmaps. Nearly every file met in practice. |
Telling the two starts apart
Read the first four bytes. If they are D7 CD C6 9A the file is placeable
and the metafile header starts at offset 22; otherwise it starts at 0. A file that
starts at 0 usually has 01 00 09 00 or 02 00 09 00 there.
The picture’s logical size in a non-placeable file has to be worked out from the first
META_SETWINDOWEXT record, because the metafile header holds no bounds.