+ bool found = false;
+ CFArrayRef formatList;
+ PMSessionCreatePageFormatList(m_macPrintSession, printer, &formatList);
+ if (formatList)
+ {
+ count = CFArrayGetCount(formatList);
+ for (index = 0; index < count; index++)
+ {
+ PMPageFormat temp = (PMPageFormat)CFArrayGetValueAtIndex(formatList, index);
+ PMRect rPaper;
+ PMGetUnadjustedPaperRect(temp, &rPaper);
+ wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
+ (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ));
+ wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
+ if (((data.GetPaperId() != wxPAPER_NONE) && (id == data.GetPaperId())) ||
+ ((data.GetPaperId() == wxPAPER_NONE) && (sz == data.GetPaperSize())))
+ {
+ PMCopyPageFormat(temp, m_macPageFormat);
+ found = true;
+ break;
+ }
+ }
+ CFRelease(formatList);
+ }
+ if (!found)
+ {
+ PMPaper paper;
+ const PMPaperMargins margins = { 0.0, 0.0, 0.0, 0.0 };
+ wxString id, name(_T("Custom paper"));
+ wxSize sz;
+ double width, height;
+
+ id.Printf(_T("wxPaperCustom%dx%d"), sz.x, sz.y);
+ if (data.GetPaperId() == wxPAPER_NONE)
+ sz = data.GetPaperSize();
+ else
+ sz = wxThePrintPaperDatabase->GetSize(data.GetPaperId());
+ width = ((double)sz.x / 10.0) * mm2pt;
+ height = ((double)sz.y / 10.0) * mm2pt;
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
+ PMPaperCreate(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ), width, height, &margins, &paper);
+#else
+ if (PMPaperCreateCustom(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ), width, height, &margins, &paper) != noErr)
+ paper = NULL;
+#endif
+ if (paper)
+ {
+ PMPageFormat temp;
+ if (PMCreatePageFormatWithPMPaper(&temp, paper) == noErr) {
+ PMCopyPageFormat(temp, m_macPageFormat);
+ PMRelease(temp);
+ }
+ PMRelease(paper);
+ }
+ }
+
+ if ( data.IsOrientationReversed() )
+ PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
+ kPMReverseLandscape : kPMReversePortrait , false ) ;
+ else
+ PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
+ kPMLandscape : kPMPortrait , false ) ;
+