How to know if I'm printing from a PaintEventArg?

L

Lloyd Dupont

In my (C#) code I have some painting methods using Interop and GDI (win32).
Unfortunately, as you might know, you have to apply some transformation to
your space and fonts if you want to achieve WYSIWIG result with GDI
(as summarized here:
http://msdn.microsoft.com/msdnmag/issues/06/03/TextRendering/default.aspx )

Therefore, if I want to have good WYSIWUG results in my method I need to
know if we are printing or not.
I don't want to reproduce the same blunder as TextRenderer does, I want to
pre-empt it!

Any tips for me to know from the Graphics / HDC that I'm doing a print
operation?
 
B

Bob Powell [MVP]

Generally, for WYSIWYG work I recommend using a real-world measurement
system in the layout of text and graphics. Pixels are too dependent on the
hardware but using Points, Millimeters, Inches or any of the other
measurement systems will render identical results on paper as well as on
screen.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
L

Lloyd Dupont

But how do I real point measurement?

mmhh....
the only thing I could come up with is ...
=== GDI+ ====
e.Graphics.PageUnit = Inch
e.Graphics.ScaleTransform(1000);
=== GDI =====
SetMapMode(hdc, MM_HIENGISH)
============

this way I could achieve equals coordinate...
but I still have problem with font, as described in this article:
http://msdn.microsoft.com/msdnmag/issues/06/03/TextRendering/default.aspx

After this article I was able to fix my problem but I had both to:
- scale the GDI space (if printing) with SetWorldTransform( 1 x Dpi / 100 )
- and scale font size (if printing) by 1 x 100 / 72

could I go around all that someway?
with the transformation I suggested at the top?
I have to test....
 
L

Lloyd Dupont

Hi Bob,

I have a simple sample (in C# & ManagedC++) which should illustrate my
problem...
Would you care to take a look?
 
L

Lloyd Dupont

Do not worry, for I am in the process of writing a device independant
Managed C++ wrapper around HFONT & HDC.

The most difficult problem was the font but let say the various important
call were:
for the Font => GdiFont transformation
SetMapMode(hdc, MM_TEXT);
lfHeight = -MulDiv(font->PointSize, ::GetDeviceCaps(hdc, LOGPIXELSX), 72);
for the coordinate mapping =>
switch(g->PageUnit)
{
case GraphicsUnit.Inch:
mul = 10 * GetDeviceCaps(hdc, LOGPIXELSX);
div = 254;
break;
.........
}
SetWorldTransform()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top