|
-
Jul 18th, 2015, 10:48 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] A better way for Print Page dpi awareness
In Printer Priting mode, I have considered the scale of printer vs screen. I expect I will get the same result because I have scaled the size of Text Rectangle. Printer DPI (normal 600) is larger than screen dpi (normal 96), so the ratio is 600/96 = 6.25.
But the text got slight difference on my preview Window and printer Page. The text is being wrapped in difference. Refer to my attachments.
I think the reason is the scale. Theory is OK but...
How to solve my problem or has a better way for Print Page dpi awareness?
Scale :
If bPrintingView then
SetRect rc, Round(rc.Left + 2 ), Round(rc.Top + 1), Round(rc.Right - 2), Round(rc.Bottom - 1)
ElseIf bPrintingMode Then
SetRect rc, Round(rc.Left + 2 * dpiXRatio), Round(rc.Top + 1* dpiYRatio), Round(rc.Right - 2 * dpiXRatio), Round(rc.Bottom - 1* dpiYRatio)
End If
Sample Code:
the hdc in preview window, it is picturebox hdc,otherwise, it is Printer.hdc
Code:
Dim lhDC As Long
lhDC = GetDC(0)
ScreenLogPixelsX = GetDeviceCaps(lhDC, 88) 'Const LOGPIXELSX As Long = 88 Number of pixels per logical inch along the screen width
ScreenLogPixelsY = GetDeviceCaps(lhDC, 90) 'Const LOGPIXELSY As Long = 90 Number of pixels per logical inch along the screen height
ReleaseDC 0, lhDC
'Logical pixels inch in X and Y
Dim DpiX As Long
Dim DpiY As Long
DpiX = GetDeviceCaps(hPrinterDC, 88) 'LOGPIXELSX= 88 (e.g. Sharp AR-5316: 600,Depend on Printer setting)
DpiY = GetDeviceCaps(hPrinterDC, 90) ' LOGPIXELSY = 90 (e.g. Sharp AR-5316: 600,Depend on Printer setting)
Dim dpiXRatio As Single
Dim dpiYRatio As Single
dpiXRatio = DpiX / ScreenLogPixelsX
dpiYRatio = DpiY / ScreenLogPixelsY
If bPrintingView then
SetRect rc, Round(rc.Left + 2 ), Round(rc.Top + 1), Round(rc.Right - 2), Round(rc.Bottom - 1)
ElseIf bPrintingMode Then
SetRect rc, Round(rc.Left + 2 * dpiXRatio), Round(rc.Top + 1* dpiYRatio), Round(rc.Right - 2 * dpiXRatio), Round(rc.Bottom - 1* dpiYRatio)
End If
Dim oFont As Std_Font
Dim hFont as Long, hOldFont as Long
Dim wFormat As Long
wFormat = &H12810
Set oFont = m_oFont
hFont= CreateFont(-pMulDiv(oFont.Size, GetDeviceCaps(hdc, 90), 72!), 0, 0, 0, IIf(oFont.Bold, 700, 400), _
IIf(oFont.Italic, 1, 0), IIf(oFont.Underline, 1, 0), IIf(oFont.Strikethrough, 1, 0), 1, 0, 0, 3, 48, oFont.Name)
Set oFont = Nothing
hOldFont= SelectObject(hdc, hFont)
DrawTextEx hdc, Text, rc, wFormat
SelectObject hdc, hOldFont
DeleteObject hFont
Last edited by Jonney; Jul 18th, 2015 at 11:19 PM.
Tags for this Thread
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
|