+wxGraphicsFont
+wxGDIPlusRenderer::CreateFont(double size,
+ const wxString& facename,
+ int flags,
+ const wxColour& col)
+{
+ ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont);
+
+ // Convert wxFont flags to GDI+ style:
+ int style = FontStyleRegular;
+ if ( flags & wxFONTFLAG_ITALIC )
+ style |= FontStyleItalic;
+ if ( flags & wxFONTFLAG_UNDERLINED )
+ style |= FontStyleUnderline;
+ if ( flags & wxFONTFLAG_BOLD )
+ style |= FontStyleBold;
+ if ( flags & wxFONTFLAG_STRIKETHROUGH )
+ style |= FontStyleStrikeout;
+
+
+ wxGraphicsFont f;
+ f.SetRefData(new wxGDIPlusFontData(this, facename, size, style, col));
+ return f;
+}
+
+wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap )
+{
+ ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
+ if ( bitmap.IsOk() )
+ {
+ wxGraphicsBitmap p;
+ p.SetRefData(new wxGDIPlusBitmapData( this , bitmap ));
+ return p;
+ }
+ else
+ return wxNullGraphicsBitmap;
+}
+
+#if wxUSE_IMAGE
+
+wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromImage(const wxImage& image)
+{
+ ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
+ if ( image.IsOk() )
+ {
+ // Notice that we rely on conversion from wxImage to wxBitmap here but
+ // we could probably do it more efficiently by converting from wxImage
+ // to GDI+ Bitmap directly, i.e. copying wxImage pixels to the buffer
+ // returned by Bitmap::LockBits(). However this would require writing
+ // code specific for this task while like this we can reuse existing
+ // code (see also wxGDIPlusBitmapData::ConvertToImage()).
+ wxGraphicsBitmap gb;
+ gb.SetRefData(new wxGDIPlusBitmapData(this, image));
+ return gb;
+ }
+ else
+ return wxNullGraphicsBitmap;
+}
+
+
+wxImage wxGDIPlusRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp)
+{
+ ENSURE_LOADED_OR_RETURN(wxNullImage);
+ const wxGDIPlusBitmapData* const
+ data = static_cast<wxGDIPlusBitmapData*>(bmp.GetGraphicsData());
+
+ return data ? data->ConvertToImage() : wxNullImage;
+}
+
+#endif // wxUSE_IMAGE
+
+
+wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap )
+{
+ ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
+ if ( bitmap != NULL )
+ {
+ wxGraphicsBitmap p;
+ p.SetRefData(new wxGDIPlusBitmapData( this , (Bitmap*) bitmap ));
+ return p;
+ }
+ else
+ return wxNullGraphicsBitmap;
+}
+
+wxGraphicsBitmap wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
+ Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bitmap.GetRefData())->GetGDIPlusBitmap();
+ if ( image )
+ {
+ wxGraphicsBitmap p;
+ p.SetRefData(new wxGDIPlusBitmapData( this , image->Clone( (REAL) x , (REAL) y , (REAL) w , (REAL) h , PixelFormat32bppPARGB) ));
+ return p;
+ }
+ else
+ return wxNullGraphicsBitmap;
+}
+
+// Shutdown GDI+ at app exit, before possible dll unload
+class wxGDIPlusRendererModule : public wxModule
+{
+public:
+ wxGDIPlusRendererModule()
+ {
+ // We must be uninitialized before GDI+ DLL itself is unloaded.
+ AddDependency("wxGdiPlusModule");
+ }
+
+ virtual bool OnInit() { return true; }
+ virtual void OnExit()
+ {
+ wxDELETE(gs_drawTextStringFormat);
+
+ gs_GDIPlusRenderer.Unload();
+ }
+
+private:
+ DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule, wxModule)
+
+// ----------------------------------------------------------------------------
+// wxMSW-specific parts of wxGCDC
+// ----------------------------------------------------------------------------
+
+WXHDC wxGCDC::AcquireHDC()
+{
+ wxGraphicsContext * const gc = GetGraphicsContext();
+ if ( !gc )
+ return NULL;
+
+#if wxUSE_CAIRO
+ // we can't get the HDC if it is not a GDI+ context
+ wxGraphicsRenderer* r1 = gc->GetRenderer();
+ wxGraphicsRenderer* r2 = wxGraphicsRenderer::GetCairoRenderer();
+ if (r1 == r2)
+ return NULL;
+#endif
+
+ Graphics * const g = static_cast<Graphics *>(gc->GetNativeContext());
+ return g ? g->GetHDC() : NULL;
+}
+
+void wxGCDC::ReleaseHDC(WXHDC hdc)
+{
+ if ( !hdc )
+ return;
+
+ wxGraphicsContext * const gc = GetGraphicsContext();
+ wxCHECK_RET( gc, "can't release HDC because there is no wxGraphicsContext" );
+
+#if wxUSE_CAIRO
+ // we can't get the HDC if it is not a GDI+ context
+ wxGraphicsRenderer* r1 = gc->GetRenderer();
+ wxGraphicsRenderer* r2 = wxGraphicsRenderer::GetCairoRenderer();
+ if (r1 == r2)
+ return;
+#endif
+
+ Graphics * const g = static_cast<Graphics *>(gc->GetNativeContext());
+ wxCHECK_RET( g, "can't release HDC because there is no Graphics" );
+
+ g->ReleaseHDC((HDC)hdc);
+}
+