|
-
June 10th, 2005, 08:44 PM
#1
Printing out text to the printer?
I want to print out some text to the printer DC, but when reviewing the page
in PrintPreview, it's in the wrong place. The text is too far down.
I want my text to be roughly 0.5 inches high. I'm assuming 1 inch = 72 points,
so 0.5 inches = 36 points, in MM_TEXT mapping mode.
Code:
INT point_size = 36;
// I create some text using this formula, found in the SDK docs:
LOGFONT lf;
memset( &lf, 0, sizeof(LOGFONT));
// The value 72 is dependent on the mapping mode, MM_TEXT
INT fh = -MulDiv( point_size, pDC->GetDeviceCaps(LOGPIXELSY), 72 );
lf.lfHeight = fh;
// other variables set to default values
CFont myfont;
myfont.CreateFontIndirect(&lf);
// And then draw the text at location (0.5, 10) in inches:
INT ppi_x = pDC->GetDeviceCaps(LOGPIXELSX);
INT ppi_y = pDC->GetDeviceCaps(LOGPIXELSY);
INT x = (INT)(ppi_x * 0.5f);
INT y = (INT)(ppi_y * 10.0f);
// draw it directly to the printer DC
pDC->TextOut( x,y, "Test" );
But in PrintPreview, the text is too far down, past (0.5, 10) inches.
The map mode of the printer DC is set to MM_TEXT.
(LOGPIXELSX,LOGPIXELSY) for the printer DC returns (300,300).
(HORZRES,VERTRES) for the printer DC returns (2400,3074) as I selected
a (8.5 x 11 inch) paper size.
Question is, what is the correct way to print out text to the printer
at a specific location in inches?
Why isn't the text starting exactly at location (0.5, 10) inches?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|