Solved

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

Posted on 2001-08-21
8
378 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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 …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…

776 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