Solved

Urgent: Using DrawText() to send text to printer. Font size appears strange.

Posted on 2001-08-21
8
373 Views
Last Modified: 2013-12-03
Hi,
I am using Win 95, and I have set font size to very large (200%, using Display Properties dialog and choose Customize). With size 8 specify for text to draw on screen, the text appears large, which is expected. However, when printing to the printer (I assume that printer knows nothing about how the font size is set for the screen), the text also appears large, which I think is not correct.

The details following will explain what I have done to print the text to printer. I appreciate any help.

After specifying size 8 for hPrinterDC, as in following:
HGDIOBJ saveFont = SelectObject(hPrinterDC,
                   (HGDIOBJ)font.GetObject);
                   //font contains the font size
and looking at the return value from DrawText, I realize that textheight is 13, as in the following code:
int textheight = DrawText(hPrinterDC, str, length, &lpDCRect, just);

Please explain to me what is the idea behind this? In other words, how is this return value related to the value that we specify (size 8). Thanks.

0
Comment
Question by:Thuy
  • 3
  • 3
  • 2
8 Comments
 
LVL 9

Expert Comment

by:BeyondWu
ID: 6412023
Please give the DPI of printerDC
0
 

Author Comment

by:Thuy
ID: 6414714
Thanks for your response. I will go get the DPI for the printer, but could you please explain to me how this helps since the problem occurs despite of any printer I am using? Thanks.

0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 6416044
The return value "textheight" depend on DC's DPI and the font size.So you should tell me how you create your font?
"size 8" is logical size or physical size?
Get me the snippet.
0
 
LVL 9

Expert Comment

by:Pacman
ID: 6416494
what is "font" ?
Assuming this is MFC and a CFont instance.
How did you create the font ?
Could you post the code?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Thuy
ID: 6418769
BeyondWu and Pacman,
Thanks for your responses.


font is created using CreateFont as in following:
::CreateFont(-MulDiv(8,
                     GetDeviceCaps(hPrinterDC,  
                                   LOGPIXELSY),
                     72),
          0,//Best fit width
          0,//No escapement
          0,//No Orientation
          weight ,                                    italicStyle,
          FALSE, //No underline
          FALSE, //No strikeout
          GetTextCharset(hDC),
          OUT_DEFAULT_PRECIS,                         CLIP_DEFAULT_PRECIS,
          DEFAULT_QUALITY,
          FF_DONTCARE,
          name);

So, 8 is point size (I would say logical).

Also, GetDeviceCaps(hDC, LOGPIXELSX) and GetDeviceCaps(hDC, LOGPIXELSY) both return 600 pixels per (logical) inch.

I appreciate any explanation, or correction, etc.

0
 
LVL 9

Accepted Solution

by:
BeyondWu earned 100 total points
ID: 6420797
First of all, maybe you make some mistake in your code.
Because for a 8 point size font and a 600 DPI DC, you can't get the textheight 13. It's must be 96 DPI. It's means maybe you confuse the printerDC with ScreenDC.

Here is the formula:
FontHeight = (Point size of font)*DPI/72;
StringHeight = FontHeight + tmInternalLeading;
you can use,
TEXTMETRIC txtmtric;
GetTextMetrics(pDC->m_hDC, &txtmtric);
to get the txtmtric.tmInternalLeading;

Search "String Widths and Heights" in MSDN.

So for your case:
the textheight wich drawtext will return is:
textheight = 8*600/72+txtmtric.tmInternalLeading;
           = 67 + 9 = 76;
If for 96 DPI;
textheight = 8*96/72+txtmtric.tmInternalLeading;
           = 11 + 2 = 13;
Good Luck.
0
 
LVL 9

Expert Comment

by:Pacman
ID: 6420890
instead of CreateFont() you can use CreatePointFont().
Then you don't have to care about formulas.
You've only to pass the size of the font in 1/10 points.
for example 240 means 24 point. Further you pass the DC and let the function do the math.
0
 

Author Comment

by:Thuy
ID: 6422758
BeyondWu and Pacman,
Thanks for all of your answers. They all clarify the questions I have.

Regards,
Thuy
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now