* Implement dynamic loading of the Cairo DLL on Windows similar to how it was
done for GDI+. * Enable the use of the wxCairoContext on MSW. * Enable creating a wxGCDC from an exisiting wxGraphicsContext. * Since it's possible for a DLL that is using wx to not be on the PATH nor in the same location as the .exe, change the wxDynamicLibrary::RawLoad method to explicitly look first in the same place as the main wx-using binary. This way it will find DLLs that are in the same folder as the wx-using binary even if that would not be in the normal DLL search path. * Change wxDCImpl and wxDC::GetLogicalScale to be const methods. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68935 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -21,6 +21,10 @@
|
||||
|
||||
#if wxUSE_CAIRO
|
||||
|
||||
// keep cairo.h from defining dllimport as we're defining the symbols inside
|
||||
// the wx dll in order to load them dynamically.
|
||||
#define cairo_public
|
||||
|
||||
#include "wx/cairo.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
@@ -1089,7 +1093,13 @@ wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitm
|
||||
// Create a surface object and copy the bitmap pixel data to it. if the
|
||||
// image has alpha (or a mask represented as alpha) then we'll use a
|
||||
// different format and iterator than if it doesn't...
|
||||
if (bmpSource.HasAlpha() || bmpSource.GetMask())
|
||||
if (bmpSource.HasAlpha() || (bmpSource.GetMask()
|
||||
#ifdef __WXMSW__
|
||||
// this check is needed under wxMSW, but adding this condition to wxGTK
|
||||
// causes an assert when getting alpha pixel data, not sure about Mac.
|
||||
&& bmpSource.GetDepth() == 32
|
||||
#endif
|
||||
))
|
||||
{
|
||||
m_surface = cairo_image_surface_create_for_data(
|
||||
m_buffer, CAIRO_FORMAT_ARGB32, bw, bh, bw*4);
|
||||
@@ -1190,10 +1200,20 @@ public :
|
||||
wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC& dc )
|
||||
: wxGraphicsContext(renderer)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
// wxMSW contexts always use MM_ANISOTROPIC, which messes up
|
||||
// text rendering when printing using Cairo. Switch it to MM_TEXT
|
||||
// map mode to avoid this problem.
|
||||
HDC hdc = (HDC)dc.GetHDC();
|
||||
::SetMapMode(hdc, MM_TEXT);
|
||||
m_mswSurface = cairo_win32_printing_surface_create(hdc);
|
||||
Init( cairo_create(m_mswSurface) );
|
||||
#endif
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
const wxDCImpl *impl = dc.GetImpl();
|
||||
Init( (cairo_t*) impl->GetCairoContext() );
|
||||
|
||||
#endif
|
||||
wxSize sz = dc.GetSize();
|
||||
m_width = sz.x;
|
||||
m_height = sz.y;
|
||||
@@ -1203,11 +1223,21 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC&
|
||||
|
||||
double sx,sy;
|
||||
dc.GetUserScale( &sx, &sy );
|
||||
|
||||
// TODO: Determine if these fixes are needed on other platforms too.
|
||||
// On MSW, without this the printer context will not respect wxDC SetMapMode calls.
|
||||
// For example, using dc.SetMapMode(wxMM_POINTS) can let us share printer and screen
|
||||
// drawing code
|
||||
#ifdef __WXMSW__
|
||||
double lsx,lsy;
|
||||
dc.GetLogicalScale( &lsx, &lsy );
|
||||
sx *= lsx;
|
||||
sy *= lsy;
|
||||
#endif
|
||||
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 )
|
||||
@@ -1220,6 +1250,11 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC&
|
||||
|
||||
m_enableOffset = true;
|
||||
|
||||
#ifdef __WXMSW__
|
||||
m_mswSurface = cairo_win32_surface_create((HDC)dc.GetHDC());
|
||||
Init( cairo_create(m_mswSurface) );
|
||||
#endif
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl();
|
||||
Init( gdk_cairo_create( impldc->GetGDKWindow() ) );
|
||||
@@ -1258,6 +1293,11 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC&
|
||||
m_height = height;
|
||||
|
||||
m_enableOffset = true;
|
||||
|
||||
#ifdef __WXMSW__
|
||||
m_mswSurface = cairo_win32_surface_create((HDC)dc.GetHDC());
|
||||
Init( cairo_create(m_mswSurface) );
|
||||
#endif
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl();
|
||||
@@ -1837,7 +1877,13 @@ public :
|
||||
// create a subimage from a native image representation
|
||||
virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
|
||||
|
||||
protected :
|
||||
bool EnsureIsLoaded();
|
||||
void Load();
|
||||
void Unload();
|
||||
friend class wxCairoModule;
|
||||
private :
|
||||
int m_loaded;
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxCairoRenderer)
|
||||
} ;
|
||||
|
||||
@@ -1852,18 +1898,46 @@ static wxCairoRenderer gs_cairoGraphicsRenderer;
|
||||
extern wxGraphicsRenderer* gCairoRenderer;
|
||||
wxGraphicsRenderer* gCairoRenderer = &gs_cairoGraphicsRenderer;
|
||||
|
||||
bool wxCairoRenderer::EnsureIsLoaded()
|
||||
{
|
||||
#ifndef __WXGTK__
|
||||
Load();
|
||||
return wxCairoInit();
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxCairoRenderer::Load()
|
||||
{
|
||||
wxCairoInit();
|
||||
}
|
||||
|
||||
void wxCairoRenderer::Unload()
|
||||
{
|
||||
wxCairoCleanUp();
|
||||
}
|
||||
|
||||
// call EnsureIsLoaded() and return returnOnFail value if it fails
|
||||
#define ENSURE_LOADED_OR_RETURN(returnOnFail) \
|
||||
if ( !EnsureIsLoaded() ) \
|
||||
return (returnOnFail)
|
||||
|
||||
wxGraphicsContext * wxCairoRenderer::CreateContext( const wxWindowDC& dc)
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(NULL);
|
||||
return new wxCairoContext(this,dc);
|
||||
}
|
||||
|
||||
wxGraphicsContext * wxCairoRenderer::CreateContext( const wxMemoryDC& dc)
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(NULL);
|
||||
return new wxCairoContext(this,dc);
|
||||
}
|
||||
|
||||
wxGraphicsContext * wxCairoRenderer::CreateContext( const wxPrinterDC& dc)
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(NULL);
|
||||
#ifdef __WXGTK20__
|
||||
const wxDCImpl *impl = dc.GetImpl();
|
||||
cairo_t* context = (cairo_t*) impl->GetCairoContext();
|
||||
@@ -1871,13 +1945,14 @@ wxGraphicsContext * wxCairoRenderer::CreateContext( const wxPrinterDC& dc)
|
||||
return new wxCairoContext(this,dc);
|
||||
else
|
||||
#endif
|
||||
return NULL;
|
||||
return new wxCairoContext(this,dc);
|
||||
}
|
||||
|
||||
#ifdef __WXMSW__
|
||||
#if wxUSE_ENH_METAFILE
|
||||
wxGraphicsContext * wxCairoRenderer::CreateContext( const wxEnhMetaFileDC& dc)
|
||||
wxGraphicsContext * wxCairoRenderer::CreateContext( const wxEnhMetaFileDC& WXUNUSED(dc) )
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(NULL);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
@@ -1885,6 +1960,7 @@ wxGraphicsContext * wxCairoRenderer::CreateContext( const wxEnhMetaFileDC& dc)
|
||||
|
||||
wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeContext( void * context )
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(NULL);
|
||||
#ifdef __WXMSW__
|
||||
return new wxCairoContext(this,(HDC)context);
|
||||
#else
|
||||
@@ -1895,15 +1971,18 @@ wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeContext( void * cont
|
||||
|
||||
wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeWindow( void * window )
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(NULL);
|
||||
#ifdef __WXGTK__
|
||||
return new wxCairoContext(this,(GdkDrawable*)window);
|
||||
#else
|
||||
wxUnusedVar(window);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
wxGraphicsContext * wxCairoRenderer::CreateMeasuringContext()
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(NULL);
|
||||
#ifdef __WXGTK__
|
||||
return CreateContextFromNativeWindow(gdk_get_default_root_window());
|
||||
#endif
|
||||
@@ -1913,6 +1992,7 @@ wxGraphicsContext * wxCairoRenderer::CreateMeasuringContext()
|
||||
|
||||
wxGraphicsContext * wxCairoRenderer::CreateContext( wxWindow* window )
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(NULL);
|
||||
return new wxCairoContext(this, window );
|
||||
}
|
||||
|
||||
@@ -1920,6 +2000,7 @@ wxGraphicsContext * wxCairoRenderer::CreateContext( wxWindow* window )
|
||||
|
||||
wxGraphicsPath wxCairoRenderer::CreatePath()
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath);
|
||||
wxGraphicsPath path;
|
||||
path.SetRefData( new wxCairoPathData(this) );
|
||||
return path;
|
||||
@@ -1932,6 +2013,7 @@ wxGraphicsMatrix wxCairoRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDouble
|
||||
wxDouble tx, wxDouble ty)
|
||||
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix);
|
||||
wxGraphicsMatrix m;
|
||||
wxCairoMatrixData* data = new wxCairoMatrixData( this );
|
||||
data->Set( a,b,c,d,tx,ty ) ;
|
||||
@@ -1941,6 +2023,7 @@ wxGraphicsMatrix wxCairoRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDouble
|
||||
|
||||
wxGraphicsPen wxCairoRenderer::CreatePen(const wxPen& pen)
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen);
|
||||
if ( !pen.IsOk() || pen.GetStyle() == wxPENSTYLE_TRANSPARENT )
|
||||
return wxNullGraphicsPen;
|
||||
else
|
||||
@@ -1953,6 +2036,7 @@ wxGraphicsPen wxCairoRenderer::CreatePen(const wxPen& pen)
|
||||
|
||||
wxGraphicsBrush wxCairoRenderer::CreateBrush(const wxBrush& brush )
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
|
||||
if ( !brush.IsOk() || brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT )
|
||||
return wxNullGraphicsBrush;
|
||||
else
|
||||
@@ -1968,6 +2052,7 @@ wxCairoRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
|
||||
wxDouble x2, wxDouble y2,
|
||||
const wxGraphicsGradientStops& stops)
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
|
||||
wxGraphicsBrush p;
|
||||
wxCairoBrushData* d = new wxCairoBrushData( this );
|
||||
d->CreateLinearGradientBrush(x1, y1, x2, y2, stops);
|
||||
@@ -1980,6 +2065,7 @@ wxCairoRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
|
||||
wxDouble xc, wxDouble yc, wxDouble r,
|
||||
const wxGraphicsGradientStops& stops)
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
|
||||
wxGraphicsBrush p;
|
||||
wxCairoBrushData* d = new wxCairoBrushData( this );
|
||||
d->CreateRadialGradientBrush(xo, yo, xc, yc, r, stops);
|
||||
@@ -1990,6 +2076,7 @@ wxCairoRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
|
||||
// sets the font
|
||||
wxGraphicsFont wxCairoRenderer::CreateFont( const wxFont &font , const wxColour &col )
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont);
|
||||
if ( font.IsOk() )
|
||||
{
|
||||
wxGraphicsFont p;
|
||||
@@ -2002,6 +2089,7 @@ wxGraphicsFont wxCairoRenderer::CreateFont( const wxFont &font , const wxColour
|
||||
|
||||
wxGraphicsBitmap wxCairoRenderer::CreateBitmap( const wxBitmap& bmp )
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
|
||||
if ( bmp.IsOk() )
|
||||
{
|
||||
wxGraphicsBitmap p;
|
||||
@@ -2014,6 +2102,7 @@ wxGraphicsBitmap wxCairoRenderer::CreateBitmap( const wxBitmap& bmp )
|
||||
|
||||
wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromNativeBitmap( void* bitmap )
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
|
||||
if ( bitmap != NULL )
|
||||
{
|
||||
wxGraphicsBitmap p;
|
||||
@@ -2031,6 +2120,7 @@ wxCairoRenderer::CreateSubBitmap(const wxGraphicsBitmap& WXUNUSED(bitmap),
|
||||
wxDouble WXUNUSED(w),
|
||||
wxDouble WXUNUSED(h))
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
|
||||
wxFAIL_MSG("wxCairoRenderer::CreateSubBitmap is not implemented.");
|
||||
return wxNullGraphicsBitmap;
|
||||
}
|
||||
|
Reference in New Issue
Block a user