#include "wx/mac/uma.h"
#include "wx/mac/private/print.h"
+#include "wx/graphics.h"
IMPLEMENT_CLASS(wxPrinterDC, wxDC)
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()
kPMGraphicsContextCoreGraphics,
(void**) &pageContext );
#endif
- dc->MacSetCGContext(pageContext) ;
#else
m_err = PMSessionGetGraphicsContext(native->m_macPrintSession,
kPMGraphicsContextQuickdraw,
#if wxMAC_USE_CORE_GRAPHICS
PMRect paperRect ;
PMGetAdjustedPaperRect( native->m_macPageFormat , &paperRect ) ;
- CGContextTranslateCTM( pageContext , -paperRect.left , -paperRect.top + ( rPage.bottom - rPage.top ) ) ;
+ // make sure (0,0) is at the upper left of the printable area (wx conventions)
+ // Core Graphics initially has the lower left of the paper as 0,0
+ CGContextTranslateCTM( pageContext , -paperRect.left , paperRect.bottom ) ;
CGContextScaleCTM( pageContext , 1 , -1 ) ;
- CGContextSaveGState( pageContext ) ;
#else
dc->m_macLocalOrigin.x = (int) rPage.left;
dc->m_macLocalOrigin.y = (int) rPage.top;
// since this is a non-critical error, we set the flag back
m_err = noErr ;
}
+#if wxMAC_USE_CORE_GRAPHICS
+ dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( pageContext ) );
+#endif
}
void wxMacCarbonPrinterDC::EndPage( wxPrinterDC* dc )
{
PMSessionEndDocument(native->m_macPrintSession);
}
+#if wxMAC_USE_CORE_GRAPHICS
+ // the cg context we got when starting the page isn't valid anymore, so replace it
+ dc->SetGraphicsContext( wxGraphicsContext::Create() );
+#endif
}
void wxMacCarbonPrinterDC::GetSize( int *w , int *h) const
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() ;
+ // we need at least a measuring context because people start measuring before a page
+ // gets printed at all
+ SetGraphicsContext( wxGraphicsContext::Create() );
#endif
}
}
wxPrinterDC::~wxPrinterDC(void)
{
-#if wxMAC_USE_CORE_GRAPHICS
- // this context was borrowed
- ((wxMacCGContext*)(m_graphicContext))->SetNativeContext( NULL ) ;
-#endif
delete m_nativePrinterDC ;
}
-#if wxMAC_USE_CORE_GRAPHICS
-void wxPrinterDC::MacSetCGContext( void * cg )
-{
- ((wxMacCGContext*)(m_graphicContext))->SetNativeContext( (CGContextRef) cg ) ;
- m_graphicContext->SetPen( m_pen ) ;
- m_graphicContext->SetBrush( m_brush ) ;
-}
-#endif
bool wxPrinterDC::StartDoc( const wxString& message )
{
wxASSERT_MSG( Ok() , wxT("Called wxPrinterDC::StartDoc from an invalid object") ) ;
}
}
+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 )