How do I get the logical to device ratio from an EMF ()Enhanced MetaFile?

101 views Asked by At

I have closely studied the MS documentation on EMF files and from the definitions for the 3 header types I can't see how to convert from logical coords (which the graphics records coords are stored as) to device coords. The header has a Frame part that specifies the page size surrounding (but not necessarily bounding) the composite image in 0.01mm units; and a Bounds part that specifies the actual bounds of the composite image in logical units. And finally there are the Device and Millimeters parts that specify the size of the recording device.

From these there seems no way that calculating the ratio to convert from logical coords to device coords is possible.

I must be missing something simple :-)

3

There are 3 answers

0
TorontoJohn On

After creating your DC (createDC), use getdevicecaps to get the total number of dots (raster lines) available for your DC. Horzres for width, Vertres for height. The dots aren't square. Then after reading your EMF file with getenhmetafile, use getenhmetafileheader to get the header record. You then look at either rclbound or rclframe in the header record.

The second rectangle is a multiple of the first rectangle. For emfs created by powerpoint, the top and left is zero in my experience, so you focus on the bottom and right. The ratio of the two is your aspect ratio. You use that ratio to calculate the rectangle in DC units that has the same aspect ratio as rclbound, but likely adds margins all around so your image doesn't go right to the edge of your device.

That rectangle, with units that fall within the range provide by vertres and horzres is the third argument to the playenhmetafile command where your finish up. In sum, you convert from the EMF logical units to the DC logical units by using vertres and horzres (from your DC) combined with the aspect ratio you calculate (from your EMF).

1
John Trinder On

Think I sussed it: you use the records:

EMR_SETVIEWPORTEXTEX - device units

EMR_SETVIEWPORTORGEX - (ditto)

EMR_SETWINDOWEXTEX - logical units

EMR_SETWINDOWORGEX - (ditto)

EMR_SETWORLDTRANSFORM

1
user20766011 On

Yes, the Bounds header property is specified as the actual bounds of the composite image (in logical units) but, on investigating Inkscape and Adobe Illustrator created emf's, I find that they do not adhere to this.