X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3e700936123465187e5c662a0a3d11f5e91fbd5f..3201a1046ba71ba8e5ef2ed694fde34d12f743f3:/src/generic/graphicc.cpp?ds=sidebyside diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 79493bbb99..08b92ef8c7 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -34,7 +34,7 @@ #include "wx/module.h" #endif -#include "wx/graphics.h" +#include "wx/private/graphics.h" #include "wx/rawbmp.h" #include @@ -99,6 +99,7 @@ static inline double RadToDeg(double deg) #ifdef __WXGTK__ #include #include "wx/fontutil.h" +#include "wx/gtk/dc.h" #endif #ifdef __WXMSW__ @@ -106,7 +107,7 @@ static inline double RadToDeg(double deg) #endif #ifdef __WXMAC__ -#include "wx/mac/private.h" +#include "wx/osx/private.h" #include #include #endif @@ -323,6 +324,8 @@ class WXDLLIMPEXP_CORE wxCairoContext : public wxGraphicsContext public: wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& dc ); + wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& dc ); + wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC& dc ); #ifdef __WXGTK__ wxCairoContext( wxGraphicsRenderer* renderer, GdkDrawable *drawable ); #endif @@ -1032,12 +1035,49 @@ public : bool m_offset; } ; +wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC& dc ) +: wxGraphicsContext(renderer) +{ +#ifdef __WXGTK20__ + const wxDCImpl *impl = dc.GetImpl(); + Init( (cairo_t*) impl->GetCairoContext() ); + + wxPoint org = dc.GetDeviceOrigin(); + cairo_translate( m_context, org.x, org.y ); + + double sx,sy; + dc.GetUserScale( &sx, &sy ); + cairo_scale( m_context, sx, sy ); + + org = dc.GetLogicalOrigin(); + cairo_translate( m_context, -org.x, -org.y ); +#endif +} + wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& dc ) : wxGraphicsContext(renderer) { -#ifdef __WXGTK__ - Init( gdk_cairo_create( dc.m_window ) ); +#ifdef __WXGTK20__ + wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl(); + Init( gdk_cairo_create( impldc->GetGDKWindow() ) ); + +#if 0 + wxGraphicsMatrix matrix = CreateMatrix(); + + wxPoint org = dc.GetDeviceOrigin(); + matrix.Translate( org.x, org.y ); + + org = dc.GetLogicalOrigin(); + matrix.Translate( -org.x, -org.y ); + + double sx,sy; + dc.GetUserScale( &sx, &sy ); + matrix.Scale( sx, sy ); + + ConcatTransform( matrix ); +#endif #endif + #ifdef __WXMAC__ int width, height; dc.GetSize( &width, &height ); @@ -1048,7 +1088,41 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& #endif } -#ifdef __WXGTK__ +wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& dc ) +: wxGraphicsContext(renderer) +{ +#ifdef __WXGTK20__ + wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl(); + Init( gdk_cairo_create( impldc->GetGDKWindow() ) ); + +#if 0 + wxGraphicsMatrix matrix = CreateMatrix(); + + wxPoint org = dc.GetDeviceOrigin(); + matrix.Translate( org.x, org.y ); + + org = dc.GetLogicalOrigin(); + matrix.Translate( -org.x, -org.y ); + + double sx,sy; + dc.GetUserScale( &sx, &sy ); + matrix.Scale( sx, sy ); + + ConcatTransform( matrix ); +#endif +#endif + +#ifdef __WXMAC__ + int width, height; + dc.GetSize( &width, &height ); + CGContextRef cgcontext = (CGContextRef)dc.GetWindow()->MacGetCGContextRef(); + cairo_surface_t* surface = cairo_quartz_surface_create_for_cg_context(cgcontext, width, height); + Init( cairo_create( surface ) ); + cairo_surface_destroy( surface ); +#endif +} + +#ifdef __WXGTK20__ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, GdkDrawable *drawable ) : wxGraphicsContext(renderer) { @@ -1328,7 +1402,7 @@ void wxCairoContext::DrawText( const wxString &str, wxDouble x, wxDouble y ) return; #ifdef __WXGTK__ - const wxCharBuffer data = wxConvUTF8.cWC2MB( str ); + const wxCharBuffer data = str.utf8_str(); if ( !data ) return; size_t datalen = strlen(data); @@ -1374,7 +1448,7 @@ void wxCairoContext::GetTextExtent( const wxString &str, wxDouble *width, wxDoub PangoLayout *layout = pango_cairo_create_layout (m_context); pango_layout_set_font_description( layout, ((wxCairoFontData*)m_font.GetRefData())->GetFont()); - const wxCharBuffer data = wxConvUTF8.cWC2MB( str ); + const wxCharBuffer data = str.utf8_str(); if ( !data ) { return; @@ -1460,10 +1534,8 @@ public : // Context virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc); - -#ifdef __WXMSW__ virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc); -#endif + virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc); virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ); @@ -1499,6 +1571,20 @@ public : // sets the font virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) ; + // create a native bitmap representation +#if 0 + virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) + { + return wxGraphicsBitmap; + } + + // create a subimage from a native image representation + virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) + { + return wxGraphicsBitmap; + } +#endif + private : DECLARE_DYNAMIC_CLASS_NO_COPY(wxCairoRenderer) } ; @@ -1526,12 +1612,22 @@ wxGraphicsContext * wxCairoRenderer::CreateContext( const wxWindowDC& dc) return new wxCairoContext(this,dc); } -#ifdef __WXMSW__ wxGraphicsContext * wxCairoRenderer::CreateContext( const wxMemoryDC& dc) { - return NULL; + return new wxCairoContext(this,dc); } + +wxGraphicsContext * wxCairoRenderer::CreateContext( const wxPrinterDC& dc) +{ +#ifdef __WXGTK20__ + const wxDCImpl *impl = dc.GetImpl(); + cairo_t* context = (cairo_t*) impl->GetCairoContext(); + if (context) + return new wxCairoContext(this,dc); + else #endif + return NULL; +} wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeContext( void * context ) {