An EMF file is a list of records. Each one starts with its Type (u32) and
Size (u32, in bytes, a multiple of 4), and the fields listed below follow.
The header is the first record and
EMR_EOF the last. The numbers come from the MS-EMF
RecordType enumeration and the fields from the record sections of
[MS-EMF]
(revision 18.0, 23 April 2024); u32 and s32 are 4-byte unsigned and signed integers,
little-endian. Bitmap records end with a buffer holding the bitmap headers and bits at
the offsets they give.
Drawing records
| Value | Name | Fields after Size | Meaning |
|---|---|---|---|
| 0x02 | EMR_POLYBEZIER | Bounds RectL, count u32, PointL[count] | Bezier curves. |
| 0x03 | EMR_POLYGON | Bounds RectL, count u32, PointL[count] | Closed polygon. |
| 0x04 | EMR_POLYLINE | Bounds RectL, count u32, PointL[count] | Connected lines. |
| 0x05 | EMR_POLYBEZIERTO | Bounds RectL, count u32, PointL[count] | Beziers from the current position. |
| 0x06 | EMR_POLYLINETO | Bounds RectL, count u32, PointL[count] | Lines from the current position. |
| 0x07 | EMR_POLYPOLYLINE | Bounds RectL, nPolys u32, total u32, nPolys u32 counts, PointL points | Several polylines. |
| 0x08 | EMR_POLYPOLYGON | Same layout as EMR_POLYPOLYLINE | Several polygons. |
| 0x0F | EMR_SETPIXELV | Pixel PointL, ColorRef | Set one pixel. |
| 0x29 | EMR_ANGLEARC | Center PointL, radius u32, start float, sweep float | Arc on a circle. |
| 0x2A | EMR_ELLIPSE | Box RectL | Ellipse. |
| 0x2B | EMR_RECTANGLE | Box RectL | Rectangle. |
| 0x2C | EMR_ROUNDRECT | Box RectL, corner SizeL | Rectangle with rounded corners. |
| 0x2D | EMR_ARC | Box RectL, start PointL, end PointL | Elliptical arc. |
| 0x2E | EMR_CHORD | Box RectL, start PointL, end PointL | Chord. |
| 0x2F | EMR_PIE | Box RectL, start PointL, end PointL | Pie wedge. |
| 0x35 | EMR_EXTFLOODFILL | Start PointL, Color ColorRef, FloodFillMode u32 | Flood fill. |
| 0x36 | EMR_LINETO | PointL | Line to a point. |
| 0x37 | EMR_ARCTO | Box RectL, start PointL, end PointL | Arc that moves the current position. |
| 0x38 | EMR_POLYDRAW | Bounds RectL, Count u32, PointL[Count], abTypes u8[Count] | Lines and Beziers. |
| 0x47 | EMR_FILLRGN | Bounds RectL, RgnDataSize u32, ihBrush u32, RgnData (RegionData) | Fill a region with a brush. |
| 0x48 | EMR_FRAMERGN | Bounds RectL, RgnDataSize u32, ihBrush u32, Width s32, Height s32, RgnData | Border around a region; width of vertical and height of horizontal strokes. |
| 0x49 | EMR_INVERTRGN | Bounds RectL, RgnDataSize u32, RgnData | Invert a region. |
| 0x4A | EMR_PAINTRGN | Bounds RectL, RgnDataSize u32, RgnData | Paint a region with the current brush. |
| 0x53 | EMR_EXTTEXTOUTA | Same layout as EMR_EXTTEXTOUTW | ASCII text. |
| 0x54 | EMR_EXTTEXTOUTW | Bounds RectL, iGraphicsMode u32, exScale float, eyScale float, EmrText | Unicode text. |
| 0x55 | EMR_POLYBEZIER16 | Bounds RectL, count u32, PointS[count] | 16-bit form. |
| 0x56 | EMR_POLYGON16 | Bounds RectL, count u32, PointS[count] | 16-bit form. |
| 0x57 | EMR_POLYLINE16 | Bounds RectL, count u32, PointS[count] | 16-bit form. |
| 0x58 | EMR_POLYBEZIERTO16 | Bounds RectL, count u32, PointS[count] | 16-bit form. |
| 0x59 | EMR_POLYLINETO16 | Bounds RectL, count u32, PointS[count] | 16-bit form. |
| 0x5A | EMR_POLYPOLYLINE16 | Bounds, nPolys, total, counts, PointS | 16-bit form. |
| 0x5B | EMR_POLYPOLYGON16 | Bounds, nPolys, total, counts, PointS | 16-bit form. |
| 0x5C | EMR_POLYDRAW16 | Bounds, count, PointS, type bytes | 16-bit form. |
| 0x60 | EMR_POLYTEXTOUTA | Bounds RectL, iGraphicsMode u32, exScale float, eyScale float, cStrings u32, EmrText[cStrings] (8-bit strings) | Several ASCII strings. |
| 0x61 | EMR_POLYTEXTOUTW | As EMR_POLYTEXTOUTA, with Unicode strings | Several Unicode strings. |
| 0x6C | EMR_SMALLTEXTOUT | x s32, y s32, cChars u32, fuOptions u32, iGraphicsMode u32, exScale float, eyScale float, Bounds RectL (absent if ETO_NO_RECT), TextString (8-bit codes if ETO_SMALL_CHARS, else 16-bit; not null-terminated) | A compact text record. |
| 0x76 | EMR_GRADIENTFILL | Bounds, nVer, nTri, ulMode, TriVertex[nVer], then rectangles or triangles | Gradient fill. |
EmrText holds the reference point, character count, string offset, options,
clip rectangle and spacing offset: ptlReference (PointL),
nChars, offString, fOptions, rcl
(RectL), offDx.
Path records
| Value | Name | Fields | Meaning |
|---|---|---|---|
| 0x3B | EMR_BEGINPATH | None | Open a path. |
| 0x3C | EMR_ENDPATH | None | Close the path and select it. |
| 0x3D | EMR_CLOSEFIGURE | None | Close the open figure. |
| 0x3E | EMR_FILLPATH | Bounds RectL | Fill the path. |
| 0x3F | EMR_STROKEANDFILLPATH | Bounds RectL | Stroke and fill. |
| 0x40 | EMR_STROKEPATH | Bounds RectL | Stroke. |
| 0x41 | EMR_FLATTENPATH | None | Turn curves into lines. |
| 0x42 | EMR_WIDENPATH | None | Widen the path to the pen. |
| 0x43 | EMR_SELECTCLIPPATH | RegionMode | Use the path as clip region. |
| 0x44 | EMR_ABORTPATH | None | Discard the path. |
Bitmap records
| Value | Name | Fields after Size | Meaning |
|---|---|---|---|
| 0x4C | EMR_BITBLT | Bounds RectL, xDest, yDest, cxDest, cyDest (s32), dwRop u32, xSrc, ySrc s32, xformSrc XForm, crBkColorSrc, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc (u32) | Block transfer. |
| 0x4D | EMR_STRETCHBLT | Same as EMR_BITBLT, then cxSrc, cySrc (s32) | With stretching. |
| 0x4E | EMR_MASKBLT | Bounds RectL, xDest, yDest, cxDest, cyDest (s32), ROP4 (Reserved u16, BackgroundROP3 u8, ForegroundROP3 u8), xSrc, ySrc s32, XformSrc, BkColorSrc, UsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, xMask, yMask s32, UsageMask, offBmiMask, cbBmiMask, offBitsMask, cbBitsMask (u32) | Block transfer with a mask. |
| 0x4F | EMR_PLGBLT | Bounds RectL, aptlDest PointL[3], xSrc, ySrc, cxSrc, cySrc (s32), XformSrc, BkColorSrc, UsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, xMask, yMask, UsageMask, offBmiMask, cbBmiMask, offBitsMask, cbBitsMask | Transfer to a parallelogram. |
| 0x50 | EMR_SETDIBITSTODEVICE | Bounds RectL, xDest, yDest, xSrc, ySrc, cxSrc, cySrc (s32), offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, UsageSrc, iStartScan, cScans (u32) | Pixels from DIB scan lines. |
| 0x51 | EMR_STRETCHDIBITS | Bounds RectL, xDest, yDest, xSrc, ySrc, cxSrc, cySrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, iUsageSrc, dwRop, cxDest, cyDest | Stretch a DIB. |
| 0x72 | EMR_ALPHABLEND | As EMR_STRETCHBLT, with a 4-byte BLENDFUNCTION in place of the raster operation | Copy with alpha. |
| 0x74 | EMR_TRANSPARENTBLT | As EMR_STRETCHBLT, with TransparentColor (ColorRef) in place of the raster operation | Copy with one colour transparent. |
Bitmap headers and pixels are stored inside the record at
offBmiSrc and offBitsSrc and use the same formats as a
BMP DIB.
Object records
| Value | Name | Fields after Size | Meaning |
|---|---|---|---|
| 0x25 | EMR_SELECTOBJECT | ihObject u32 | Select an object, or a stock object if the top bit is set. |
| 0x26 | EMR_CREATEPEN | ihPen u32, LogPen | Create a pen. |
| 0x27 | EMR_CREATEBRUSHINDIRECT | ihBrush u32, LogBrush | Create a brush. |
| 0x28 | EMR_DELETEOBJECT | ihObject u32 | Delete an object. |
| 0x30 | EMR_SELECTPALETTE | ihPal u32 | Select a palette. |
| 0x31 | EMR_CREATEPALETTE | ihPal u32, LogPalette (Version 0x0300) | Create a palette. |
| 0x32 | EMR_SETPALETTEENTRIES | ihPal u32, Start u32, NumberofEntries u32, LogPaletteEntry[NumberofEntries] | Set colours in a palette. |
| 0x33 | EMR_RESIZEPALETTE | ihPal u32, NumberOfEntries u32 | Resize a palette. |
| 0x34 | EMR_REALIZEPALETTE | None | Map to the system palette. |
| 0x52 | EMR_EXTCREATEFONTINDIRECTW | ihFont u32, ExtLogFontW | Create a font. |
| 0x5D | EMR_CREATEMONOBRUSH | ihBrush u32, Usage u32, offBmi, cbBmi, offBits, cbBits (u32), then the monochrome DIB | Brush from a bitmap. |
| 0x5E | EMR_CREATEDIBPATTERNBRUSHPT | ihBrush u32, Usage u32, offBmi, cbBmi, offBits, cbBits (u32), then the DIB | Brush from a DIB. |
| 0x5F | EMR_EXTCREATEPEN | ihPen u32, offBmi, cbBmi, offBits, cbBits u32, ExtLogPen32 | Extended pen. |
| 0x63 | EMR_CREATECOLORSPACE | ihCS u32, lcs (LogColorSpace) | Colour space, ASCII profile name. |
| 0x64 | EMR_SETCOLORSPACE | ihCS u32 | Select a colour space. |
| 0x65 | EMR_DELETECOLORSPACE | ihCS u32 | Delete a colour space. |
| 0x6F | EMR_COLORCORRECTPALETTE | ihPalette u32, nFirstEntry u32, nPalEntries u32, nReserved u32 | Correct palette entries. |
| 0x7A | EMR_CREATECOLORSPACEW | ihCS u32, lcs (LogColorSpaceW), dwFlags u32, cbData u32, Data[cbData] | Colour space, Unicode profile name, optional embedded profile. |
State records
| Value | Name | Fields | Meaning |
|---|---|---|---|
| 0x09 | EMR_SETWINDOWEXTEX | SizeL | Window extent. |
| 0x0A | EMR_SETWINDOWORGEX | PointL | Window origin. |
| 0x0B | EMR_SETVIEWPORTEXTEX | SizeL | Viewport extent. |
| 0x0C | EMR_SETVIEWPORTORGEX | PointL | Viewport origin. |
| 0x0D | EMR_SETBRUSHORGEX | PointL | Brush origin. |
| 0x10 | EMR_SETMAPPERFLAGS | Flags u32 | Font mapper flags. |
| 0x11 | EMR_SETMAPMODE | iMode u32 | Map mode. |
| 0x12 | EMR_SETBKMODE | iMode u32 | Background mode. |
| 0x13 | EMR_SETPOLYFILLMODE | iMode u32 | Polygon fill mode. |
| 0x14 | EMR_SETROP2 | iMode u32 | Foreground mix. |
| 0x15 | EMR_SETSTRETCHBLTMODE | iMode u32 | Stretch mode. |
| 0x16 | EMR_SETTEXTALIGN | u32 | Text alignment. |
| 0x17 | EMR_SETCOLORADJUSTMENT | ColorAdjustment (24 bytes) | Colour adjustment. |
| 0x18 | EMR_SETTEXTCOLOR | ColorRef | Text colour. |
| 0x19 | EMR_SETBKCOLOR | ColorRef | Background colour. |
| 0x1A | EMR_OFFSETCLIPRGN | PointL | Move the clip region. |
| 0x1B | EMR_MOVETOEX | PointL | Current position. |
| 0x1C | EMR_SETMETARGN | None | Combine clip region into the metaregion. |
| 0x1D | EMR_EXCLUDECLIPRECT | RectL | Remove a rectangle from the clip. |
| 0x1E | EMR_INTERSECTCLIPRECT | RectL | Intersect the clip. |
| 0x1F | EMR_SCALEVIEWPORTEXTEX | xNum, xDenom, yNum, yDenom (s32, none zero) | Scale the viewport. |
| 0x20 | EMR_SCALEWINDOWEXTEX | xNum, xDenom, yNum, yDenom (s32, none zero) | Scale the window. |
| 0x21 | EMR_SAVEDC | None | Save the state. |
| 0x22 | EMR_RESTOREDC | iRelative s32 | Restore a saved state. |
| 0x23 | EMR_SETWORLDTRANSFORM | XForm | World transform. |
| 0x24 | EMR_MODIFYWORLDTRANSFORM | XForm, iMode u32 | Modify the transform. |
| 0x39 | EMR_SETARCDIRECTION | u32 | Arc direction. |
| 0x3A | EMR_SETMITERLIMIT | MiterLimit, 4 bytes | Miter limit. MS-EMF calls the field an unsigned integer; its note says Windows GDI accepts a float. |
| 0x4B | EMR_EXTSELECTCLIPRGN | RgnDataSize u32, RegionMode u32, RgnData (RegionData) | Combine with the clip region. |
| 0x62 | EMR_SETICMMODE | u32 | Colour management mode. |
| 0x68 | EMR_PIXELFORMAT | pfd (PixelFormatDescriptor, 40 bytes) | Pixel format. |
| 0x6D | EMR_FORCEUFIMAPPING | ufi (UniversalFontId, 8 bytes) | Font mapping by id. |
| 0x70 | EMR_SETICMPROFILEA | dwFlags u32, cbName u32, cbData u32, Data (ASCII name, then profile data) | Colour profile, ASCII name. |
| 0x71 | EMR_SETICMPROFILEW | dwFlags u32, cbName u32, cbData u32, Data (UTF-16LE name, then profile data) | Colour profile, Unicode name. |
| 0x73 | EMR_SETLAYOUT | u32 | Text and graphics order. |
| 0x77 | EMR_SETLINKEDUFIS | uNumLinkedUFI u32, UniversalFontId[uNumLinkedUFI], Reserved (8 bytes) | Linked fonts. |
| 0x78 | EMR_SETTEXTJUSTIFICATION | nBreakExtra s32, nBreakCount s32 | Extra space on break characters. |
| 0x79 | EMR_COLORMATCHTOTARGETW | dwAction u32, dwFlags u32, cbName u32, cbData u32, Data (UTF-16LE name, then target profile data) | Colour matching to a target. |
Other records
| Value | Name | Meaning |
|---|---|---|
| 0x01 | EMR_HEADER | See Header. |
| 0x0E | EMR_EOF | End of file. Fields: nPalEntries, offPalEntries, optional palette, SizeLast (the record’s size again, last in the file). |
| 0x46 | EMR_COMMENT | Comment. Fields: DataSize, then the data. |
| 0x66 | EMR_GLSRECORD | OpenGL function. Fields: cbData u32, Data. |
| 0x67 | EMR_GLSBOUNDEDRECORD | OpenGL function with bounds. Fields: Bounds RectL, cbData u32, Data. |
| 0x69 | EMR_DRAWESCAPE | Data for the driver, intended to draw. Fields: iEscape u32, cjIn u32, Data. |
| 0x6A | EMR_EXTESCAPE | Data for the driver, not drawing. Fields: iEscape u32, cjIn u32, Data. |
| 0x6E | EMR_NAMEDESCAPE | Data for a named driver. Fields: iEscape u32, cjDriver u32, cjIn u32, DriverName (null-terminated UTF-16), Data. |
Values not listed, such as 0x45, 0x6B and 0x75, have no named record type in the MS-EMF list.
Comments and EMF+
A comment record holds DataSize and then the data. If the data starts with
one of the identifiers below, it is one of the defined comment types. Any other start
means private application data.
| Value | Name | Meaning |
|---|---|---|
0x00000000 | EMR_COMMENT_EMFSPOOL | Holds EMFSPOOL records (MS-EMFSPOOL). |
0x2B464D45 | EMR_COMMENT_EMFPLUS | Bytes EMF+. Holds EMF+ records (MS-EMFPLUS). |
0x43494447 | EMR_COMMENT_PUBLIC | Bytes GDIC. Extension comments. |
A public comment identifies its type next:
| Value | Name | Meaning |
|---|---|---|
0x80000001 | EMR_COMMENT_WINDOWS_METAFILE | Holds a WMF image. |
0x00000002 | EMR_COMMENT_BEGINGROUP | Starts a group of drawing records. |
0x00000003 | EMR_COMMENT_ENDGROUP | Ends a group. |
0x40000004 | EMR_COMMENT_MULTIFORMATS | Several definitions of the same image, for example EPS and EMF. |
0x00000040 | EMR_COMMENT_UNICODE_STRING | Reserved, must not be used. |
0x00000080 | EMR_COMMENT_UNICODE_END | Reserved, must not be used. |
In EMR_COMMENT_MULTIFORMATS, each format starts with a signature:
0x464D4520 “ EMF” for EMF data or 0x46535045 “EPSF” for
PostScript. EMF+ is a separate format, specified in
[MS-EMFPLUS].
Its own record set is not listed on this site; a program that only knows plain EMF
plays the plain records that normally accompany it.
Stock objects
An object index with the top bit set is a stock object.
| Value | Name | Value | Name |
|---|---|---|---|
0x80000000 | WHITE_BRUSH | 0x80000001 | LTGRAY_BRUSH |
0x80000002 | GRAY_BRUSH | 0x80000003 | DKGRAY_BRUSH |
0x80000004 | BLACK_BRUSH | 0x80000005 | NULL_BRUSH |
0x80000006 | WHITE_PEN | 0x80000007 | BLACK_PEN |
0x80000008 | NULL_PEN | 0x8000000A | OEM_FIXED_FONT |
0x8000000B | ANSI_FIXED_FONT | 0x8000000C | ANSI_VAR_FONT |
0x8000000D | SYSTEM_FONT | 0x8000000E | DEVICE_DEFAULT_FONT |
0x8000000F | DEFAULT_PALETTE | 0x80000010 | SYSTEM_FIXED_FONT |
0x80000011 | DEFAULT_GUI_FONT | 0x80000012 | DC_BRUSH |
0x80000013 | DC_PEN |
Code values
| Field | Values |
|---|---|
| Graphics mode | 1 GM_COMPATIBLE, 2 GM_ADVANCED |
| Arc direction | 1 AD_COUNTERCLOCKWISE, 2 AD_CLOCKWISE |
| World transform mode | 1 MWT_IDENTITY, 2 MWT_LEFTMULTIPLY, 3 MWT_RIGHTMULTIPLY |
| Region mode | 1 RGN_AND, 2 RGN_OR, 3 RGN_XOR, 4 RGN_DIFF, 5 RGN_COPY |
| Point type | PT_CLOSEFIGURE 1, PT_LINETO 2, PT_BEZIERTO 4, PT_MOVETO 6 |
| Map mode, ROP2, brush, pen, stretch and fill modes | As in WMF; the pen style also has PS_GEOMETRIC 0x10000. |