Windows Metafile (WMF) is an
image file format
An image file format is a file format for a digital image. There are many formats that can be used, such as JPEG, PNG, and GIF. Most formats up until 2022 were for storing 2D images, not 3D ones. The data stored in an image file format may be co ...
originally designed for
Microsoft Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
in the 1990s. The original Windows Metafile format was not device-independent (though could be made more so with placement headers) and may contain both
vector graphics
Vector graphics are a form of computer graphics in which visual images are created directly from geometric shapes defined on a Cartesian plane, such as points, lines, curves and polygons. The associated mechanisms may include vector displ ...
and
bitmap
In computing, a bitmap (also called raster) graphic is an image formed from rows of different colored pixels. A GIF is an example of a graphics image file that uses a bitmap.
As a noun, the term "bitmap" is very often used to refer to a partic ...
components. It acts in a similar manner to
SVG files. WMF files were later superseded by Enhanced Metafiles (EMF files) which did provide for device-independence. EMF files were then themselves enhanced via EMF+ files.
Essentially, a metafile stores a list of records consisting of drawing commands, property definitions and graphics objects to display an image on screen.
The drawing commands used are closely related to the commands of the
Graphics Device Interface
The Graphics Device Interface (GDI) is a legacy component of Microsoft Windows responsible for representing graphical objects and transmitting them to output devices such as monitors and printers. It was superseded by DirectDraw API and later ...
(GDI)
API
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build ...
used for drawing in Microsoft Windows.
There are three major types of metafiles – a WMF is a
16-bit
16-bit microcomputers are microcomputers that use 16-bit microprocessors.
A 16-bit register can store 216 different values. The range of integer values that can be stored in 16 bits depends on the integer representation used. With the two ...
format introduced in
Windows 3.0. It is the native
vector format for
Microsoft Office
Microsoft Office, MS Office, or simply Office, is an office suite and family of client software, server software, and services developed by Microsoft. The first version of the Office suite, announced by Bill Gates on August 1, 1988, at CO ...
applications such as
Word
A word is a basic element of language that carries semantics, meaning, can be used on its own, and is uninterruptible. Despite the fact that language speakers often have an intuitive grasp of what a word is, there is no consensus among linguist ...
,
PowerPoint, and
Publisher
Publishing is the activities of making information, literature, music, software, and other content, physical or digital, available to the public for sale or free of charge. Traditionally, the term publishing refers to the creation and distribu ...
. , revision 18 of the Windows Metafile Format specification is available.
EMF files, which replaced WMF files, work on the same principle only it is a 32-bit file format that also allows for the embedding of private data within "comment" records.
EMF+ is an extension to EMF files and embedded in these comment records, allowing for images and text using commands, objects and properties that are similar to Windows
GDI+
The Graphics Device Interface (GDI) is a legacy component of Microsoft Windows responsible for representing graphical objects and transmitting them to output devices such as monitors and printers. It was superseded by DirectDraw API and later ...
.
History
The original
16 bit WMF file format was fully specified in volume 4 of the 1992
Windows 3.1
Windows 3.1 is a major release of Microsoft Windows. It was released to manufacturing on April 6, 1992, as a successor to Windows 3.0. Like its predecessors, the Windows 3.1 series run as a shell on top of MS-DOS; it was the last Windows 1 ...
SDK documentation (at least if combined with the descriptions of the individual functions and structures in the other volumes), but that specification was vague about a few details. These manuals were published as printed books available in bookstores with no
click through EULA
An end-user license agreement or EULA () is a legal contract between a software supplier and a customer or end-user.
The practice of selling licenses to rather than copies of software predates the recognition of software copyright, which has ...
or other unusual licensing restrictions (just a general warning that if purchased as part of a software bundle, the software would be subject to one).
Over time the existence of that historic specification was largely forgotten and some alternative implementations resorted to reverse engineering to figure out the file format from existing WMF files, which was difficult and error prone. In September 2006, Microsoft again published the WMF file format specification in a more complete form in the context of the
Microsoft Open Specification Promise, promising to not assert patent rights to file format implementors.
Microsoft later deprecated WMF files in favour of
32-bit
In computer architecture, 32-bit computing refers to computer systems with a processor, memory, and other major system components that operate on data in a maximum of 32- bit units. Compared to smaller bit widths, 32-bit computers can perform la ...
EMF files as WMF files had real issues with device independence, despite the use of a "placeable" file header which provided basic device independence. Microsoft found that developers who use the format were "
mbeddingapplication, location, or scaling comments in the metafiles... Others added headers to the metafile that provided various application-specific information", causing major compatibility issues.
Thus, in 1992 with
Windows NT 3.1
Windows NT 3.1 is the first major release of the Windows NT operating system developed by Microsoft, released on July 27, 1993. It marked the company's entry into the corporate computing environment, designed to support large networks and to be ...
, Microsoft introduced the Enhanced Metafile format (EMF)
— a format which was based on the
Win32
The Windows API, informally WinAPI, is the foundational application programming interface (API) that allows a computer program to access the features of the Microsoft Windows operating system in which the program is running. Programs can acces ...
API and with which they built-in device independence.
— these were also known as NT metafiles. With the release of
Windows XP
Windows XP is a major release of Microsoft's Windows NT operating system. It was released to manufacturing on August 24, 2001, and later to retail on October 25, 2001. It is a direct successor to Windows 2000 for high-end and business users a ...
and GDI+, the set of records had to be significantly increased and so Microsoft released EMF+ as an extension to the existing EMF file format.
Metafile structure

