Problems with EMF output using DrawCurrentPage() in 4.0

The PDF Creator enables you to create secure PDF documents and to view, print and process existing PDF documents.
If you have any questions about the installation and usage of the PDF Creator please post them here.
Post Reply
MaxMotovilov
Posts: 8
Joined: Thu Sep 09 2004

Problems with EMF output using DrawCurrentPage() in 4.0

Post by MaxMotovilov » Tue May 25 2010

I have been using the following wrapper code for the DrawCurrentPage() API for a long time (definitely with versions 2.x and 3.x):

==================================
::SetGraphicsMode( dc, GM_ADVANCED );

XFORM twips_xform = {
FLOAT(inches_xform[0] / 1440.0), FLOAT(inches_xform[1] / 1440.0), FLOAT(inches_xform[3] / 1440.0),
FLOAT(inches_xform[4] / 1440.0), FLOAT(inches_xform[2]), FLOAT(inches_xform[5])
};

BOOL s = ::SetWorldTransform( dc, &twips_xform );

pdf_creator_control->DrawCurrentPage( reinterpret_cast<long>(dc), FALSE );
==================================

where inches_xform is all that the external code needs to deal with when setting up the view. This code is known to work properly with both window paint DCs (from BeginPaint()) and the EMF DCs (from CreateEnhMetafile()) when used with the PDF Creator prior to version 4. In version 4 things seem to have changed:

- The code still works properly with paint/screen DCs, both when the transformation specifies translation and scaling only and when it includes 90-degree rotations.

- With the EMF DC and scaling/translation matrix, the output comes out significantly smaller than expected. Interestingly enough, the size of the output is NOT LINEAR in respect to the scaling coefficient: with the code above unchanged, it looks about 16x smaller than the screen version but multiplying every coefficient by about 3.8 brings it close to expected size. In fact, I am inclined to think that the linear scale is proportional to the square of the coefficients (or to the determinant of the matrix) and 1:1 correspondence is achieved by changing the scaling coefficient in the code above from 1440 to 100 * sqrt(14.4) -- however little sense it makes.

- With the EMF DC and a rotational matrix, not only the scale is out of whack but the rotational angle seems to be twice the one specified -- a 90-degree matrix rotates by 180 degrees. Which, come to think of it, dovetails nicely with the scaling issue -- the matrix seems to be applied twice in a row!

I can think of some workarounds for the issue -- such as rendering into a non-rotated EMF DC and then playing it back into a rotated one, as well as forcing the expected scale. However, since this issue seems to have been introduced by the latest version and things still work as expected with screen DCs, I was hoping that the product owners may suggest a simpler approach.

Regards,
...Max...

Post Reply