---
name: "EMF_METAFILEDEVICECONTEXT"
section: "3"
platform: "linux"
package: "libemf-doc"
version: "1.0.13-8"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/EMF_METAFILEDEVICECONTEXT"
---

# EMF\_METAFILEDEVICECONTEXT(3)

Graphics Device Context.

## NAME

EMF::METAFILEDEVICECONTEXT - Graphics Device Context.

## SYNOPSIS

`#include <libemf.h>`

Inherits **EMF::OBJECT**.

### Public Member Functions

**METAFILEDEVICECONTEXT** (FILE \*fp\_, const RECT \*size, LPCWSTR description\_w)\
 virtual **~METAFILEDEVICECONTEXT** ()\
 OBJECTTYPE **getType** (void) const\
 DWORD **nextHandle** (void)\
 void **clearHandle** (DWORD **handle**)\
 void **appendRecord** (**METARECORD** \*record)\
 void **appendHandle** (**METARECORD** \*record)\
 void **deleteMetafile** (void)\
 void **mergePoint** (const LONG &x, const LONG &y)\
 void **mergePoint** (const POINT &p)\

Public Member Functions inherited from **EMF::OBJECT** virtual **~OBJECT** ()\
 OBJECTs have a virtual destructor.  **OBJECT** (void)\

### Data Fields

::FILE \* **fp**\
 **DATASTREAM** **ds**\
 **ENHMETAHEADER** \* **header**\
 std::vector\< **EMF::METARECORD** \* \> **records**\
 SIZEL **resolution**\
 The resolution in DPI of the *reference* DC.  SIZEL **viewport\_ext**\
 The extent of the viewport.  POINT **viewport\_org**\
 The origin of the viewport.  SIZEL **window\_ext**\
 The extent of the window.  POINT **window\_org**\
 The origin of the window.  bool **update\_frame**\
 Update the frame automatically?  POINT **min\_device\_point**\
 The lft/top-most painted point in device units.  POINT **max\_device\_point**\
 The rgt/btm-most painted point in device units.  POINT **point**\
 The current point.  **PEN** \* **pen**\
 The current pen.  **BRUSH** \* **brush**\
 The current brush.  **FONT** \* **font**\
 The current font.  **PALETTE** \* **palette**\
 The current palette.  UINT **text\_alignment**\
 The current text alignment.  COLORREF **text\_color**\
 The current text foreground color.  COLORREF **bk\_color**\
 The current background color.  INT **bk\_mode**\
 The current background mode.  INT **polyfill\_mode**\
 The current polygon fill mode.  INT **map\_mode**\
 The current mapping mode.  FLOAT **miter\_limit**\
 The current miter length limit.  std::vector\< bool \> **handles**\
 std::map\< HGDIOBJ, HGDIOBJ \> **emf\_handles**\

Data Fields inherited from **EMF::OBJECT** HGDIOBJ **handle**\

## Detailed Description

Graphics Device Context.

Almost all GDI graphics calls require a device context (except those which create graphics objects such as pens and fonts). This is a specific context which renders to a metafile. There is a one-to-one correspondence between the device context and the metafile.

## Constructor & Destructor Documentation

### EMF::METAFILEDEVICECONTEXT::METAFILEDEVICECONTEXT (FILE \* fp\_, const RECT \* size, LPCWSTR description\_w)` [inline]`

Most graphics programs seem to want to handle the opening and closing of files themselves, so this is an extension to the w32 interface.

**Parameters**

*fp\_* stdio pointer to an open file. May be null. \
 *size* the rectangle describing the position and size of the metafile on the 'page'. May be null. \
 *description\_w* a UNICODE string describing the metafile. The format must be 'some text\\0some more text\\0\\0'. May be null.

### virtual EMF::METAFILEDEVICECONTEXT::~METAFILEDEVICECONTEXT ()` [inline]`, ` [virtual]`

Destructor frees all the graphics objects which may have been allocated. Now, it also frees any metarecords which it might hold, too.

