3.1.1.1 EMF Object Table

The EMF object table is an element of the state maintained during EMF metafile playback. It contains data used for managing graphics objects as they are created, activated, used, deactivated, and deleted by the processing of EMF records.

A possible implementation is described by the following elements.

Element name

Type

Set by

EMFObjectArray

EMFObject[]

Object creation record (section 2.3.7)

EMFObject

EMFObject

Object creation record

EMFObjectArray (variable): An array of EMFObject elements. The maximum number of objects is specified in the Handles field of the Header object (section 2.2.9) in an EMF_HEADER record (section 2.3.4.2). The table should be large enough for (Handles + 1) because element zero in the array is reserved.

EMFObject (variable): A graphics object and its associated index.

When a graphics object is created by an object creation record, the record specifies a numerical index. The object can be referenced by its index during metafile processing until the object is deleted. Object indexes start at 1; zero is reserved for references to the metafile itself.

An object manipulation record (section 2.3.8) can use the index of a graphics object to select it into the playback device context. This has the effect of activating the object so that it can be used in graphics operations specified by subsequent metafile records. Until the object is activated, it is not used. Later, if a different object of the same type is activated, the former object is deactivated but not deleted. An object is not deleted until an object manipulation record is processed that deletes it.

Before a graphics object is instantiated and activated, a default stock object (section 2.1.31) for that type is used in graphics operations.

Element name

Type

Set by

GraphicsObjectIndex

UINT32

Object creation record

GraphicsObject

See element description.

Object creation record

GraphicsObjectIndex (4 bytes): An unsigned integer that specifies the index associated with the GraphicsObject, which is used to refer to the object after it is created.

GraphicsObject (variable): One of the following structures.

The following process can be used to manage graphics objects with the EMF object table:

  1. At the start of metafile processing, the EMFObjectArray structure is created.

  2. The EMF object table needs to be large enough to keep track of objects that are explicitly created as well as stock objects. Each element in the object table contains information that indicates whether an object with that index has been created, a way to access the object, and whether the object is currently active.

  3. When a graphics object is created, the element in the EMF object table that corresponds to its index is updated so that it can be accessed later.

  4. When a graphics object is activated, the element in the EMF object table that corresponds to its index is updated. In addition, the element that was activated before is now deactivated.

  5. When a graphics object is deactivated, the element in the EMF object table that corresponds to its index is updated. In addition, the default stock object of that type is now activated.

  6. When a record is encountered that deletes the graphics object, its memory is released, and the EMF object table is updated accordingly. A graphics object can be deleted without first being deactivated. If that happens, the default stock object of that type is now activated.

There are some index values that are reserved:

  • The index zero is reserved; it refers to the EMF metafile itself.

  • Indexes that have the most-significant bit set refer to stock objects.

The object state changes of creation, activation, deactivation, and deletion, require management during playback to achieve the expected results in rendering the image stored in the metafile.