+ Init();
+#if wxMAC_USE_CORE_GRAPHICS
+ if ( !filename.empty() )
+ {
+ wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxMacCFStringHolder(filename)));
+ CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
+ wxCFRef<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false));
+ m_pdfDoc.reset(CGPDFDocumentCreateWithURL(url));
+ }
+#else
+ wxASSERT_MSG( filename.empty(), wxT("no file-based metafile support yet") );
+ m_metafile = NULL;
+#endif
+}
+
+
+wxMetafileRefData::wxMetafileRefData( int width, int height)
+{
+ Init();
+
+ m_width = width;
+ m_height = height;
+#if wxMAC_USE_CORE_GRAPHICS
+ CGRect r = CGRectMake( 0 , 0 , width , height );
+
+ CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
+ m_data.reset(data);
+ CGDataConsumerRef dataConsumer = UMACGDataConsumerCreateWithCFData(data);
+ m_context = CGPDFContextCreate( dataConsumer, (width != 0 && height != 0) ? &r : NULL , NULL );
+ CGDataConsumerRelease( dataConsumer );
+ if ( m_context )
+ {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+ if ( &CGPDFContextBeginPage != NULL )
+ CGPDFContextBeginPage(m_context, NULL);
+ else
+#endif
+ CGContextBeginPage(m_context, &r);
+
+ CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
+
+ CGContextSetFillColorSpace( m_context, genericColorSpace );
+ CGContextSetStrokeColorSpace( m_context, genericColorSpace );
+
+ CGContextTranslateCTM( m_context , 0 , height ) ;
+ CGContextScaleCTM( m_context , 1 , -1 ) ;
+ }
+#else
+ Rect r = { 0, 0, height, width };
+ m_metafile = OpenPicture( &r ) ;
+#endif
+}
+
+wxMetafileRefData::~wxMetafileRefData()
+{
+#if! wxMAC_USE_CORE_GRAPHICS