From 40fcf546f6168f51c070d4ded3c40a75c0780fe8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sun, 21 Sep 2008 09:35:49 +0000 Subject: [PATCH] added wxGetDisplayPPI() convenience function and wxPrintout::SetPPI*() overloads accepting single wxSize argument git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55761 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gdicmn.h | 1 + include/wx/prntbase.h | 2 ++ interface/wx/gdicmn.h | 12 ++++++++++++ src/common/gdicmn.cpp | 9 +++++++++ src/gtk/gnome/gprint.cpp | 12 ++---------- src/gtk/print.cpp | 12 ++---------- 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index fc3b079658..59c52cd1bb 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -819,6 +819,7 @@ extern void WXDLLIMPEXP_CORE wxDisplaySize(int *width, int *height); extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySize(); extern void WXDLLIMPEXP_CORE wxDisplaySizeMM(int *width, int *height); extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySizeMM(); +extern wxSize WXDLLIMPEXP_CORE wxGetDisplayPPI(); // Get position and size of the display workarea extern void WXDLLIMPEXP_CORE wxClientDisplayRect(int *x, int *y, int *width, int *height); diff --git a/include/wx/prntbase.h b/include/wx/prntbase.h index 81e32415b5..a613f6cdef 100644 --- a/include/wx/prntbase.h +++ b/include/wx/prntbase.h @@ -284,8 +284,10 @@ public: void GetPageSizeMM(int *w, int *h) const { *w = m_pageWidthMM; *h = m_pageHeightMM; } void SetPPIScreen(int x, int y) { m_PPIScreenX = x; m_PPIScreenY = y; } + void SetPPIScreen(const wxSize& ppi) { SetPPIScreen(ppi.x, ppi.y); } void GetPPIScreen(int *x, int *y) const { *x = m_PPIScreenX; *y = m_PPIScreenY; } void SetPPIPrinter(int x, int y) { m_PPIPrinterX = x; m_PPIPrinterY = y; } + void SetPPIPrinter(const wxSize& ppi) { SetPPIPrinter(ppi.x, ppi.y); } void GetPPIPrinter(int *x, int *y) const { *x = m_PPIPrinterX; *y = m_PPIPrinterY; } void SetPaperRectPixels(const wxRect& paperRectPixels) { m_paperRectPixels = paperRectPixels; } diff --git a/interface/wx/gdicmn.h b/interface/wx/gdicmn.h index b5fb341b21..fb9d647fab 100644 --- a/interface/wx/gdicmn.h +++ b/interface/wx/gdicmn.h @@ -852,6 +852,18 @@ void wxClientDisplayRect(int* x, int* y, int* width, int* height); wxRect wxGetClientDisplayRect(); //@} +/** @ingroup group_funcmacro_gdi */ +//@{ +/** + Returns the display resolution in pixels per inch. + + @header{wx/gdicmn.h} + + @since 2.9.0 +*/ +wxSize wxGetDisplayPPI(); +//@} + /** @ingroup group_funcmacro_gdi */ //@{ /** diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp index a79f31aa2c..f56aad7d4c 100644 --- a/src/common/gdicmn.cpp +++ b/src/common/gdicmn.cpp @@ -880,6 +880,15 @@ wxSize wxGetDisplaySizeMM() return wxSize(x, y); } +wxSize wxGetDisplayPPI() +{ + const wxSize pixels = wxGetDisplaySize(); + const wxSize mm = wxGetDisplaySizeMM(); + + return wxSize((pixels.x * 25.4) / mm.x, + (pixels.y * 25.4) / mm.y); +} + wxResourceCache::~wxResourceCache () { wxList::compatibility_iterator node = GetFirst (); diff --git a/src/gtk/gnome/gprint.cpp b/src/gtk/gnome/gprint.cpp index aa93c96e64..b8b8086cb9 100644 --- a/src/gtk/gnome/gprint.cpp +++ b/src/gtk/gnome/gprint.cpp @@ -872,11 +872,7 @@ bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) return false; } - wxSize ScreenPixels = wxGetDisplaySize(); - wxSize ScreenMM = wxGetDisplaySizeMM(); - - printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), - (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); + printout->SetPPIScreen(wxGetDisplayPPI()); printout->SetPPIPrinter( dc->GetResolution(), dc->GetResolution() ); @@ -2099,12 +2095,8 @@ void wxGnomePrintPreview::DetermineScaling() if (paper) { - wxSize ScreenPixels = wxGetDisplaySize(); - wxSize ScreenMM = wxGetDisplaySizeMM(); + m_previewPrintout->SetPPIScreen(wxGetDisplayPPI()); - m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), - (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); - int resolution = DPI; m_previewPrintout->SetPPIPrinter( resolution, resolution ); diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index c275c56e09..62c47203f5 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -926,11 +926,8 @@ void wxGtkPrinter::BeginPrint(wxPrintout *printout, GtkPrintOperation *operation } return; } - wxSize ScreenPixels = wxGetDisplaySize(); - wxSize ScreenMM = wxGetDisplaySizeMM(); - printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), - (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); + printout->SetPPIScreen(wxGetDisplayPPI()); printout->SetPPIPrinter( printDC->GetResolution(), printDC->GetResolution() ); @@ -2366,12 +2363,7 @@ void wxGtkPrintPreview::DetermineScaling() if (paper) { - wxSize ScreenPixels = wxGetDisplaySize(); - wxSize ScreenMM = wxGetDisplaySizeMM(); - - m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), - (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); - + m_previewPrintout->SetPPIScreen(wxGetDisplayPPI()); m_previewPrintout->SetPPIPrinter( m_resolution, m_resolution ); // Get width and height in points (1/72th of an inch) -- 2.45.2