Every EMF file begins with an EMR_HEADER record, type 1. It gives the
picture’s bounds and physical size, the file’s total size and record count, and the
reference device it was made for. All numbers are little-endian.
Header fields
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | Type | 0x00000001, EMR_HEADER. |
| 4 | 4 | u32 | Size | Size of this record in bytes, a multiple of 4. |
| 8 | 16 | RectL | Bounds | Smallest rectangle around the image, inclusive, in logical units. |
| 24 | 16 | RectL | Frame | Rectangle around the image, inclusive, in 0.01 mm. |
| 40 | 4 | u32 | RecordSignature | 0x464D4520, the bytes 20 45 4D 46, “ EMF”. The space is significant. |
| 44 | 4 | u32 | Version | EMF version, typically 0x00010000. |
| 48 | 4 | u32 | Bytes | Size of the whole metafile in bytes. |
| 52 | 4 | u32 | Records | Number of records in the metafile. |
| 56 | 2 | u16 | Handles | Number of graphics objects used. |
| 58 | 2 | u16 | Reserved | Must be 0, ignored. |
| 60 | 4 | u32 | nDescription | Characters in the description, or 0. |
| 64 | 4 | u32 | offDescription | Offset of the description from the start of this record. |
| 68 | 4 | u32 | nPalEntries | Entries in the metafile palette, which is stored in the EMR_EOF record. |
| 72 | 8 | SizeL | Device | Reference device size in pixels. |
| 80 | 8 | SizeL | Millimeters | Reference device size in millimetres. |
Header extensions
Fixed fields may be followed by extensions, then the variable data. The extensions are not flagged: the first one exists only if the fixed part reaches 100 bytes, the second only if it reaches 108.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 88 | 4 | u32 | cbPixelFormat | Size of the PixelFormatDescriptor, or 0. |
| 92 | 4 | u32 | offPixelFormat | Offset of that descriptor, or 0. |
| 96 | 4 | u32 | bOpenGL | 1 if OpenGL records are present, otherwise 0. |
| 100 | 4 | u32 | MicrometersX | Width of the reference device in micrometres. |
| 104 | 4 | u32 | MicrometersY | Height of the reference device in micrometres. |
Bytes 88 to 99 are HeaderExtension1 and 100 to 107 are
HeaderExtension2. MS-EMF says to create new files with both.
Which header is it
MS-EMF defines a header size that a reader works out from the record’s size and the offsets of the description and pixel format. If it is at least 108, the header has both extensions; if at least 100, only the first; otherwise neither.
Structures used
| Name | Size | Layout |
|---|---|---|
RectL | 16 | Left, top, right, bottom: four s32. |
SizeL | 8 | cx, cy: two s32. |
PointL | 8 | x, y: two s32. |
PointS | 4 | x, y: two s16. |
XForm | 24 | Six 32-bit floats: M11, M12, M21, M22, Dx, Dy. |
ColorRef | 4 | Red, green, blue, then a reserved byte. |
Records and code values are on the records page.