X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4f74e0d132e73250ef422c06175dcf7e4146ec57..2e57368359ab190b5bbad1849d88f298e30723c9:/src/mac/carbon/dcprint.cpp diff --git a/src/mac/carbon/dcprint.cpp b/src/mac/carbon/dcprint.cpp index ce17739428..34af3cc1cb 100644 --- a/src/mac/carbon/dcprint.cpp +++ b/src/mac/carbon/dcprint.cpp @@ -27,6 +27,7 @@ #include "wx/mac/uma.h" #include "wx/mac/private/print.h" +#include "wx/graphics.h" IMPLEMENT_CLASS(wxPrinterDC, wxDC) @@ -94,8 +95,8 @@ wxMacCarbonPrinterDC::wxMacCarbonPrinterDC( wxPrintData* data ) PMPrinterGetOutputResolution( printer, native->m_macPrintSettings, &res) ; #else m_err = PMGetResolution((PMPageFormat) (native->m_macPageFormat), &res); - m_ppi = wxSize(int(res.hRes), int(res.vRes)); #endif + m_ppi = wxSize(int(res.hRes), int(res.vRes)); } wxMacCarbonPrinterDC::~wxMacCarbonPrinterDC() @@ -196,7 +197,6 @@ void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc ) kPMGraphicsContextCoreGraphics, (void**) &pageContext ); #endif - dc->MacSetCGContext(pageContext) ; #else m_err = PMSessionGetGraphicsContext(native->m_macPrintSession, kPMGraphicsContextQuickdraw, @@ -221,7 +221,6 @@ void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc ) PMGetAdjustedPaperRect( native->m_macPageFormat , &paperRect ) ; CGContextTranslateCTM( pageContext , -paperRect.left , -paperRect.top + ( rPage.bottom - rPage.top ) ) ; CGContextScaleCTM( pageContext , 1 , -1 ) ; - CGContextSaveGState( pageContext ) ; #else dc->m_macLocalOrigin.x = (int) rPage.left; dc->m_macLocalOrigin.y = (int) rPage.top; @@ -230,6 +229,9 @@ void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc ) // since this is a non-critical error, we set the flag back m_err = noErr ; } +#if wxMAC_USE_CORE_GRAPHICS + dc->MacSetCGContext(pageContext) ; +#endif } void wxMacCarbonPrinterDC::EndPage( wxPrinterDC* dc ) @@ -244,6 +246,9 @@ void wxMacCarbonPrinterDC::EndPage( wxPrinterDC* dc ) { PMSessionEndDocument(native->m_macPrintSession); } +#if wxMAC_USE_CORE_GRAPHICS + dc->MacSetCGContext(NULL) ; +#endif } void wxMacCarbonPrinterDC::GetSize( int *w , int *h) const @@ -286,8 +291,10 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata) m_mm_to_pix_y = mm2inches * sz.y; } #if wxMAC_USE_CORE_GRAPHICS +/* // the cgContext will only be handed over page by page m_graphicContext = new wxMacCGContext() ; + */ #endif } } @@ -300,8 +307,10 @@ wxSize wxPrinterDC::GetPPI() const wxPrinterDC::~wxPrinterDC(void) { #if wxMAC_USE_CORE_GRAPHICS +/* // this context was borrowed ((wxMacCGContext*)(m_graphicContext))->SetNativeContext( NULL ) ; + */ #endif delete m_nativePrinterDC ; } @@ -309,7 +318,7 @@ wxPrinterDC::~wxPrinterDC(void) #if wxMAC_USE_CORE_GRAPHICS void wxPrinterDC::MacSetCGContext( void * cg ) { - ((wxMacCGContext*)(m_graphicContext))->SetNativeContext( (CGContextRef) cg ) ; + SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) ); m_graphicContext->SetPen( m_pen ) ; m_graphicContext->SetBrush( m_brush ) ; } @@ -354,6 +363,21 @@ void wxPrinterDC::EndDoc(void) } } +wxRect wxPrinterDC::GetPaperRect() +{ + wxCoord w, h; + GetSize(&w, &h); + wxRect pageRect(0, 0, w, h); + wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) m_printData.GetNativeData() ; + OSStatus err = noErr ; + PMRect rPaper; + err = PMGetAdjustedPaperRect(native->m_macPageFormat, &rPaper); + if ( err != noErr ) + return pageRect; + return wxRect(wxCoord(rPaper.left), wxCoord(rPaper.top), + wxCoord(rPaper.right - rPaper.left), wxCoord(rPaper.bottom - rPaper.top)); +} + void wxPrinterDC::StartPage(void) { if ( !m_ok )