WMF, EMF and EMF+ files all consist of a series of records that are played back to produce graphical output. Some records define objects which can specify graphical objects used to determine how graphics should be drawn (e.g. pens specify the color and width of lines). Each of these objects are stored in metafiles and are placed into an object table, which tracks the usage of graphic objects while processing the metafile. The object table is an
associative array
In computer science, an associative array, key-value store, map, symbol table, or dictionary is an abstract data type that stores a collection of (key, value) pairs, such that each possible key appears at most once in the collection. In math ...
of indexes to graphical object structures defined within the metafile.
WMF and EMF files handle object processing differently to EMF+ records in EMF files. As a WMF and EMF file is being processed, the records are read into an object table once an object is defined. If an object is deleted then the object is released from the table and the identifier can be reused. Notably an object will not be used until it is specifically selected during record playback. This differs for EMF+ files, which also use an associative array via a
hashmap which records the object along with an object identifier. However, unlike WMF and EMF files which can delete an object, when a new object is created that has the same index as an existing object, the entry in the table is replaced with the new object. An EMF file also does not need to specifically select an object before it is used.
WMF

WMF files were not originally designed to be device independent, meaning that a file could not be played back on output devices that differed from the original device on which the file was recorded. A partial solution to this issue was invented by
Aldus Corporation
Aldus Corporation was an American software company best known for its pioneering desktop publishing software. PageMaker, the company's most well-known product, ushered in the modern era of desktop computers such as the Macintosh seeing widesp ...
, who added an additional "placeable" header, called the "APM header",
which added a bounding rectangle, a metafile version, metafile size, number of objects in the metafile and the size of the largest single record in the metafile.
This was later incorporated into the WMF format by
Microsoft
Microsoft Corporation is an American multinational corporation and technology company, technology conglomerate headquartered in Redmond, Washington. Founded in 1975, the company became influential in the History of personal computers#The ear ...
, starting in
Windows 2000
Windows 2000 is a major release of the Windows NT operating system developed by Microsoft, targeting the server and business markets. It is the direct successor to Windows NT 4.0, and was Software release life cycle#Release to manufacturing (RT ...
.
WMF files are structured by a series of records, starting with a number of control records: the header record,
the aforementioned optional placeable record, and finished by an
end of file record.
Encapsulated by the control records are the records that make up the image itself. These records work within what is known as the ''playback device context'', which is the collection of properties and objects that make up a device's graphical environment as the metafile is being "played back" onto this output device.
Records other than control records can be largely grouped into bitmap records, drawing records, object records, state records and escape records.
Bitmap records
Bitmap records manage and output
bitmap image
In computing, a bitmap (also called raster) graphic is an image formed from rows of different colored pixels. A GIF is an example of a graphics image file that uses a bitmap.
As a noun, the term "bitmap" is very often used to refer to a partic ...
s.
Drawing records
Drawing records produce graphics output.
Object records
Object records create and manage graphics objects. In WMF files there are two broad categories of objects – graphics objects and structure objects. Structure objects are not explicitly created or deleted in a WMF, they are instead of complex structures. For example, the BitmapCoreHeader contains information about the dimensions and color format of a device-independent bitmap, which is itself part of a DeviceIndependentBitmap object. A graphics object, however, specifies parameters for graphics output and during playback of the WMF it sets up the playback device context.
Graphics objects can be ''brushes'' (defines the style, color and pattern of a brush which defines how to paint an area of the graphic), ''fonts'' (defines properties that affect how text is displayed), ''palettes'' (specifies colors as device-independent values, defined by an application), ''pens'' (specifies the graphical attributes of a line), and ''regions'' (which specify line and curve segments that define a shape).
State records
State records manage the graphics properties of the playback device context.
Escape records

