Solved

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

Posted on 2001-08-21
8
389 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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