+ {
+ papersize = data.GetPaperSize();
+ }
+
+ if ( papersize != wxDefaultSize )
+ {
+ papersize.x = (wxInt32) (papersize.x * mm2pt);
+ papersize.y = (wxInt32) (papersize.y * mm2pt);
+
+ double height, width;
+ PMPaperGetHeight(m_macPaper, &height);
+ PMPaperGetWidth(m_macPaper, &width);
+
+ if ( fabs( width - papersize.x ) >= 5 ||
+ fabs( height - papersize.y ) >= 5 )
+ {
+ // we have to change the current paper
+ CFArrayRef paperlist = 0 ;
+ if ( PMPrinterGetPaperList( printer, &paperlist ) == noErr )
+ {
+ PMPaper bestPaper = kPMNoData ;
+ CFIndex top = CFArrayGetCount(paperlist);
+ for ( CFIndex i = 0 ; i < top ; ++ i )
+ {
+ PMPaper paper = (PMPaper) CFArrayGetValueAtIndex( paperlist, i );
+ PMPaperGetHeight(paper, &height);
+ PMPaperGetWidth(paper, &width);
+ if ( fabs( width - papersize.x ) < 5 &&
+ fabs( height - papersize.y ) < 5 )
+ {
+ // TODO test for duplicate hits and use additional
+ // criteria for best match
+ bestPaper = paper;
+ }
+ }
+ PMPaper paper = kPMNoData;
+ if ( bestPaper == kPMNoData )
+ {
+ const PMPaperMargins margins = { 0.0, 0.0, 0.0, 0.0 };
+ wxString id, name(wxT("Custom paper"));
+ id.Printf(wxT("wxPaperCustom%dx%d"), papersize.x, papersize.y);
+
+ PMPaperCreateCustom(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ),
+ papersize.x, papersize.y, &margins, &paper);
+ }
+ if ( bestPaper != kPMNoData )
+ {
+ PMPageFormat pageFormat;
+ PMCreatePageFormatWithPMPaper(&pageFormat, bestPaper);
+ PMCopyPageFormat( pageFormat, m_macPageFormat );
+ PMRelease(pageFormat);
+ PMGetPageFormatPaper(m_macPageFormat, &m_macPaper);
+ }
+ PMRelease(paper);
+ }
+ }
+ }
+
+ PMSetCopies( m_macPrintSettings , data.GetNoCopies() , false ) ;
+ PMSetCollate(m_macPrintSettings, data.GetCollate());
+ if ( data.IsOrientationReversed() )
+ PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
+ kPMReverseLandscape : kPMReversePortrait , false ) ;
+ else
+ PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
+ kPMLandscape : kPMPortrait , false ) ;