Escape records are a means to extend metafile functionality via records that are not otherwise defined as a WMF record type. Each escape record contains a record function, an escape function and potentially escape data.
The following escape records make up a WMF file.
There was a
major vulnerability found in escape records around the Abort escape record, which stores the abort procedure code within the record itself. This affected Windows systems (see ) and the
Wine project (see ). According to
Secunia, "The vulnerability is caused due to an error in the handling of Windows Metafile files ('.wmf') containing specially crafted SETABORTPROC 'Escape' records. Such records allow arbitrary user-defined function to be executed when the rendering of a WMF file fails."
According to the Windows 3.1 SDK documentation, the SETABORTPROC escape was obsoleted and replaced by the function of the same name in Windows 3.1, long before the WMF vulnerability was discovered. However the obsoleted escape code was retained for compatibility with 16 bit programs written for (or at least backwards compatible with) Windows 3.0. This change happened at approximately the same time as Microsoft was creating the 32 bit reimplementation of GDI for Windows NT, and it is likely that the vulnerability occurred during this effort.
After
Steve Gibson accused Microsoft of deliberately implementing a
backdoor into their code,
Mark Russinovich
Mark Eugene Russinovich (born December 22, 1966) is a Spanish-born American software engineer and author who serves as CTO of Microsoft Azure. He was a cofounder of software producers Winternals before Microsoft acquired it in 2006.
Early lif ...
provided a rebuttal, and stated that:
Peter Ferrie of Symantec Security Response, USA also disagreed with Gibson, noting that:
EMF

EMF files have three possible versions of headers. The original headers is just a container for images, the second and third version encapsulates the original header and contains a pixel format record and support for OpenGL records, and the third version encapsulates the second header extension and increases EMF accuracy and scalability of EMFs as it adds the ability to measure distances of device surfaces using the metric system.
Each EMF header starts with an EMR_HEADER record, and records the relevant properties of the device on which the metafile image was recorded. The original EMF header has an 80 byte header and an optional variable length description string. Other metafiles contain extension fields, which encapsulate the original header.
EmfMetafileHeaderExtension1
is a record that is inserted directly after the original EMF header, specifies whether there is a pixel format descriptor and the offset to the descriptor object within the header, as well as a field that specifies if
OpenGL
OpenGL (Open Graphics Library) is a Language-independent specification, cross-language, cross-platform application programming interface (API) for rendering 2D computer graphics, 2D and 3D computer graphics, 3D vector graphics. The API is typic ...
records exist in the metafile. The pixel format descriptor specifies the capabilities of the drawing surface and whether a pixel is encoded in
RGBA
RGBA stands for red green blue alpha. While it is sometimes described as a color space, it is actually a three-channel RGB color model supplemented with a fourth ''alpha channel''. Alpha indicates how opaque each pixel is and allows an image to ...
or is an index into a color table.
EmfMetafileHeaderExtension2
is a record that is inserted directly after the
EmfMetafileHeaderExtension1
record, and it contains two fields with the X and Y values to measure the device surface in micrometers.
Like WMF files, records can be classified by function, however there are more record types in EMF files than there are in WMF files. Records can be classified as control, bitmap, clipping, comment, drawing, escape, object creation, object manipulation, OpenGL, path bracket, state and transform records.
EMF+
With the release of
Windows XP
Windows XP is a major release of Microsoft's Windows NT operating system. It was released to manufacturing on August 24, 2001, and later to retail on October 25, 2001. It is a direct successor to Windows 2000 for high-end and business users a ...
, the ''Enhanced Metafile Format Plus Extensions'' (EMF+) format was introduced. EMF+ provides a way to serialize calls to the
GDI+
The Graphics Device Interface (GDI) is a legacy component of Microsoft Windows responsible for representing graphical objects and transmitting them to output devices such as monitors and printers. It was superseded by DirectDraw API and later ...
API in the same way that WMF/EMF stores calls to GDI.
There are also compressed versions of Windows Metafiles known as ''Compressed Windows Metafile'' (WMZ) and ''Compressed Windows Enhanced Metafile'' (EMZ),
which are basically
gzip
gzip is a file format and a software application used for file compression and decompression. The program was created by Jean-loup Gailly and Mark Adler as a free software replacement for the compress program used in early Unix systems, and ...
compressed WMF and EMF files correspondingly.
Implementations
The WMF format was designed to be executed by the Windows GDI layer in order to restore the
image
An image or picture is a visual representation. An image can be Two-dimensional space, two-dimensional, such as a drawing, painting, or photograph, or Three-dimensional space, three-dimensional, such as a carving or sculpture. Images may be di ...
, but as the WMF binary files contain the definition of the GDI graphic primitives that constitute this image, it is possible to design alternative libraries that render WMF binary files or convert them into other graphic formats.
See also
*
PostScript
PostScript (PS) is a page description language and dynamically typed, stack-based programming language. It is most commonly used in the electronic publishing and desktop publishing realm, but as a Turing complete programming language, it c ...
*
Vector Markup Language (VML)
*
Scalable Vector Graphics
Scalable Vector Graphics (SVG) is an XML-based vector graphics format for defining two-dimensional graphics, having support for interactivity and animation. The SVG specification is an open standard developed by the World Wide Web Consortium sin ...
(SVG)
References
External links
Windows Metafile Format Specification from MicrosoftMetafiles – Windows applicationsFile Format Summary at fileformat.infoWindows Metafile FAQ
{{Graphics file formats
Graphics file formats
Vector graphics
Microsoft Windows multimedia technology