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
This commit is contained in:
Václav Slavík
2008-09-21 09:35:49 +00:00
parent 0c75b29e1e
commit 40fcf546f6
6 changed files with 28 additions and 20 deletions

View File

@@ -819,6 +819,7 @@ extern void WXDLLIMPEXP_CORE wxDisplaySize(int *width, int *height);
extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySize(); extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySize();
extern void WXDLLIMPEXP_CORE wxDisplaySizeMM(int *width, int *height); extern void WXDLLIMPEXP_CORE wxDisplaySizeMM(int *width, int *height);
extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySizeMM(); extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySizeMM();
extern wxSize WXDLLIMPEXP_CORE wxGetDisplayPPI();
// Get position and size of the display workarea // Get position and size of the display workarea
extern void WXDLLIMPEXP_CORE wxClientDisplayRect(int *x, int *y, int *width, int *height); extern void WXDLLIMPEXP_CORE wxClientDisplayRect(int *x, int *y, int *width, int *height);

View File

@@ -284,8 +284,10 @@ public:
void GetPageSizeMM(int *w, int *h) const { *w = m_pageWidthMM; *h = m_pageHeightMM; } 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(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 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(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 GetPPIPrinter(int *x, int *y) const { *x = m_PPIPrinterX; *y = m_PPIPrinterY; }
void SetPaperRectPixels(const wxRect& paperRectPixels) { m_paperRectPixels = paperRectPixels; } void SetPaperRectPixels(const wxRect& paperRectPixels) { m_paperRectPixels = paperRectPixels; }

View File

@@ -852,6 +852,18 @@ void wxClientDisplayRect(int* x, int* y, int* width, int* height);
wxRect wxGetClientDisplayRect(); 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 */ /** @ingroup group_funcmacro_gdi */
//@{ //@{
/** /**

View File

@@ -880,6 +880,15 @@ wxSize wxGetDisplaySizeMM()
return wxSize(x, y); 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 () wxResourceCache::~wxResourceCache ()
{ {
wxList::compatibility_iterator node = GetFirst (); wxList::compatibility_iterator node = GetFirst ();

View File

@@ -872,11 +872,7 @@ bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
return false; return false;
} }
wxSize ScreenPixels = wxGetDisplaySize(); printout->SetPPIScreen(wxGetDisplayPPI());
wxSize ScreenMM = wxGetDisplaySizeMM();
printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
(int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
printout->SetPPIPrinter( dc->GetResolution(), printout->SetPPIPrinter( dc->GetResolution(),
dc->GetResolution() ); dc->GetResolution() );
@@ -2099,12 +2095,8 @@ void wxGnomePrintPreview::DetermineScaling()
if (paper) if (paper)
{ {
wxSize ScreenPixels = wxGetDisplaySize(); m_previewPrintout->SetPPIScreen(wxGetDisplayPPI());
wxSize ScreenMM = wxGetDisplaySizeMM();
m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
(int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
int resolution = DPI; int resolution = DPI;
m_previewPrintout->SetPPIPrinter( resolution, resolution ); m_previewPrintout->SetPPIPrinter( resolution, resolution );

View File

@@ -926,11 +926,8 @@ void wxGtkPrinter::BeginPrint(wxPrintout *printout, GtkPrintOperation *operation
} }
return; return;
} }
wxSize ScreenPixels = wxGetDisplaySize();
wxSize ScreenMM = wxGetDisplaySizeMM();
printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), printout->SetPPIScreen(wxGetDisplayPPI());
(int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
printout->SetPPIPrinter( printDC->GetResolution(), printout->SetPPIPrinter( printDC->GetResolution(),
printDC->GetResolution() ); printDC->GetResolution() );
@@ -2366,12 +2363,7 @@ void wxGtkPrintPreview::DetermineScaling()
if (paper) if (paper)
{ {
wxSize ScreenPixels = wxGetDisplaySize(); m_previewPrintout->SetPPIScreen(wxGetDisplayPPI());
wxSize ScreenMM = wxGetDisplaySizeMM();
m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
(int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
m_previewPrintout->SetPPIPrinter( m_resolution, m_resolution ); m_previewPrintout->SetPPIPrinter( m_resolution, m_resolution );
// Get width and height in points (1/72th of an inch) // Get width and height in points (1/72th of an inch)