References **deleteMetafile()**, and **records**.

## Member Function Documentation

### void EMF::METAFILEDEVICECONTEXT::appendHandle (METARECORD \* record)` [inline]`

Add this record to the metafile.

**Parameters**

*record* this record is an object so it increments the handle count as well.

References **header**, **records**, and **EMF::METARECORD::size()**.

### void EMF::METAFILEDEVICECONTEXT::appendRecord (METARECORD \* record)` [inline]`

Add this record to the metafile.

**Parameters**

*record* standard graphics record

References **header**, **records**, and **EMF::METARECORD::size()**.

### void EMF::METAFILEDEVICECONTEXT::clearHandle (DWORD handle)` [inline]`

Clear the usage of this handle

References **EMF::OBJECT::handle**, and **handles**.

### void EMF::METAFILEDEVICECONTEXT::deleteMetafile (void)` [inline]`

Delete all the records from the metafile. This would seem to include deleting the header record as well.

References **records**.

Referenced by **~METAFILEDEVICECONTEXT()**.

### OBJECTTYPE EMF::METAFILEDEVICECONTEXT::getType (void) const` [inline]`, ` [virtual]`

Return the type of this object (could probably do better with RTTI()).

Implements **EMF::OBJECT**.

### void EMF::METAFILEDEVICECONTEXT::mergePoint (const LONG & x, const LONG & y)` [inline]`

Somewhat superfluous, except checker doesn't understand the initialization of automatic structures in the declaration.

References **mergePoint()**.

Referenced by **mergePoint()**.

### void EMF::METAFILEDEVICECONTEXT::mergePoint (const POINT & p)` [inline]`

Take the given point and determine if it enlarges the 'painted' area of the device.

References **header**, **max\_device\_point**, **min\_device\_point**, **update\_frame**, **viewport\_ext**, **viewport\_org**, **window\_ext**, and **window\_org**.

### DWORD EMF::METAFILEDEVICECONTEXT::nextHandle (void)` [inline]`

Scan the bit vector of used handles and return the index of the first free bit as this objects metafile handle.

References **handles**, **header**, and **EMF::ENHMETAHEADER::size()**.

## Field Documentation

### DATASTREAM EMF::METAFILEDEVICECONTEXT::ds

All i/o to the metafile is wrapped by this class so that byte swapping on big-endian machines is transparent.

### std::map\< HGDIOBJ, HGDIOBJ \> EMF::METAFILEDEVICECONTEXT::emf\_handles

This map holds the *current* mapping between EMF handles and global object handles as a metafile is played back (with PlayEnhMetaFile).

Referenced by **EMF::EMRSELECTOBJECT::execute()**, **EMF::EMRDELETEOBJECT::execute()**, **EMF::EMRCREATEPEN::execute()**, **EMF::EMREXTCREATEPEN::execute()**, **EMF::EMRCREATEBRUSHINDIRECT::execute()**, and **EMF::EMREXTCREATEFONTINDIRECTW::execute()**.

### ::FILE\* EMF::METAFILEDEVICECONTEXT::fp

If it is a file-based metafile, then this pointer is not null.

### std::vector\< bool \> EMF::METAFILEDEVICECONTEXT::handles

For compatibility, it appears that metafile handles are reused as objects are deleted. Attempt to emulate that behavior with a bit vector of used metafile handles.

Referenced by **clearHandle()**, and **nextHandle()**.

### ENHMETAHEADER\* EMF::METAFILEDEVICECONTEXT::header

Serves double duty as the physical device description.

Referenced by **appendHandle()**, **appendRecord()**, **mergePoint()**, and **nextHandle()**.

### std::vector\< EMF::METARECORD\* \> EMF::METAFILEDEVICECONTEXT::records

All of the metafile records are stored in memory.

Referenced by **appendHandle()**, **appendRecord()**, **deleteMetafile()**, and **~METAFILEDEVICECONTEXT()**.

## Author

Generated automatically by Doxygen for libemf from the source code.
