X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/84f67b116a47004a1bd391a6fd095bd4a433437b..601398b9b1e63109f44af34ff79bc558fe929b4d:/src/generic/graphicc.cpp diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 040844ed4d..b70fbd4f9a 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -11,12 +11,14 @@ #include "wx/wxprec.h" -#include "wx/dc.h" - #ifdef __BORLANDC__ #pragma hdrstop #endif +#if wxUSE_GRAPHICS_CONTEXT + +#include "wx/dc.h" + #ifndef WX_PRECOMP #include "wx/image.h" #include "wx/window.h" @@ -32,15 +34,9 @@ #include "wx/module.h" #endif -#ifdef __WXGTK__ -#include -#endif - -#include "wx/graphics.h" +#include "wx/private/graphics.h" #include "wx/rawbmp.h" -#if wxUSE_GRAPHICS_CONTEXT - #include using namespace std; @@ -101,9 +97,9 @@ static inline double RadToDeg(double deg) #include #ifdef __WXGTK__ -#include "wx/gtk/win_gtk.h" #include #include "wx/fontutil.h" +#include "wx/gtk/dc.h" #endif #ifdef __WXMSW__ @@ -328,6 +324,7 @@ class WXDLLIMPEXP_CORE wxCairoContext : public wxGraphicsContext public: wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& dc ); + wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& dc ); #ifdef __WXGTK__ wxCairoContext( wxGraphicsRenderer* renderer, GdkDrawable *drawable ); #endif @@ -740,6 +737,7 @@ void wxCairoFontData::Apply( wxGraphicsContext* context ) // the rest is done using Pango layouts #elif defined(__WXMAC__) cairo_set_font_face(ctext, m_font); + cairo_set_font_size(ctext, m_size ); #else cairo_select_font_face(ctext, m_fontName, m_slant, m_weights ); cairo_set_font_size(ctext, m_size ); @@ -1040,7 +1038,25 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& : wxGraphicsContext(renderer) { #ifdef __WXGTK__ - Init( gdk_cairo_create( dc.m_window ) ); + wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl(); + Init( gdk_cairo_create( impldc->GetGDKWindow() ) ); +#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 +} + +wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& dc ) +: wxGraphicsContext(renderer) +{ +#ifdef __WXGTK__ + wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl(); + Init( gdk_cairo_create( impldc->GetGDKWindow() ) ); #endif #ifdef __WXMAC__ int width, height; @@ -1072,22 +1088,17 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, wxWindow *window) #ifdef __WXGTK__ // something along these lines (copied from dcclient) - GtkWidget *widget = window->m_wxwindow; - // Some controls don't have m_wxwindow - like wxStaticBox, but the user // code should still be able to create wxClientDCs for them, so we will // use the parent window here then. - if ( !widget ) + if (window->m_wxwindow == NULL) { window = window->GetParent(); - widget = window->m_wxwindow; } - wxASSERT_MSG( widget, wxT("wxCairoContext needs a widget") ); + wxASSERT_MSG( window->m_wxwindow, wxT("wxCairoContext needs a widget") ); - wxPizza *pizza = WX_PIZZA( widget ); - GdkDrawable* drawable = pizza->m_backing_window; - Init( gdk_cairo_create( drawable ) ) ; + Init(gdk_cairo_create(window->GTKGetDrawingWindow())); #endif } @@ -1117,7 +1128,7 @@ void wxCairoContext::Clip( const wxRegion& region ) while (ri) { path.AddRectangle(ri.GetX(), ri.GetY(), ri.GetW(), ri.GetH()); - ri++; + ++ri; } // Put it in the context @@ -1140,7 +1151,7 @@ void wxCairoContext::Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) cairo_append_path(m_context, cp); // clip to that path -// cairo_clip(m_context); + cairo_clip(m_context); path.UnGetNativePath(cp); } @@ -1337,7 +1348,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); @@ -1383,7 +1394,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; @@ -1417,6 +1428,17 @@ void wxCairoContext::GetTextExtent( const wxString &str, wxDouble *width, wxDoub { cairo_font_extents_t fe; cairo_font_extents(m_context, &fe); + + // some backends have negative descents + + if ( fe.descent < 0 ) + fe.descent = -fe.descent; + + if ( fe.height < (fe.ascent + fe.descent ) ) + { + // some backends are broken re height ... (eg currently ATSUI) + fe.height = fe.ascent + fe.descent; + } if (height) *height = fe.height; @@ -1458,10 +1480,7 @@ public : // Context virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc); - -#ifdef __WXMSW__ virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc); -#endif virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ); @@ -1508,6 +1527,9 @@ private : IMPLEMENT_DYNAMIC_CLASS(wxCairoRenderer,wxGraphicsRenderer) static wxCairoRenderer gs_cairoGraphicsRenderer; +// temporary hack to allow creating a cairo context on any platform +extern wxGraphicsRenderer* gCairoRenderer; +wxGraphicsRenderer* gCairoRenderer = &gs_cairoGraphicsRenderer; #ifdef __WXGTK__ wxGraphicsRenderer* wxGraphicsRenderer::GetDefaultRenderer() @@ -1521,12 +1543,10 @@ 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); } -#endif wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeContext( void * context ) {