| Herd Software Development
|=
DaVinci Graphics Library
|==
DaVinci Documentation Home Search Order


The METARESOLUTION structure

The METARESOLUTION suffix contains resolution information for Windows metafiles, specifically the size of the image in millimeters and the ratio of width to height.

Unfortunately, these specifications are not stored in a metafile’s HMETAFILE and must be managed separately by the application. The standard .WMF file format includes a small header which contains this data in its METARESOLUTION structure.

Enhanced metafiles used within 16 bit Windows applications do not need this structure since the application can retrieve size and aspect ratio using the GetEnhMetaFileHeader API function.

The METARESOLUTION structure is defined in the DAVINCI.H header file. If the data returned from import is in metafile format, the companion METARESOLUTION structure will be filled with information about the size and the aspect ratio (the ratio of width to height when the image is displayed).
typedef struct 
{
	RECT	bbox;
	WORD	inch;
	char	reserved[2];
} METARESOLUTION, FAR *LPMETARESOLUTION;

METARESOLUTION structure has the following members:

Field Type Description
bbox RECT Specifies the coordinates of the smallest rectangle that encloses the picture. The coordinates are listed in metafile units as defined by the inch member.
Inch WORD Specifies the number of metafile units to the inch. This conversion index is required by the bbox member. To avoid numeric overflow, this value should be less than 1,440. Most applications use 576 or 1,000.
Reserved Char[2] Reserved for future use; this member is currently used to insure that METARESOLUTION’s structure length is neutral to compiler alignment settings.

Remarks

Metafiles which will be exchanged between applications should always use the MM_ANISOTROPIC scaling mode and define the size of the logical coordinate system using SetWindowExtEx and/or SetWindowOrgEx.

The bbox member of the METARESOLUTION structure usually contains the same specifications as the specifications in SetWindowExtEx and SetWindowOrgEx, and is calculated as a RECT type.

Conversions

Calculating METARESOLUTION in pixels

Before playing metafiles, the application must use SetViewportExtEx and SetViewportOrgEx to determine the size of the display area in the target DC. The specifications in the METARESOLUTION structure must be combined with the resolution of the target DC to compute the number of pixels required to display the image in the target DC. Theoretically, the METARESOLUTION structure defines both the sizing and positioning of the metafile. In practice, the positioning information is usually ignored.

Example: Printing a metafile
LPMETARESOLUTION   lpmr;
HDC                hPrinterDC;
RECT               rcPrinter;
POINT              PrinterPixelPerInch;
PrinterPixelPerInch.x = GetDeviceCaps(hPrinterDC, LOGPIXELSX);
PrinterPixelPerInch.y = GetDeviceCaps(hPrinterDC, LOGPIXELSY);
rcPrinter.left   = MulDiv( PrinterPixelPerInch.x, lpmr->bbox.left  , lpmr->inch);
rcPrinter.top    = MulDiv( PrinterPixelPerInch.y, lpmr->bbox.top   , lpmr->inch);
rcPrinter.right  = MulDiv( PrinterPixelPerInch.x, lpmr->bbox.right , lpmr->inch);
rcPrinter.bottom = MulDiv( PrinterPixelPerInch.y, lpmr->bbox.bottom, lpmr->inch);
SetMapMode(hPrinterDC, MM_ANISOTROPIC);
SetViewportExtEx(hPrinterDC, rcPrinter.right-rcPrinter.left, rcPrinter.bottom-rcPrinter.top, NULL);
SetViewportOrgEx(hPrinterDC, rcPrinter.left                , rcPrinter.top                 , NULL);

Calculating METARESOLUTION in tenths of a millimeter (HIMETRIC)

The resolution specifications in the METARESOLUTION structure are defined in pixels per inch. Be sure to calculate accurately, using a conversion ratio of one inch to 25.4 millimetres, when converting to or from metric values.

Example: Conversion from tenths of millimetres to inches
SIZE          size10mm;
size10mm.cx = MulDiv( lpmr->bbox.right-lpmr->bbox.left, 254, lpmr->inch);
size10mm.cy = MulDiv( lpmr->bbox.bottom-lpmr->bbox.top, 254, lpmr->inch);