3.1.3 Mapping Modes

When an application pastes a WMF metafile from a clipboard, the application can determine the size of metafile output. For this to work cleanly between applications, be aware of the following:

  • The metafile is responsible for specifying the window part of the mapping mode.

  • The player of the metafile is responsible for the viewport part of the mapping mode.

To perform a simple playback of the metafile, an application can perform the following initialization before processing records.

  1. Set the mapping mode to the mode specified in the METAFILEPICT structure (for more information, see [MSDN-CLIPFORM]).

  2. Convert the horizontal and vertical extents of the viewport to logical units, if necessary (see the following).

  3. Perform scaling computations, if required (see below).

  4. Set the viewport origin according to the desired placement of the metafile.

If the mapping mode in a metafile is MM_ANISOTROPIC or MM_ISOTROPIC, coordinate conversion might be required, as mentioned earlier. If the horizontal and vertical extents of the image are given in MM_HIMETRIC coordinates, they are converted to pixel values. Before playback, the application sets the viewport origin to the desired location, sets the mapping mode to the specified mode, and computes the viewport extents. If no extents are specified in the METAFILEPICT structure, the application performing the playback can arbitrarily choose a size.

Thus, scaling a metafile that uses the MM_ANISOTROPIC or MM_ISOTROPIC mapping modes can be performed by changing the viewport extents to the appropriate dimensions before playback. The viewport defines the size of the metafile image.

To scale metafiles that use any other mapping mode, first convert the metafile to use MM_ANISOTROPIC mapping mode. The metafile itself does not need to change, but the mapping mode setup does need to be correct before beginning the playback.