+ // 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);
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+ if ( PMPaperCreateCustom != NULL)
+ {
+ PMPaperCreateCustom(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ),
+ papersize.x, papersize.y, &margins, &paper);
+ }
+#endif
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
+ if ( paper == kPMNoData )
+ {
+ PMPaperCreate(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ),
+ papersize.x, papersize.y, &margins, &paper);
+ }
+#endif
+ }
+ if ( bestPaper != kPMNoData )
+ {
+ PMPageFormat pageFormat;
+ PMCreatePageFormatWithPMPaper(&pageFormat, bestPaper);
+ PMCopyPageFormat( pageFormat, m_macPageFormat );
+ PMRelease(pageFormat);
+ PMGetPageFormatPaper(m_macPageFormat, &m_macPaper);
+ }
+ PMRelease(paper);
+ }