After the header a metafile is a list of records that are played in order. Each one is a recorded call to the 16-bit Windows graphics system.
Record layout
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | RecordSize | Size of the whole record in 16-bit words, including these six bytes. |
| 4 | 2 | u16 | RecordFunction | The function number. The low byte identifies the record; the high byte is the number of 16-bit parameter words, by convention. |
| 6 | varies | Parameters | Words in the order listed below. |
Parameters are stored in the reverse of the order in which the GDI call takes them, so
MoveTo(x, y) stores y first. Coordinates and offsets are
signed 16-bit (s16). A colour (ColorRef) is 4 bytes and is
written red green blue 0. The high byte of the function number should be
ignored, except for META_BITBLT, META_DIBBITBLT,
META_DIBSTRETCHBLT, META_POLYGON, META_POLYLINE,
META_SETPALENTRIES and META_STRETCHBLT, where it carries
meaning.
The Field columns below list parameters in file order, after RecordFunction.
Where a parameter is a combined value, the layout is spelled out. The structures and
code values are on the objects and codes page.
Control records
| Function | Name | Fields | Meaning |
|---|---|---|---|
0x0000 | META_EOF | None | End of the file. The record is three words: 03 00 00 00 00 00. |
Drawing records
| Function | Name | Fields | Meaning |
|---|---|---|---|
0x0213 | META_LINETO | y, x | Line from the output position up to, not including, the point. |
0x0324 | META_POLYGON | NumberOfPoints (u16), then x, y pairs (s16) | Closed polygon, outlined with the pen and filled with the brush and fill mode. |
0x0325 | META_POLYLINE | NumberOfPoints (u16), then x, y pairs (s16) | Connected line segments. |
0x0538 | META_POLYPOLYGON | NumberOfPolygons (u16), a u16 count per polygon, then all x, y pairs (s16) | A series of closed polygons, which may overlap. |
0x041B | META_RECTANGLE | bottom, right, top, left | Rectangle. |
0x0418 | META_ELLIPSE | bottom, right, top, left | Ellipse inside the bounding rectangle. |
0x061C | META_ROUNDRECT | height, width, bottom, right, top, left | Rectangle with rounded corners, whose ellipse is width by height. |
0x0817 | META_ARC | yEnd, xEnd, yStart, xStart, bottom, right, top, left | Elliptical arc. |
0x081A | META_PIE | yEnd, xEnd, yStart, xStart, bottom, right, top, left | Pie-shaped wedge between two radials. |
0x0830 | META_CHORD | yEnd, xEnd, yStart, xStart, bottom, right, top, left | Region bounded by an ellipse and a line segment. |
0x041F | META_SETPIXEL | ColorRef, y, x | Set one pixel. |
0x0419 | META_FLOODFILL | ColorRef, y, x | Fill an area with the brush. |
0x0548 | META_EXTFLOODFILL | Mode (u16), ColorRef, y, x | Fill with a FloodFill mode. |
0x061D | META_PATBLT | RasterOperation (u32), height, width, y, x | Paint a rectangle with the brush and a raster operation. |
0x0521 | META_TEXTOUT | StringLength (u16), the string padded to even length, y, x | Draw text with the current font and colours. |
0x0a32 | META_EXTTEXTOUT | y, x, StringLength (u16), fwOpts (u16), Rectangle (only with ETO_OPAQUE or ETO_CLIPPED), string padded to even length, optional s16 Dx per character | Text with optional clip or opaque rectangle and spacing. |
0x0228 | META_FILLREGION | Brush index, Region index | Fill a region with a brush. |
0x0429 | META_FRAMEREGION | height, width, Brush index, Region index | Draw a border around a region. |
0x012A | META_INVERTREGION | Region index | Invert the colours in a region. |
0x012B | META_PAINTREGION | Region index | Paint a region with the current brush. |
Bitmap records
Each of these carries a raster operation code as a 32-bit value; see
the codes page. The bitmap formats are
Bitmap16 (device-dependent) and DeviceIndependentBitmap,
which is the same as a DIB in a BMP
file.
| Function | Name | Fields | Meaning |
|---|---|---|---|
0x0922 | META_BITBLT | RasterOperation (high word), ySrc, xSrc, height, width, yDest, xDest, then a Bitmap16: Width, Height, width in bytes, Planes, BitsPixel, Bits | Copy a block of pixels with a raster operation. |
0x0B23 | META_STRETCHBLT | RasterOperation (u32), srcHeight, srcWidth, ySrc, xSrc, destHeight, destWidth, yDest, xDest, then a Bitmap16 | Copy with stretching. |
0x0940 | META_DIBBITBLT | RasterOperation (u32), ySrc, xSrc, height, width, yDest, xDest, then a DIB. A short record without a DIB is a pattern form: RasterOperation, height, width, y, x | Copy device-independent pixels. |
0x0b41 | META_DIBSTRETCHBLT | RasterOperation (u32), srcHeight, srcWidth, ySrc, xSrc, destHeight, destWidth, yDest, xDest, then a DIB | Copy device-independent pixels with stretching. |
0x0f43 | META_STRETCHDIB | RasterOperation (u32), ColorUsage, srcHeight, srcWidth, ySrc, xSrc, destHeight, destWidth, yDest, xDest, then a DIB | Copy colour data from a DIB with stretching. |
0x0d33 | META_SETDIBTODEV | ColorUsage, numScans, startScan, ySrc, xSrc, height, width, yDest, xDest, then a DIB | Set a block of pixels from DIB scan lines. |
Object records
Created objects go into a table indexed from 0, whose size is
NumberOfObjects in the header. A new object takes the lowest free slot.
META_SELECTOBJECT and META_DELETEOBJECT refer to those slots,
and the region and palette records use them too.
| Function | Name | Fields | Meaning |
|---|---|---|---|
0x02FA | META_CREATEPENINDIRECT | Pen object: PenStyle (u16), Width (s16 x, s16 y, y ignored), ColorRef | Create a pen. |
0x02FC | META_CREATEBRUSHINDIRECT | LogBrush: BrushStyle (u16), ColorRef, BrushHatch (u16) | Create a brush. |
0x02FB | META_CREATEFONTINDIRECT | Font object, see codes page | Create a font. |
0x00f7 | META_CREATEPALETTE | Palette object | Create a logical palette. |
0x06FF | META_CREATEREGION | Region object | Create a region. |
0x01F9 | META_CREATEPATTERNBRUSH | Style word, then a bitmap | Create a pattern brush from a bitmap. |
0x0142 | META_DIBCREATEPATTERNBRUSH | Style (u16), ColorUsage (u16), then a DIB | Create a pattern brush from a DIB. |
0x012D | META_SELECTOBJECT | ObjectIndex | Make an object current in place of the same type. |
0x01f0 | META_DELETEOBJECT | ObjectIndex | Delete an object and free its slot. |
0x0234 | META_SELECTPALETTE | Palette object index | Make a palette current. |
0x012C | META_SELECTCLIPREGION | Region index (0 for none) | Set the clipping region. |
State records
| Function | Name | Fields | Meaning |
|---|---|---|---|
0x001E | META_SAVEDC | None | Save the playback state. |
0x0127 | META_RESTOREDC | nSavedDC (s16) | Restore a saved state. |
0x020B | META_SETWINDOWORG | y, x | Window origin. |
0x020C | META_SETWINDOWEXT | cy, cx | Window extent. |
0x020D | META_SETVIEWPORTORG | y, x | Viewport origin. |
0x020E | META_SETVIEWPORTEXT | cy, cx | Viewport extent. |
0x020F | META_OFFSETWINDOWORG | dy, dx | Move the window origin. |
0x0211 | META_OFFSETVIEWPORTORG | dy, dx | Move the viewport origin. |
0x0410 | META_SCALEWINDOWEXT | yDenom, yNum, xDenom, xNum | Scale the window extent by ratios. |
0x0412 | META_SCALEVIEWPORTEXT | yDenom, yNum, xDenom, xNum | Scale the viewport extent by ratios. |
0x0103 | META_SETMAPMODE | MapMode | How logical units map to device units. |
0x0214 | META_MOVETO | y, x | Set the output position. |
0x0201 | META_SETBKCOLOR | ColorRef | Background colour. |
0x0102 | META_SETBKMODE | MixMode | Background mix mode. |
0x0209 | META_SETTEXTCOLOR | ColorRef | Text colour. |
0x012E | META_SETTEXTALIGN | TextAlignmentMode | Text alignment. |
0x0108 | META_SETTEXTCHAREXTRA | extra (s16) | Extra spacing between characters. |
0x020A | META_SETTEXTJUSTIFICATION | breakCount, extra | Space added to break characters. |
0x0104 | META_SETROP2 | BinaryRasterOperation | Foreground mix mode. |
0x0106 | META_SETPOLYFILLMODE | PolyFillMode | Fill mode for polygons. |
0x0107 | META_SETSTRETCHBLTMODE | StretchMode | How stretched bitmaps are resampled. |
0x0105 | META_SETRELABS | mode | Undefined; must be ignored. |
0x0149 | META_SETLAYOUT | Layout | Layout orientation. |
0x0231 | META_SETMAPPERFLAGS | flags (u32) | Font mapper algorithm. |
0x0415 | META_EXCLUDECLIPRECT | bottom, right, top, left | Remove a rectangle from the clip region. |
0x0416 | META_INTERSECTCLIPRECT | bottom, right, top, left | Intersect the clip region with a rectangle. |
0x0220 | META_OFFSETCLIPRGN | dy, dx | Move the clip region. |
0x0035 | META_REALIZEPALETTE | None | Map the logical palette to the system palette. |
0x0037 | META_SETPALENTRIES | Palette object | Set colours in a palette range. |
0x0139 | META_RESIZEPALETTE | Number of entries | Change the palette size. |
0x0436 | META_ANIMATEPALETTE | Palette object | Replace palette entries for animation. |
Escape records
Function 0x0626 (META_ESCAPE) passes data to a printer driver
or carries an embedded metafile. Its fields are EscapeFunction (u16),
ByteCount (u16) and the data. The escape values are on the
codes page. The most important is
META_ESCAPE_ENHANCED_METAFILE (0x000F), which embeds an
EMF file, split across several records.