mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-23 06:33:59 +08:00
Add wxGetDPIofHDC() helper function and use it in wxMSW code
No real changes, just replace several pairs of calls to GetDeviceCaps() with a single helper function call.
This commit is contained in:
@@ -471,6 +471,13 @@ private:
|
||||
wxDECLARE_NO_COPY_CLASS(MemoryHDC);
|
||||
};
|
||||
|
||||
// Helper function returning the resolution of the given HDC.
|
||||
inline wxSize wxGetDPIofHDC(HDC hdc)
|
||||
{
|
||||
return wxSize(::GetDeviceCaps(hdc, LOGPIXELSX),
|
||||
::GetDeviceCaps(hdc, LOGPIXELSY));
|
||||
}
|
||||
|
||||
// a class which selects a GDI object into a DC in its ctor and deselects in
|
||||
// dtor
|
||||
class SelectInHDC
|
||||
|
||||
+1
-2
@@ -2648,8 +2648,7 @@ wxSize wxMSWDCImpl::GetPPI() const
|
||||
|
||||
if ( !ppi.x || !ppi.y )
|
||||
{
|
||||
ppi.x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX);
|
||||
ppi.y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY);
|
||||
ppi = wxGetDPIofHDC(GetHdc());
|
||||
}
|
||||
|
||||
return ppi;
|
||||
|
||||
@@ -2545,11 +2545,11 @@ wxGDIPlusPrintingContext::wxGDIPlusPrintingContext( wxGraphicsRenderer* renderer
|
||||
void wxGDIPlusPrintingContext::GetDPI(wxDouble* dpiX, wxDouble* dpiY) const
|
||||
{
|
||||
// override to use same scaling as wxWindowsPrintPreview::DetermineScaling
|
||||
ScreenHDC hdc;
|
||||
const wxSize dpi = wxGetDPIofHDC(ScreenHDC());
|
||||
if ( dpiX )
|
||||
*dpiX = ::GetDeviceCaps(hdc, LOGPIXELSX);
|
||||
*dpiX = dpi.x;
|
||||
if ( dpiY )
|
||||
*dpiY = ::GetDeviceCaps(hdc, LOGPIXELSY);
|
||||
*dpiY = dpi.y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -5316,13 +5316,11 @@ wxGraphicsFont wxD2DRenderer::CreateFont(
|
||||
{
|
||||
// Use the same DPI as wxFont will use in SetPixelSize, so these cancel
|
||||
// each other out and we are left with the actual pixel size.
|
||||
ScreenHDC hdc;
|
||||
wxRealPoint dpi(::GetDeviceCaps(hdc, LOGPIXELSX),
|
||||
::GetDeviceCaps(hdc, LOGPIXELSY));
|
||||
const wxSize dpi = wxGetDPIofHDC(ScreenHDC());
|
||||
|
||||
return CreateFontAtDPI(
|
||||
wxFontInfo(wxSize(sizeInPixels, sizeInPixels)).AllFlags(flags).FaceName(facename),
|
||||
dpi, col);
|
||||
wxRealPoint(dpi.x, dpi.y), col);
|
||||
}
|
||||
|
||||
wxGraphicsFont wxD2DRenderer::CreateFontAtDPI(const wxFont& font,
|
||||
|
||||
+3
-13
@@ -157,23 +157,13 @@ wxDEFINE_EVENT( wxEVT_ACTIVEX, wxActiveXEvent );
|
||||
|
||||
static void PixelsToHimetric(SIZEL &sz)
|
||||
{
|
||||
static int logX = 0;
|
||||
static int logY = 0;
|
||||
|
||||
if (logY == 0)
|
||||
{
|
||||
// initaliase
|
||||
HDC dc = GetDC(NULL);
|
||||
logX = GetDeviceCaps(dc, LOGPIXELSX);
|
||||
logY = GetDeviceCaps(dc, LOGPIXELSY);
|
||||
ReleaseDC(NULL, dc);
|
||||
}
|
||||
static const wxSize logSz = wxGetDPIofHDC(ScreenHDC());
|
||||
|
||||
#define HIMETRIC_INCH 2540
|
||||
#define CONVERT(x, logpixels) wxMulDivInt32(HIMETRIC_INCH, (x), (logpixels))
|
||||
|
||||
sz.cx = CONVERT(sz.cx, logX);
|
||||
sz.cy = CONVERT(sz.cy, logY);
|
||||
sz.cx = CONVERT(sz.cx, logSz.x);
|
||||
sz.cy = CONVERT(sz.cy, logSz.y);
|
||||
|
||||
#undef CONVERT
|
||||
#undef HIMETRIC_INCH
|
||||
|
||||
+10
-15
@@ -310,10 +310,8 @@ bool wxWindowsPrintPreview::Print(bool interactive)
|
||||
|
||||
void wxWindowsPrintPreview::DetermineScaling()
|
||||
{
|
||||
ScreenHDC dc;
|
||||
int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX);
|
||||
int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY);
|
||||
m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY);
|
||||
const wxSize logPPIScreen = wxGetDPIofHDC(ScreenHDC());
|
||||
m_previewPrintout->SetPPIScreen(logPPIScreen);
|
||||
|
||||
// Get a device context for the currently selected printer
|
||||
wxPrinterDC printerDC(m_printDialogData.GetPrintData());
|
||||
@@ -322,8 +320,7 @@ void wxWindowsPrintPreview::DetermineScaling()
|
||||
int printerHeightMM;
|
||||
int printerXRes;
|
||||
int printerYRes;
|
||||
int logPPIPrinterX;
|
||||
int logPPIPrinterY;
|
||||
wxSize logPPIPrinter;
|
||||
|
||||
wxRect paperRect;
|
||||
|
||||
@@ -335,13 +332,12 @@ void wxWindowsPrintPreview::DetermineScaling()
|
||||
printerHeightMM = ::GetDeviceCaps(hdc, VERTSIZE);
|
||||
printerXRes = ::GetDeviceCaps(hdc, HORZRES);
|
||||
printerYRes = ::GetDeviceCaps(hdc, VERTRES);
|
||||
logPPIPrinterX = ::GetDeviceCaps(hdc, LOGPIXELSX);
|
||||
logPPIPrinterY = ::GetDeviceCaps(hdc, LOGPIXELSY);
|
||||
logPPIPrinter = wxGetDPIofHDC(hdc);
|
||||
|
||||
paperRect = printerDC.GetPaperRect();
|
||||
|
||||
if ( logPPIPrinterX == 0 ||
|
||||
logPPIPrinterY == 0 ||
|
||||
if ( logPPIPrinter.x == 0 ||
|
||||
logPPIPrinter.y == 0 ||
|
||||
printerWidthMM == 0 ||
|
||||
printerHeightMM == 0 )
|
||||
{
|
||||
@@ -355,8 +351,7 @@ void wxWindowsPrintPreview::DetermineScaling()
|
||||
printerHeightMM = 250;
|
||||
printerXRes = 1500;
|
||||
printerYRes = 2500;
|
||||
logPPIPrinterX = 600;
|
||||
logPPIPrinterY = 600;
|
||||
logPPIPrinter = wxSize(600, 600);
|
||||
|
||||
paperRect = wxRect(0, 0, printerXRes, printerYRes);
|
||||
m_isOk = false;
|
||||
@@ -366,11 +361,11 @@ void wxWindowsPrintPreview::DetermineScaling()
|
||||
m_previewPrintout->SetPageSizePixels(printerXRes, printerYRes);
|
||||
m_previewPrintout->SetPageSizeMM(printerWidthMM, printerHeightMM);
|
||||
m_previewPrintout->SetPaperRectPixels(paperRect);
|
||||
m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY);
|
||||
m_previewPrintout->SetPPIPrinter(logPPIPrinter);
|
||||
|
||||
// At 100%, the page should look about page-size on the screen.
|
||||
m_previewScaleX = float(logPPIScreenX) / logPPIPrinterX;
|
||||
m_previewScaleY = float(logPPIScreenY) / logPPIPrinterY;
|
||||
m_previewScaleX = float(logPPIScreen.x) / logPPIPrinter.x;
|
||||
m_previewScaleY = float(logPPIScreen.y) / logPPIPrinter.y;
|
||||
}
|
||||
|
||||
#if wxUSE_ENH_METAFILE
|
||||
|
||||
+1
-3
@@ -4878,9 +4878,7 @@ wxSize wxWindowMSW::GetDPI() const
|
||||
|
||||
if ( !dpi.x || !dpi.y )
|
||||
{
|
||||
WindowHDC hdc(hwnd);
|
||||
dpi.x = ::GetDeviceCaps(hdc, LOGPIXELSX);
|
||||
dpi.y = ::GetDeviceCaps(hdc, LOGPIXELSY);
|
||||
dpi = wxGetDPIofHDC(WindowHDC(hwnd));
|
||||
}
|
||||
|
||||
return dpi;
|
||||
|
||||
Reference in New Issue
Block a user