Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

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

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
Thuy
Asked:
Thuy
  • 3
  • 3
  • 2
1 Solution
 
BeyondWuCommented:
Please give the DPI of printerDC
0
 
ThuyAuthor Commented:
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
 
BeyondWuCommented:
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
PacmanCommented:
what is "font" ?
Assuming this is MFC and a CFont instance.
How did you create the font ?
Could you post the code?
0
 
ThuyAuthor Commented:
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
 
BeyondWuCommented:
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
 
PacmanCommented:
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
 
ThuyAuthor Commented:
BeyondWu and Pacman,
Thanks for all of your answers. They all clarify the questions I have.

Regards,
Thuy
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now