making pdf implementation compile and work under 10.3
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@46350 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -24,19 +24,12 @@
|
|||||||
|
|
||||||
#include "wx/metafile.h"
|
#include "wx/metafile.h"
|
||||||
#include "wx/clipbrd.h"
|
#include "wx/clipbrd.h"
|
||||||
#include "wx/mac/private.h"
|
#include "wx/mac/uma.h"
|
||||||
#include "wx/graphics.h"
|
#include "wx/graphics.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// NB: The new implementation added in 1.34.4.2 uses a number of APIs which
|
|
||||||
// were introduced in Tiger. Unfortunately, this also left the class with
|
|
||||||
// no implementation for Panther+CoreGraphics (which wxPython currently uses).
|
|
||||||
// I've restored compilation for Panther+CoreGraphics but this does little more
|
|
||||||
// than make it compile. It does not show Metafiles and
|
|
||||||
#define USE_CG_METAFILE (wxMAC_USE_CORE_GRAPHICS && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4))
|
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
|
IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
|
IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
|
||||||
|
|
||||||
@@ -45,12 +38,12 @@ IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
|
|||||||
class wxMetafileRefData: public wxGDIRefData
|
class wxMetafileRefData: public wxGDIRefData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
// creates a metafile from memory, assumes ownership
|
// creates a metafile from memory, assumes ownership
|
||||||
wxMetafileRefData(CFDataRef data);
|
wxMetafileRefData(CFDataRef data);
|
||||||
#else
|
#else
|
||||||
// creates a metafile from memory, assumes ownership
|
// creates a metafile from memory, assumes ownership
|
||||||
wxMetafileRefData(PicHandle data);
|
wxMetafileRefData(Handle data);
|
||||||
#endif
|
#endif
|
||||||
// prepares a recording metafile
|
// prepares a recording metafile
|
||||||
wxMetafileRefData( int width, int height);
|
wxMetafileRefData( int width, int height);
|
||||||
@@ -62,8 +55,8 @@ public:
|
|||||||
|
|
||||||
int GetWidth() const { return m_width; }
|
int GetWidth() const { return m_width; }
|
||||||
int GetHeight() const { return m_height; }
|
int GetHeight() const { return m_height; }
|
||||||
|
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
CGPDFDocumentRef GetPDFDocument() const { return m_pdfDoc; }
|
CGPDFDocumentRef GetPDFDocument() const { return m_pdfDoc; }
|
||||||
void UpdateDocumentFromData() ;
|
void UpdateDocumentFromData() ;
|
||||||
|
|
||||||
@@ -75,7 +68,7 @@ public:
|
|||||||
// ends the recording
|
// ends the recording
|
||||||
void Close();
|
void Close();
|
||||||
private:
|
private:
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
wxCFDataRef m_data;
|
wxCFDataRef m_data;
|
||||||
wxCFRef<CGPDFDocumentRef> m_pdfDoc;
|
wxCFRef<CGPDFDocumentRef> m_pdfDoc;
|
||||||
CGContextRef m_context;
|
CGContextRef m_context;
|
||||||
@@ -86,7 +79,7 @@ private:
|
|||||||
int m_height ;
|
int m_height ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if! USE_CG_METAFILE
|
#if! wxMAC_USE_CORE_GRAPHICS
|
||||||
wxMetafileRefData::wxMetafileRefData(PicHandle pict)
|
wxMetafileRefData::wxMetafileRefData(PicHandle pict)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
@@ -109,7 +102,7 @@ wxMetafileRefData::wxMetafileRefData(CFDataRef data) :
|
|||||||
wxMetafileRefData::wxMetafileRefData( const wxString& filename )
|
wxMetafileRefData::wxMetafileRefData( const wxString& filename )
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
if ( !filename.empty() )
|
if ( !filename.empty() )
|
||||||
{
|
{
|
||||||
wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxMacCFStringHolder(filename)));
|
wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxMacCFStringHolder(filename)));
|
||||||
@@ -130,19 +123,21 @@ wxMetafileRefData::wxMetafileRefData( int width, int height)
|
|||||||
|
|
||||||
m_width = width;
|
m_width = width;
|
||||||
m_height = height;
|
m_height = height;
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
CGRect r = CGRectMake( 0 , 0 , width , height );
|
CGRect r = CGRectMake( 0 , 0 , width , height );
|
||||||
|
|
||||||
CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
|
CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
|
||||||
m_data.reset(data);
|
m_data.reset(data);
|
||||||
CGDataConsumerRef dataConsumer = CGDataConsumerCreateWithCFData(data);
|
CGDataConsumerRef dataConsumer = UMACGDataConsumerCreateWithCFData(data);
|
||||||
m_context = CGPDFContextCreate( dataConsumer, (width != 0 && height != 0) ? &r : NULL , NULL );
|
m_context = CGPDFContextCreate( dataConsumer, (width != 0 && height != 0) ? &r : NULL , NULL );
|
||||||
CGDataConsumerRelease( dataConsumer );
|
CGDataConsumerRelease( dataConsumer );
|
||||||
if ( m_context )
|
if ( m_context )
|
||||||
{
|
{
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||||
if ( &CGPDFContextBeginPage != NULL )
|
if ( &CGPDFContextBeginPage != NULL )
|
||||||
CGPDFContextBeginPage(m_context, NULL);
|
CGPDFContextBeginPage(m_context, NULL);
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
CGContextBeginPage(m_context, NULL);
|
CGContextBeginPage(m_context, NULL);
|
||||||
|
|
||||||
CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
|
CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
|
||||||
@@ -161,7 +156,7 @@ wxMetafileRefData::wxMetafileRefData( int width, int height)
|
|||||||
|
|
||||||
wxMetafileRefData::~wxMetafileRefData()
|
wxMetafileRefData::~wxMetafileRefData()
|
||||||
{
|
{
|
||||||
#if! USE_CG_METAFILE
|
#if! wxMAC_USE_CORE_GRAPHICS
|
||||||
if (m_metafile)
|
if (m_metafile)
|
||||||
{
|
{
|
||||||
KillPicture( (PicHandle)m_metafile );
|
KillPicture( (PicHandle)m_metafile );
|
||||||
@@ -172,7 +167,7 @@ wxMetafileRefData::~wxMetafileRefData()
|
|||||||
|
|
||||||
void wxMetafileRefData::Init()
|
void wxMetafileRefData::Init()
|
||||||
{
|
{
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
m_context = NULL;
|
m_context = NULL;
|
||||||
#else
|
#else
|
||||||
m_metafile = NULL;
|
m_metafile = NULL;
|
||||||
@@ -183,10 +178,12 @@ void wxMetafileRefData::Init()
|
|||||||
|
|
||||||
void wxMetafileRefData::Close()
|
void wxMetafileRefData::Close()
|
||||||
{
|
{
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||||
if ( &CGPDFContextEndPage != NULL )
|
if ( &CGPDFContextEndPage != NULL )
|
||||||
CGPDFContextEndPage(m_context);
|
CGPDFContextEndPage(m_context);
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
CGContextEndPage(m_context);
|
CGContextEndPage(m_context);
|
||||||
|
|
||||||
CGContextRelease(m_context);
|
CGContextRelease(m_context);
|
||||||
@@ -198,10 +195,10 @@ void wxMetafileRefData::Close()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
void wxMetafileRefData::UpdateDocumentFromData()
|
void wxMetafileRefData::UpdateDocumentFromData()
|
||||||
{
|
{
|
||||||
wxCFRef<CGDataProviderRef> provider(CGDataProviderCreateWithCFData(m_data));
|
wxCFRef<CGDataProviderRef> provider(UMACGDataProviderCreateWithCFData(m_data));
|
||||||
m_pdfDoc.reset(CGPDFDocumentCreateWithProvider(provider));
|
m_pdfDoc.reset(CGPDFDocumentCreateWithProvider(provider));
|
||||||
if ( m_pdfDoc != NULL )
|
if ( m_pdfDoc != NULL )
|
||||||
{
|
{
|
||||||
@@ -224,7 +221,7 @@ wxMetaFile::~wxMetaFile()
|
|||||||
|
|
||||||
bool wxMetaFile::IsOk() const
|
bool wxMetaFile::IsOk() const
|
||||||
{
|
{
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
return (M_METAFILEDATA && (M_METAFILEDATA->GetData() != NULL));
|
return (M_METAFILEDATA && (M_METAFILEDATA->GetData() != NULL));
|
||||||
#else
|
#else
|
||||||
return (M_METAFILEDATA && (M_METAFILEDATA->GetHandle() != NULL));
|
return (M_METAFILEDATA && (M_METAFILEDATA->GetHandle() != NULL));
|
||||||
@@ -233,7 +230,7 @@ bool wxMetaFile::IsOk() const
|
|||||||
|
|
||||||
WXHMETAFILE wxMetaFile::GetHMETAFILE() const
|
WXHMETAFILE wxMetaFile::GetHMETAFILE() const
|
||||||
{
|
{
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
return (WXHMETAFILE) (CFDataRef) M_METAFILEDATA->GetData();
|
return (WXHMETAFILE) (CFDataRef) M_METAFILEDATA->GetData();
|
||||||
#else
|
#else
|
||||||
return (WXHMETAFILE) M_METAFILEDATA->GetHandle();
|
return (WXHMETAFILE) M_METAFILEDATA->GetHandle();
|
||||||
@@ -268,7 +265,7 @@ void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
|
|||||||
{
|
{
|
||||||
UnRef();
|
UnRef();
|
||||||
|
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
m_refData = new wxMetafileRefData((CFDataRef)mf);
|
m_refData = new wxMetafileRefData((CFDataRef)mf);
|
||||||
#else
|
#else
|
||||||
m_refData = new wxMetafileRefData((PicHandle)mf);
|
m_refData = new wxMetafileRefData((PicHandle)mf);
|
||||||
@@ -284,7 +281,7 @@ bool wxMetaFile::Play(wxDC *dc)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
{
|
{
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
CGContextRef cg = (CGContextRef) dc->GetGraphicsContext()->GetNativeContext();
|
CGContextRef cg = (CGContextRef) dc->GetGraphicsContext()->GetNativeContext();
|
||||||
CGPDFDocumentRef doc = M_METAFILEDATA->GetPDFDocument();
|
CGPDFDocumentRef doc = M_METAFILEDATA->GetPDFDocument();
|
||||||
CGPDFPageRef page = CGPDFDocumentGetPage( doc, 1 );
|
CGPDFPageRef page = CGPDFDocumentGetPage( doc, 1 );
|
||||||
@@ -292,29 +289,7 @@ bool wxMetaFile::Play(wxDC *dc)
|
|||||||
CGContextDrawPDFPage( cg, page );
|
CGContextDrawPDFPage( cg, page );
|
||||||
// CGContextTranslateCTM( cg, 0, bounds.size.width );
|
// CGContextTranslateCTM( cg, 0, bounds.size.width );
|
||||||
// CGContextScaleCTM( cg, 1, -1 );
|
// CGContextScaleCTM( cg, 1, -1 );
|
||||||
#elif wxMAC_USE_CORE_GRAPHICS
|
|
||||||
// FIXME: Please check the implementation, this is based solely on
|
|
||||||
// the original CoreGraphics impl and I'm not sure if this is right.
|
|
||||||
PicHandle pict = (PicHandle)GetHMETAFILE();
|
|
||||||
HLock((Handle)pict);
|
|
||||||
CGDataProviderRef dataProvider = CGDataProviderCreateWithData ( NULL, *pict,
|
|
||||||
GetHandleSize((Handle)pict), NULL );
|
|
||||||
QDPictRef cgPictRef = QDPictCreateWithProvider(dataProvider);
|
|
||||||
CGContextRef cg = (CGContextRef) dc->GetGraphicsContext()->GetNativeContext();
|
|
||||||
CGRect bounds = QDPictGetBounds( cgPictRef ) ;
|
|
||||||
|
|
||||||
CGContextSaveGState(cg);
|
|
||||||
CGContextTranslateCTM(cg, 0 , bounds.size.width );
|
|
||||||
CGContextScaleCTM(cg, 1, -1);
|
|
||||||
QDPictDrawToCGContext( cg , bounds , cgPictRef ) ;
|
|
||||||
CGContextRestoreGState( cg ) ;
|
|
||||||
|
|
||||||
QDPictRelease(cgPictRef);
|
|
||||||
CGDataProviderRelease(dataProvider);
|
|
||||||
#else
|
#else
|
||||||
// FIXME: This code doesn't work for the case where wxMAC_USE_CORE_GRAPHICS
|
|
||||||
// is used. However, the old CG code used QDPictRef which is gone from the
|
|
||||||
// current code.
|
|
||||||
PicHandle pict = (PicHandle)GetHMETAFILE();
|
PicHandle pict = (PicHandle)GetHMETAFILE();
|
||||||
wxMacPortSetter helper( dc );
|
wxMacPortSetter helper( dc );
|
||||||
Rect picFrame;
|
Rect picFrame;
|
||||||
@@ -355,11 +330,9 @@ wxMetaFileDC::wxMetaFileDC(
|
|||||||
wxMetafileRefData* metafiledata = new wxMetafileRefData(width, height);
|
wxMetafileRefData* metafiledata = new wxMetafileRefData(width, height);
|
||||||
m_metaFile->UnRef();
|
m_metaFile->UnRef();
|
||||||
m_metaFile->SetRefData( metafiledata );
|
m_metaFile->SetRefData( metafiledata );
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
SetGraphicsContext( wxGraphicsContext::CreateFromNative(metafiledata->GetContext()));
|
SetGraphicsContext( wxGraphicsContext::CreateFromNative(metafiledata->GetContext()));
|
||||||
m_ok = (m_graphicContext != NULL) ;
|
m_ok = (m_graphicContext != NULL) ;
|
||||||
#elif wxMAC_USE_CORE_GRAPHICS
|
|
||||||
// we don't do anything here for now
|
|
||||||
#else
|
#else
|
||||||
Rect r = { 0, 0, height, width };
|
Rect r = { 0, 0, height, width };
|
||||||
RectRgn( (RgnHandle)m_macBoundaryClipRgn, &r );
|
RectRgn( (RgnHandle)m_macBoundaryClipRgn, &r );
|
||||||
@@ -388,7 +361,7 @@ void wxMetaFileDC::DoGetSize(int *width, int *height) const
|
|||||||
|
|
||||||
wxMetaFile *wxMetaFileDC::Close()
|
wxMetaFile *wxMetaFileDC::Close()
|
||||||
{
|
{
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
delete m_graphicContext;
|
delete m_graphicContext;
|
||||||
m_graphicContext = NULL;
|
m_graphicContext = NULL;
|
||||||
m_ok = false;
|
m_ok = false;
|
||||||
@@ -402,7 +375,7 @@ wxMetaFile *wxMetaFileDC::Close()
|
|||||||
#if wxUSE_DATAOBJ
|
#if wxUSE_DATAOBJ
|
||||||
size_t wxMetafileDataObject::GetDataSize() const
|
size_t wxMetafileDataObject::GetDataSize() const
|
||||||
{
|
{
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
CFIndex length = 0;
|
CFIndex length = 0;
|
||||||
wxMetafileRefData* refData = M_METAFILEREFDATA(m_metafile);
|
wxMetafileRefData* refData = M_METAFILEREFDATA(m_metafile);
|
||||||
if ( refData )
|
if ( refData )
|
||||||
@@ -416,7 +389,7 @@ size_t wxMetafileDataObject::GetDataSize() const
|
|||||||
bool wxMetafileDataObject::GetDataHere(void *buf) const
|
bool wxMetafileDataObject::GetDataHere(void *buf) const
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
wxMetafileRefData* refData = M_METAFILEREFDATA(m_metafile);
|
wxMetafileRefData* refData = M_METAFILEREFDATA(m_metafile);
|
||||||
if ( refData )
|
if ( refData )
|
||||||
{
|
{
|
||||||
@@ -440,7 +413,7 @@ bool wxMetafileDataObject::GetDataHere(void *buf) const
|
|||||||
|
|
||||||
bool wxMetafileDataObject::SetData(size_t len, const void *buf)
|
bool wxMetafileDataObject::SetData(size_t len, const void *buf)
|
||||||
{
|
{
|
||||||
#if USE_CG_METAFILE
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
wxMetafileRefData* metafiledata = new wxMetafileRefData(wxCFRefFromGet(wxCFDataRef((UInt8*)buf, len).get()));
|
wxMetafileRefData* metafiledata = new wxMetafileRefData(wxCFRefFromGet(wxCFDataRef((UInt8*)buf, len).get()));
|
||||||
m_metafile.UnRef();
|
m_metafile.UnRef();
|
||||||
m_metafile.SetRefData( metafiledata );
|
m_metafile.SetRefData( metafiledata );
|
||||||
|
Reference in New Issue
Block a user