0

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 :-)

user1292456
  • 778
  • 4
  • 12
John Trinder
  • 127
  • 4
  • I omitted to say that I know the graphics are vectors, but what I'm after is a starting size. MS Word and Inkscape are able to start with the correct size, but I can't fathom how they do it! – John Trinder Dec 07 '22 at 13:17

3 Answers3

0

Think I sussed it: you use the records:

EMR_SETVIEWPORTEXTEX - device units

EMR_SETVIEWPORTORGEX - (ditto)

EMR_SETWINDOWEXTEX - logical units

EMR_SETWINDOWORGEX - (ditto)

EMR_SETWORLDTRANSFORM

John Trinder
  • 127
  • 4
  • the bounds calculation for rendering is something, which still doesn't work for all of our corpus files, but for practical application, you might find some hints in [this implementation](http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java?view=markup#l216). It also depends if you limit/scale the rendering canvas beforehand as POI does, or you allow scaling modifications to the device context to be applied to already rendered shapes. – kiwiwings Dec 12 '22 at 09:30
0

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.

Ouroborus
  • 16,237
  • 4
  • 39
  • 62
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 27 '22 at 04:49
0

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).

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459