1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/graphics.cpp
3 // Purpose: wxGCDC class
4 // Author: Stefan Csomor
8 // Copyright: (c) 2006 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #if wxUSE_GRAPHICS_CONTEXT
23 #include "wx/msw/wrapcdlg.h"
25 #include "wx/window.h"
27 #include "wx/dialog.h"
29 #include "wx/bitmap.h"
32 #include "wx/module.h"
33 // include all dc types that are used as a param
35 #include "wx/dcclient.h"
36 #include "wx/dcmemory.h"
37 #include "wx/dcprint.h"
42 #include "wx/private/graphics.h"
43 #include "wx/msw/wrapgdip.h"
44 #include "wx/msw/dc.h"
45 #if wxUSE_ENH_METAFILE
46 #include "wx/msw/enhmeta.h"
48 #include "wx/dcgraph.h"
50 #include "wx/msw/private.h" // needs to be before #include <commdlg.h>
52 #if wxUSE_COMMON_DIALOGS && !defined(__WXMICROWIN__)
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 const double RAD2DEG
= 180.0 / M_PI
;
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
70 inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
72 inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
73 inline double RadToDeg(double deg
) { return (deg
* 180.0) / M_PI
; }
75 // translate a wxColour to a Color
76 inline Color
wxColourToColor(const wxColour
& col
)
78 return Color(col
.Alpha(), col
.Red(), col
.Green(), col
.Blue());
81 // Do not use this pointer directly, it's only used by
82 // GetDrawTextStringFormat() and the cleanup code in wxGDIPlusRendererModule.
83 StringFormat
* gs_drawTextStringFormat
= NULL
;
85 // Get the string format used for the text drawing and measuring functions:
86 // notice that it must be the same one for all of them, otherwise the drawn
87 // text might be of different size than what measuring it returned.
88 inline StringFormat
* GetDrawTextStringFormat()
90 if ( !gs_drawTextStringFormat
)
92 gs_drawTextStringFormat
= new StringFormat(StringFormat::GenericTypographic());
94 // This doesn't make any difference for DrawText() actually but we want
95 // this behaviour when measuring text.
96 gs_drawTextStringFormat
->SetFormatFlags
98 gs_drawTextStringFormat
->GetFormatFlags()
99 | StringFormatFlagsMeasureTrailingSpaces
103 return gs_drawTextStringFormat
;
106 } // anonymous namespace
108 //-----------------------------------------------------------------------------
109 // device context implementation
111 // more and more of the dc functionality should be implemented by calling
112 // the appropricate wxGDIPlusContext, but we will have to do that step by step
113 // also coordinate conversions should be moved to native matrix ops
114 //-----------------------------------------------------------------------------
116 // we always stock two context states, one at entry, to be able to preserve the
117 // state we were called with, the other one after changing to HI Graphics orientation
118 // (this one is used for getting back clippings etc)
120 //-----------------------------------------------------------------------------
121 // wxGraphicsPath implementation
122 //-----------------------------------------------------------------------------
124 class wxGDIPlusContext
;
126 class wxGDIPlusPathData
: public wxGraphicsPathData
129 wxGDIPlusPathData(wxGraphicsRenderer
* renderer
, GraphicsPath
* path
= NULL
);
130 ~wxGDIPlusPathData();
132 virtual wxGraphicsObjectRefData
*Clone() const;
135 // These are the path primitives from which everything else can be constructed
138 // begins a new subpath at (x,y)
139 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
141 // adds a straight line from the current point to (x,y)
142 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
144 // adds a cubic Bezier curve from the current point, using two control points and an end point
145 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
148 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
149 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
) ;
151 // gets the last point of the current path, (0,0) if not yet set
152 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
155 virtual void AddPath( const wxGraphicsPathData
* path
);
157 // closes the current sub-path
158 virtual void CloseSubpath();
161 // These are convenience functions which - if not available natively will be assembled
162 // using the primitives from above
165 // appends a rectangle as a new closed subpath
166 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) ;
169 // appends an ellipsis as a new closed subpath fitting the passed rectangle
170 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
172 // draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
173 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
176 // returns the native path
177 virtual void * GetNativePath() const { return m_path
; }
179 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
180 virtual void UnGetNativePath(void * WXUNUSED(path
)) const {}
182 // transforms each point of this path by the matrix
183 virtual void Transform( const wxGraphicsMatrixData
* matrix
) ;
185 // gets the bounding box enclosing all points (possibly including control points)
186 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const;
188 virtual bool Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) const;
191 GraphicsPath
* m_path
;
194 class wxGDIPlusMatrixData
: public wxGraphicsMatrixData
197 wxGDIPlusMatrixData(wxGraphicsRenderer
* renderer
, Matrix
* matrix
= NULL
) ;
198 virtual ~wxGDIPlusMatrixData() ;
200 virtual wxGraphicsObjectRefData
* Clone() const ;
202 // concatenates the matrix
203 virtual void Concat( const wxGraphicsMatrixData
*t
);
205 // sets the matrix to the respective values
206 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
207 wxDouble tx
=0.0, wxDouble ty
=0.0);
209 // gets the component valuess of the matrix
210 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
211 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
213 // makes this the inverse matrix
214 virtual void Invert();
216 // returns true if the elements of the transformation matrix are equal ?
217 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
219 // return true if this is the identity matrix
220 virtual bool IsIdentity() const;
226 // add the translation to this matrix
227 virtual void Translate( wxDouble dx
, wxDouble dy
);
229 // add the scale to this matrix
230 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
232 // add the rotation to this matrix (radians)
233 virtual void Rotate( wxDouble angle
);
236 // apply the transforms
239 // applies that matrix to the point
240 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
242 // applies the matrix except for translations
243 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
245 // returns the native representation
246 virtual void * GetNativeMatrix() const;
251 class wxGDIPlusPenData
: public wxGraphicsObjectRefData
254 wxGDIPlusPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
259 virtual wxDouble
GetWidth() { return m_width
; }
260 virtual Pen
* GetGDIPlusPen() { return m_pen
; }
270 class wxGDIPlusBrushData
: public wxGraphicsObjectRefData
273 wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
);
274 wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
275 ~wxGDIPlusBrushData ();
277 void CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
278 wxDouble x2
, wxDouble y2
,
279 const wxGraphicsGradientStops
& stops
);
280 void CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
281 wxDouble xc
, wxDouble yc
,
283 const wxGraphicsGradientStops
& stops
);
285 virtual Brush
* GetGDIPlusBrush() { return m_brush
; }
291 // common part of Create{Linear,Radial}GradientBrush()
292 template <typename T
>
293 void SetGradientStops(T
*brush
, const wxGraphicsGradientStops
& stops
);
297 GraphicsPath
* m_brushPath
;
300 class WXDLLIMPEXP_CORE wxGDIPlusBitmapData
: public wxGraphicsBitmapData
303 wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, Bitmap
* bitmap
);
304 wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, const wxBitmap
&bmp
);
305 ~wxGDIPlusBitmapData ();
307 virtual Bitmap
* GetGDIPlusBitmap() { return m_bitmap
; }
308 virtual void* GetNativeBitmap() const { return m_bitmap
; }
311 wxImage
ConvertToImage() const;
312 #endif // wxUSE_IMAGE
319 class wxGDIPlusFontData
: public wxGraphicsObjectRefData
322 wxGDIPlusFontData( wxGraphicsRenderer
* renderer
,
324 const wxColour
& col
);
325 wxGDIPlusFontData(wxGraphicsRenderer
* renderer
,
326 const wxString
& name
,
329 const wxColour
& col
);
330 ~wxGDIPlusFontData();
332 virtual Brush
* GetGDIPlusBrush() { return m_textBrush
; }
333 virtual Font
* GetGDIPlusFont() { return m_font
; }
336 // Common part of all ctors, flags here is a combination of values of
337 // FontStyle GDI+ enum.
338 void Init(const wxString
& name
,
348 class wxGDIPlusContext
: public wxGraphicsContext
351 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
);
352 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HDC hdc
, wxDouble width
, wxDouble height
);
353 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HWND hwnd
);
354 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, Graphics
* gr
);
355 wxGDIPlusContext(wxGraphicsRenderer
* renderer
);
357 virtual ~wxGDIPlusContext();
359 virtual void Clip( const wxRegion
®ion
);
360 // clips drawings to the rect
361 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
363 // resets the clipping to original extent
364 virtual void ResetClip();
366 virtual void * GetNativeContext();
368 virtual void StrokePath( const wxGraphicsPath
& p
);
369 virtual void FillPath( const wxGraphicsPath
& p
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
371 virtual void DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
373 // stroke lines connecting each of the points
374 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*points
);
377 virtual void DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
379 virtual bool SetAntialiasMode(wxAntialiasMode antialias
);
381 virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation
);
383 virtual bool SetCompositionMode(wxCompositionMode op
);
385 virtual void BeginLayer(wxDouble opacity
);
387 virtual void EndLayer();
389 virtual void Translate( wxDouble dx
, wxDouble dy
);
390 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
391 virtual void Rotate( wxDouble angle
);
393 // concatenates this transform with the current transform of this context
394 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
396 // sets the transform of this context
397 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
399 // gets the matrix of this context
400 virtual wxGraphicsMatrix
GetTransform() const;
402 virtual void DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
403 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
404 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
405 virtual void PushState();
406 virtual void PopState();
408 virtual void GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
409 wxDouble
*descent
, wxDouble
*externalLeading
) const;
410 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
411 virtual bool ShouldOffset() const;
412 virtual void GetSize( wxDouble
* width
, wxDouble
*height
);
414 Graphics
* GetGraphics() const { return m_context
; }
418 wxDouble m_fontScaleRatio
;
420 // Used from ctors (including those in the derived classes) and takes
421 // ownership of the graphics pointer that must be non-NULL.
422 void Init(Graphics
* graphics
, int width
, int height
);
425 virtual void DoDrawText(const wxString
& str
, wxDouble x
, wxDouble y
);
428 wxStack
<GraphicsState
> m_stateStack
;
429 GraphicsState m_state1
;
430 GraphicsState m_state2
;
432 wxDECLARE_NO_COPY_CLASS(wxGDIPlusContext
);
437 class wxGDIPlusImageContext
: public wxGDIPlusContext
440 wxGDIPlusImageContext(wxGraphicsRenderer
* renderer
, wxImage
& image
) :
441 wxGDIPlusContext(renderer
),
443 m_bitmap(renderer
, image
)
447 new Graphics(m_bitmap
.GetGDIPlusBitmap()),
453 virtual ~wxGDIPlusImageContext()
455 m_image
= m_bitmap
.ConvertToImage();
460 wxGDIPlusBitmapData m_bitmap
;
462 wxDECLARE_NO_COPY_CLASS(wxGDIPlusImageContext
);
465 #endif // wxUSE_IMAGE
467 class wxGDIPlusMeasuringContext
: public wxGDIPlusContext
470 wxGDIPlusMeasuringContext( wxGraphicsRenderer
* renderer
) : wxGDIPlusContext( renderer
, m_hdc
= GetDC(NULL
), 1000, 1000 )
474 virtual ~wxGDIPlusMeasuringContext()
476 ReleaseDC( NULL
, m_hdc
);
483 class wxGDIPlusPrintingContext
: public wxGDIPlusContext
486 wxGDIPlusPrintingContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
);
487 virtual ~wxGDIPlusPrintingContext() { }
491 //-----------------------------------------------------------------------------
492 // wxGDIPlusRenderer declaration
493 //-----------------------------------------------------------------------------
495 class wxGDIPlusRenderer
: public wxGraphicsRenderer
504 virtual ~wxGDIPlusRenderer()
514 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
516 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
);
518 #if wxUSE_PRINTING_ARCHITECTURE
519 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
);
522 #if wxUSE_ENH_METAFILE
523 virtual wxGraphicsContext
* CreateContext( const wxEnhMetaFileDC
& dc
);
526 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
528 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
530 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
533 virtual wxGraphicsContext
* CreateContextFromImage(wxImage
& image
);
534 #endif // wxUSE_IMAGE
536 virtual wxGraphicsContext
* CreateMeasuringContext();
540 virtual wxGraphicsPath
CreatePath();
544 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
545 wxDouble tx
=0.0, wxDouble ty
=0.0);
548 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
550 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
552 virtual wxGraphicsBrush
553 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
554 wxDouble x2
, wxDouble y2
,
555 const wxGraphicsGradientStops
& stops
);
557 virtual wxGraphicsBrush
558 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
559 wxDouble xc
, wxDouble yc
,
561 const wxGraphicsGradientStops
& stops
);
563 // create a native bitmap representation
564 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
);
566 virtual wxGraphicsBitmap
CreateBitmapFromImage(const wxImage
& image
);
567 virtual wxImage
CreateImageFromBitmap(const wxGraphicsBitmap
& bmp
);
568 #endif // wxUSE_IMAGE
570 virtual wxGraphicsFont
CreateFont( const wxFont
& font
,
571 const wxColour
& col
);
573 virtual wxGraphicsFont
CreateFont(double size
,
574 const wxString
& facename
,
575 int flags
= wxFONTFLAG_DEFAULT
,
576 const wxColour
& col
= *wxBLACK
);
578 // create a graphics bitmap from a native bitmap
579 virtual wxGraphicsBitmap
CreateBitmapFromNativeBitmap( void* bitmap
);
581 // create a subimage from a native image representation
582 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
585 bool EnsureIsLoaded();
588 friend class wxGDIPlusRendererModule
;
592 ULONG_PTR m_gditoken
;
594 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer
)
597 //-----------------------------------------------------------------------------
598 // wxGDIPlusPen implementation
599 //-----------------------------------------------------------------------------
601 wxGDIPlusPenData::~wxGDIPlusPenData()
608 void wxGDIPlusPenData::Init()
615 wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
)
616 : wxGraphicsObjectRefData(renderer
)
619 m_width
= pen
.GetWidth();
623 m_pen
= new Pen(wxColourToColor(pen
.GetColour()), m_width
);
626 switch ( pen
.GetCap() )
632 case wxCAP_PROJECTING
:
637 cap
= LineCapFlat
; // TODO verify
644 m_pen
->SetLineCap(cap
,cap
, DashCapFlat
);
647 switch ( pen
.GetJoin() )
650 join
= LineJoinBevel
;
654 join
= LineJoinMiter
;
658 join
= LineJoinRound
;
662 join
= LineJoinMiter
;
666 m_pen
->SetLineJoin(join
);
668 m_pen
->SetDashStyle(DashStyleSolid
);
670 DashStyle dashStyle
= DashStyleSolid
;
671 switch ( pen
.GetStyle() )
673 case wxPENSTYLE_SOLID
:
676 case wxPENSTYLE_DOT
:
677 dashStyle
= DashStyleDot
;
680 case wxPENSTYLE_LONG_DASH
:
681 dashStyle
= DashStyleDash
; // TODO verify
684 case wxPENSTYLE_SHORT_DASH
:
685 dashStyle
= DashStyleDash
;
688 case wxPENSTYLE_DOT_DASH
:
689 dashStyle
= DashStyleDashDot
;
691 case wxPENSTYLE_USER_DASH
:
693 dashStyle
= DashStyleCustom
;
695 int count
= pen
.GetDashes( &dashes
);
696 if ((dashes
!= NULL
) && (count
> 0))
698 REAL
*userLengths
= new REAL
[count
];
699 for ( int i
= 0; i
< count
; ++i
)
701 userLengths
[i
] = dashes
[i
];
703 m_pen
->SetDashPattern( userLengths
, count
);
704 delete[] userLengths
;
708 case wxPENSTYLE_STIPPLE
:
710 wxBitmap
* bmp
= pen
.GetStipple();
711 if ( bmp
&& bmp
->IsOk() )
713 m_penImage
= Bitmap::FromHBITMAP((HBITMAP
)bmp
->GetHBITMAP(),
715 (HPALETTE
)bmp
->GetPalette()->GetHPALETTE()
720 m_penBrush
= new TextureBrush(m_penImage
);
721 m_pen
->SetBrush( m_penBrush
);
727 if ( pen
.GetStyle() >= wxPENSTYLE_FIRST_HATCH
&&
728 pen
.GetStyle() <= wxPENSTYLE_LAST_HATCH
)
731 switch( pen
.GetStyle() )
733 case wxPENSTYLE_BDIAGONAL_HATCH
:
734 style
= HatchStyleBackwardDiagonal
;
736 case wxPENSTYLE_CROSSDIAG_HATCH
:
737 style
= HatchStyleDiagonalCross
;
739 case wxPENSTYLE_FDIAGONAL_HATCH
:
740 style
= HatchStyleForwardDiagonal
;
742 case wxPENSTYLE_CROSS_HATCH
:
743 style
= HatchStyleCross
;
745 case wxPENSTYLE_HORIZONTAL_HATCH
:
746 style
= HatchStyleHorizontal
;
748 case wxPENSTYLE_VERTICAL_HATCH
:
749 style
= HatchStyleVertical
;
752 style
= HatchStyleHorizontal
;
754 m_penBrush
= new HatchBrush
757 wxColourToColor(pen
.GetColour()),
760 m_pen
->SetBrush( m_penBrush
);
764 if ( dashStyle
!= DashStyleSolid
)
765 m_pen
->SetDashStyle(dashStyle
);
768 //-----------------------------------------------------------------------------
769 // wxGDIPlusBrush implementation
770 //-----------------------------------------------------------------------------
772 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
)
773 : wxGraphicsObjectRefData(renderer
)
778 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
)
779 : wxGraphicsObjectRefData(renderer
)
782 if ( brush
.GetStyle() == wxSOLID
)
784 m_brush
= new SolidBrush(wxColourToColor( brush
.GetColour()));
786 else if ( brush
.IsHatch() )
789 switch( brush
.GetStyle() )
791 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
792 style
= HatchStyleBackwardDiagonal
;
794 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
795 style
= HatchStyleDiagonalCross
;
797 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
798 style
= HatchStyleForwardDiagonal
;
800 case wxBRUSHSTYLE_CROSS_HATCH
:
801 style
= HatchStyleCross
;
803 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
804 style
= HatchStyleHorizontal
;
806 case wxBRUSHSTYLE_VERTICAL_HATCH
:
807 style
= HatchStyleVertical
;
810 style
= HatchStyleHorizontal
;
812 m_brush
= new HatchBrush
815 wxColourToColor(brush
.GetColour()),
821 wxBitmap
* bmp
= brush
.GetStipple();
822 if ( bmp
&& bmp
->IsOk() )
824 wxDELETE( m_brushImage
);
825 m_brushImage
= Bitmap::FromHBITMAP((HBITMAP
)bmp
->GetHBITMAP(),
827 (HPALETTE
)bmp
->GetPalette()->GetHPALETTE()
832 m_brush
= new TextureBrush(m_brushImage
);
837 wxGDIPlusBrushData::~wxGDIPlusBrushData()
844 void wxGDIPlusBrushData::Init()
851 template <typename T
>
853 wxGDIPlusBrushData::SetGradientStops(T
*brush
,
854 const wxGraphicsGradientStops
& stops
)
856 const unsigned numStops
= stops
.GetCount();
859 // initial and final colours are set during the brush creation, nothing
864 wxVector
<Color
> colors(numStops
);
865 wxVector
<REAL
> positions(numStops
);
867 for ( unsigned i
= 0; i
< numStops
; i
++ )
869 wxGraphicsGradientStop stop
= stops
.Item(i
);
871 colors
[i
] = wxColourToColor(stop
.GetColour());
872 positions
[i
] = stop
.GetPosition();
875 brush
->SetInterpolationColors(&colors
[0], &positions
[0], numStops
);
879 wxGDIPlusBrushData::CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
880 wxDouble x2
, wxDouble y2
,
881 const wxGraphicsGradientStops
& stops
)
883 LinearGradientBrush
* const
884 brush
= new LinearGradientBrush(PointF(x1
, y1
) , PointF(x2
, y2
),
885 wxColourToColor(stops
.GetStartColour()),
886 wxColourToColor(stops
.GetEndColour()));
889 SetGradientStops(brush
, stops
);
893 wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
894 wxDouble xc
, wxDouble yc
,
896 const wxGraphicsGradientStops
& stops
)
898 m_brushPath
= new GraphicsPath();
899 m_brushPath
->AddEllipse( (REAL
)(xc
-radius
), (REAL
)(yc
-radius
),
900 (REAL
)(2*radius
), (REAL
)(2*radius
));
902 PathGradientBrush
* const brush
= new PathGradientBrush(m_brushPath
);
904 brush
->SetCenterPoint(PointF(xo
, yo
));
905 brush
->SetCenterColor(wxColourToColor(stops
.GetStartColour()));
907 const Color
col(wxColourToColor(stops
.GetEndColour()));
909 brush
->SetSurroundColors(&col
, &count
);
911 SetGradientStops(brush
, stops
);
914 //-----------------------------------------------------------------------------
915 // wxGDIPlusFont implementation
916 //-----------------------------------------------------------------------------
919 wxGDIPlusFontData::Init(const wxString
& name
,
925 m_font
= new Font(name
.wc_str(), size
, style
, fontUnit
);
927 m_textBrush
= new SolidBrush(wxColourToColor(col
));
930 wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer
* renderer
,
932 const wxColour
& col
)
933 : wxGraphicsObjectRefData( renderer
)
935 int style
= FontStyleRegular
;
936 if ( font
.GetStyle() == wxFONTSTYLE_ITALIC
)
937 style
|= FontStyleItalic
;
938 if ( font
.GetUnderlined() )
939 style
|= FontStyleUnderline
;
940 if ( font
.GetWeight() == wxFONTWEIGHT_BOLD
)
941 style
|= FontStyleBold
;
943 Init(font
.GetFaceName(), font
.GetPointSize(), style
, col
, UnitPoint
);
946 wxGDIPlusFontData::wxGDIPlusFontData(wxGraphicsRenderer
* renderer
,
947 const wxString
& name
,
950 const wxColour
& col
) :
951 wxGraphicsObjectRefData(renderer
)
953 Init(name
, sizeInPixels
, style
, col
, UnitPixel
);
956 wxGDIPlusFontData::~wxGDIPlusFontData()
962 // the built-in conversions functions create non-premultiplied bitmaps, while GDIPlus needs them in the
963 // premultiplied format, therefore in the failing cases we create a new bitmap using the non-premultiplied
964 // bytes as parameter, since there is no real copying of the data going in, only references are stored
965 // m_helper has to be kept alive as well
967 //-----------------------------------------------------------------------------
968 // wxGDIPlusBitmapData implementation
969 //-----------------------------------------------------------------------------
971 wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, Bitmap
* bitmap
) :
972 wxGraphicsBitmapData( renderer
), m_bitmap( bitmap
)
977 wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
,
978 const wxBitmap
&bmp
) : wxGraphicsBitmapData( renderer
)
983 Bitmap
* image
= NULL
;
986 Bitmap
interim((HBITMAP
)bmp
.GetHBITMAP(),
988 (HPALETTE
)bmp
.GetPalette()->GetHPALETTE()
994 size_t width
= interim
.GetWidth();
995 size_t height
= interim
.GetHeight();
996 Rect
bounds(0,0,width
,height
);
998 image
= new Bitmap(width
,height
,PixelFormat32bppPARGB
) ;
1000 Bitmap
interimMask((HBITMAP
)bmp
.GetMask()->GetMaskBitmap(),NULL
);
1001 wxASSERT(interimMask
.GetPixelFormat() == PixelFormat1bppIndexed
);
1003 BitmapData dataMask
;
1004 interimMask
.LockBits(&bounds
,ImageLockModeRead
,
1005 interimMask
.GetPixelFormat(),&dataMask
);
1008 BitmapData imageData
;
1009 image
->LockBits(&bounds
,ImageLockModeWrite
, PixelFormat32bppPARGB
, &imageData
);
1011 BYTE maskPattern
= 0 ;
1015 for ( size_t y
= 0 ; y
< height
; ++y
)
1018 for( size_t x
= 0 ; x
< width
; ++x
)
1023 maskByte
= *((BYTE
*)dataMask
.Scan0
+ dataMask
.Stride
*y
+ maskIndex
);
1027 maskPattern
= maskPattern
>> 1;
1029 ARGB
*dest
= (ARGB
*)((BYTE
*)imageData
.Scan0
+ imageData
.Stride
*y
+ x
*4);
1030 if ( (maskByte
& maskPattern
) == 0 )
1035 interim
.GetPixel(x
,y
,&c
) ;
1036 *dest
= (c
.GetValue() | Color::AlphaMask
);
1041 image
->UnlockBits(&imageData
);
1043 interimMask
.UnlockBits(&dataMask
);
1044 interim
.UnlockBits(&dataMask
);
1048 image
= Bitmap::FromHBITMAP((HBITMAP
)bmp
.GetHBITMAP(),
1050 (HPALETTE
)bmp
.GetPalette()->GetHPALETTE()
1055 if ( bmp
.HasAlpha() && GetPixelFormatSize(image
->GetPixelFormat()) == 32 )
1057 size_t width
= image
->GetWidth();
1058 size_t height
= image
->GetHeight();
1059 Rect
bounds(0,0,width
,height
);
1060 static BitmapData data
;
1064 m_helper
->LockBits(&bounds
, ImageLockModeRead
,
1065 m_helper
->GetPixelFormat(),&data
);
1067 image
= new Bitmap(data
.Width
, data
.Height
, data
.Stride
,
1068 PixelFormat32bppPARGB
, (BYTE
*) data
.Scan0
);
1070 m_helper
->UnlockBits(&data
);
1079 wxImage
wxGDIPlusBitmapData::ConvertToImage() const
1081 // We could use Bitmap::LockBits() and convert to wxImage directly but
1082 // passing by wxBitmap is easier. It would be nice to measure performance
1083 // of the two methods but for this the second one would need to be written
1086 if ( m_bitmap
->GetHBITMAP(Color(0xffffffff), &hbmp
) != Gdiplus::Ok
)
1090 bmp
.SetWidth(m_bitmap
->GetWidth());
1091 bmp
.SetHeight(m_bitmap
->GetHeight());
1092 bmp
.SetHBITMAP(hbmp
);
1093 bmp
.SetDepth(IsAlphaPixelFormat(m_bitmap
->GetPixelFormat()) ? 32 : 24);
1094 return bmp
.ConvertToImage();
1097 #endif // wxUSE_IMAGE
1099 wxGDIPlusBitmapData::~wxGDIPlusBitmapData()
1105 //-----------------------------------------------------------------------------
1106 // wxGDIPlusPath implementation
1107 //-----------------------------------------------------------------------------
1109 wxGDIPlusPathData::wxGDIPlusPathData(wxGraphicsRenderer
* renderer
, GraphicsPath
* path
) : wxGraphicsPathData(renderer
)
1114 m_path
= new GraphicsPath();
1117 wxGDIPlusPathData::~wxGDIPlusPathData()
1122 wxGraphicsObjectRefData
* wxGDIPlusPathData::Clone() const
1124 return new wxGDIPlusPathData( GetRenderer() , m_path
->Clone());
1131 void wxGDIPlusPathData::MoveToPoint( wxDouble x
, wxDouble y
)
1133 m_path
->StartFigure();
1134 m_path
->AddLine((REAL
) x
,(REAL
) y
,(REAL
) x
,(REAL
) y
);
1137 void wxGDIPlusPathData::AddLineToPoint( wxDouble x
, wxDouble y
)
1139 m_path
->AddLine((REAL
) x
,(REAL
) y
,(REAL
) x
,(REAL
) y
);
1142 void wxGDIPlusPathData::CloseSubpath()
1144 m_path
->CloseFigure();
1147 void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1153 m_path
->GetLastPoint(&start
);
1154 m_path
->AddBezier(start
,c1
,c2
,end
);
1157 // gets the last point of the current path, (0,0) if not yet set
1158 void wxGDIPlusPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1161 m_path
->GetLastPoint(&start
);
1166 void wxGDIPlusPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, double startAngle
, double endAngle
, bool clockwise
)
1168 double sweepAngle
= endAngle
- startAngle
;
1169 if( fabs(sweepAngle
) >= 2*M_PI
)
1171 sweepAngle
= 2 * M_PI
;
1177 if( sweepAngle
< 0 )
1178 sweepAngle
+= 2 * M_PI
;
1182 if( sweepAngle
> 0 )
1183 sweepAngle
-= 2 * M_PI
;
1187 m_path
->AddArc((REAL
) (x
-r
),(REAL
) (y
-r
),(REAL
) (2*r
),(REAL
) (2*r
),RadToDeg(startAngle
),RadToDeg(sweepAngle
));
1190 void wxGDIPlusPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1192 m_path
->AddRectangle(RectF(x
,y
,w
,h
));
1195 void wxGDIPlusPathData::AddPath( const wxGraphicsPathData
* path
)
1197 m_path
->AddPath( (GraphicsPath
*) path
->GetNativePath(), FALSE
);
1201 // transforms each point of this path by the matrix
1202 void wxGDIPlusPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1204 m_path
->Transform( (Matrix
*) matrix
->GetNativeMatrix() );
1207 // gets the bounding box enclosing all points (possibly including control points)
1208 void wxGDIPlusPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1211 m_path
->GetBounds( &bounds
, NULL
, NULL
) ;
1218 bool wxGDIPlusPathData::Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
) const
1220 m_path
->SetFillMode( fillStyle
== wxODDEVEN_RULE
? FillModeAlternate
: FillModeWinding
);
1221 return m_path
->IsVisible( (FLOAT
) x
,(FLOAT
) y
) == TRUE
;
1224 //-----------------------------------------------------------------------------
1225 // wxGDIPlusMatrixData implementation
1226 //-----------------------------------------------------------------------------
1228 wxGDIPlusMatrixData::wxGDIPlusMatrixData(wxGraphicsRenderer
* renderer
, Matrix
* matrix
)
1229 : wxGraphicsMatrixData(renderer
)
1234 m_matrix
= new Matrix();
1237 wxGDIPlusMatrixData::~wxGDIPlusMatrixData()
1242 wxGraphicsObjectRefData
*wxGDIPlusMatrixData::Clone() const
1244 return new wxGDIPlusMatrixData( GetRenderer(), m_matrix
->Clone());
1247 // concatenates the matrix
1248 void wxGDIPlusMatrixData::Concat( const wxGraphicsMatrixData
*t
)
1250 m_matrix
->Multiply( (Matrix
*) t
->GetNativeMatrix());
1253 // sets the matrix to the respective values
1254 void wxGDIPlusMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
1255 wxDouble tx
, wxDouble ty
)
1257 m_matrix
->SetElements(a
,b
,c
,d
,tx
,ty
);
1260 // gets the component valuess of the matrix
1261 void wxGDIPlusMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
1262 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
1265 m_matrix
->GetElements(elements
);
1266 if (a
) *a
= elements
[0];
1267 if (b
) *b
= elements
[1];
1268 if (c
) *c
= elements
[2];
1269 if (d
) *d
= elements
[3];
1270 if (tx
) *tx
= elements
[4];
1271 if (ty
) *ty
= elements
[5];
1274 // makes this the inverse matrix
1275 void wxGDIPlusMatrixData::Invert()
1280 // returns true if the elements of the transformation matrix are equal ?
1281 bool wxGDIPlusMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
1283 return m_matrix
->Equals((Matrix
*) t
->GetNativeMatrix())== TRUE
;
1286 // return true if this is the identity matrix
1287 bool wxGDIPlusMatrixData::IsIdentity() const
1289 return m_matrix
->IsIdentity() == TRUE
;
1296 // add the translation to this matrix
1297 void wxGDIPlusMatrixData::Translate( wxDouble dx
, wxDouble dy
)
1299 m_matrix
->Translate(dx
,dy
);
1302 // add the scale to this matrix
1303 void wxGDIPlusMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
1305 m_matrix
->Scale(xScale
,yScale
);
1308 // add the rotation to this matrix (radians)
1309 void wxGDIPlusMatrixData::Rotate( wxDouble angle
)
1311 m_matrix
->Rotate( RadToDeg(angle
) );
1315 // apply the transforms
1318 // applies that matrix to the point
1319 void wxGDIPlusMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
1322 m_matrix
->TransformPoints(&pt
);
1327 // applies the matrix except for translations
1328 void wxGDIPlusMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
1331 m_matrix
->TransformVectors(&pt
);
1336 // returns the native representation
1337 void * wxGDIPlusMatrixData::GetNativeMatrix() const
1342 //-----------------------------------------------------------------------------
1343 // wxGDIPlusContext implementation
1344 //-----------------------------------------------------------------------------
1346 class wxGDIPlusOffsetHelper
1349 wxGDIPlusOffsetHelper( Graphics
* gr
, bool offset
)
1354 m_gr
->TranslateTransform( 0.5, 0.5 );
1356 ~wxGDIPlusOffsetHelper( )
1359 m_gr
->TranslateTransform( -0.5, -0.5 );
1366 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HDC hdc
, wxDouble width
, wxDouble height
)
1367 : wxGraphicsContext(renderer
)
1369 Init(new Graphics(hdc
), width
, height
);
1372 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
)
1373 : wxGraphicsContext(renderer
)
1375 wxMSWDCImpl
*msw
= wxDynamicCast( dc
.GetImpl() , wxMSWDCImpl
);
1376 HDC hdc
= (HDC
) msw
->GetHDC();
1377 wxSize sz
= dc
.GetSize();
1379 Init(new Graphics(hdc
), sz
.x
, sz
.y
);
1382 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HWND hwnd
)
1383 : wxGraphicsContext(renderer
)
1385 RECT rect
= wxGetWindowRect(hwnd
);
1386 Init(new Graphics(hwnd
), rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
1387 m_enableOffset
= true;
1390 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, Graphics
* gr
)
1391 : wxGraphicsContext(renderer
)
1396 wxGDIPlusContext::wxGDIPlusContext(wxGraphicsRenderer
* renderer
)
1397 : wxGraphicsContext(renderer
)
1399 // Derived class must call Init() later but just set m_context to NULL for
1400 // safety to avoid crashing in our dtor if Init() ends up not being called.
1404 void wxGDIPlusContext::Init(Graphics
* graphics
, int width
, int height
)
1406 m_context
= graphics
;
1411 m_fontScaleRatio
= 1.0;
1413 m_context
->SetTextRenderingHint(TextRenderingHintSystemDefault
);
1414 m_context
->SetPixelOffsetMode(PixelOffsetModeHalf
);
1415 m_context
->SetSmoothingMode(SmoothingModeHighQuality
);
1416 m_context
->SetInterpolationMode(InterpolationModeHighQuality
);
1417 m_state1
= m_context
->Save();
1418 m_state2
= m_context
->Save();
1421 wxGDIPlusContext::~wxGDIPlusContext()
1425 m_context
->Restore( m_state2
);
1426 m_context
->Restore( m_state1
);
1432 void wxGDIPlusContext::Clip( const wxRegion
®ion
)
1434 Region
rgn((HRGN
)region
.GetHRGN());
1435 m_context
->SetClip(&rgn
,CombineModeIntersect
);
1438 void wxGDIPlusContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1440 m_context
->SetClip(RectF(x
,y
,w
,h
),CombineModeIntersect
);
1443 void wxGDIPlusContext::ResetClip()
1445 m_context
->ResetClip();
1448 void wxGDIPlusContext::DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1450 if (m_composition
== wxCOMPOSITION_DEST
)
1453 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1454 Brush
*brush
= m_brush
.IsNull() ? NULL
: ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush();
1455 Pen
*pen
= m_pen
.IsNull() ? NULL
: ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen();
1459 // the offset is used to fill only the inside of the rectangle and not paint underneath
1460 // its border which may influence a transparent Pen
1463 offset
= pen
->GetWidth();
1464 m_context
->FillRectangle( brush
, (REAL
)x
+ offset
/2, (REAL
)y
+ offset
/2, (REAL
)w
- offset
, (REAL
)h
- offset
);
1469 m_context
->DrawRectangle( pen
, (REAL
)x
, (REAL
)y
, (REAL
)w
, (REAL
)h
);
1473 void wxGDIPlusContext::StrokeLines( size_t n
, const wxPoint2DDouble
*points
)
1475 if (m_composition
== wxCOMPOSITION_DEST
)
1478 if ( !m_pen
.IsNull() )
1480 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1481 Point
*cpoints
= new Point
[n
];
1482 for (size_t i
= 0; i
< n
; i
++)
1484 cpoints
[i
].X
= (int)(points
[i
].m_x
);
1485 cpoints
[i
].Y
= (int)(points
[i
].m_y
);
1487 } // for (size_t i = 0; i < n; i++)
1488 m_context
->DrawLines( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , cpoints
, n
) ;
1493 void wxGDIPlusContext::DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode
WXUNUSED(fillStyle
) )
1495 if (m_composition
== wxCOMPOSITION_DEST
)
1498 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1499 Point
*cpoints
= new Point
[n
];
1500 for (size_t i
= 0; i
< n
; i
++)
1502 cpoints
[i
].X
= (int)(points
[i
].m_x
);
1503 cpoints
[i
].Y
= (int)(points
[i
].m_y
);
1505 } // for (int i = 0; i < n; i++)
1506 if ( !m_brush
.IsNull() )
1507 m_context
->FillPolygon( ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush() , cpoints
, n
) ;
1508 if ( !m_pen
.IsNull() )
1509 m_context
->DrawLines( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , cpoints
, n
) ;
1513 void wxGDIPlusContext::StrokePath( const wxGraphicsPath
& path
)
1515 if (m_composition
== wxCOMPOSITION_DEST
)
1518 if ( !m_pen
.IsNull() )
1520 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1521 m_context
->DrawPath( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath
*) path
.GetNativePath() );
1525 void wxGDIPlusContext::FillPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
)
1527 if (m_composition
== wxCOMPOSITION_DEST
)
1530 if ( !m_brush
.IsNull() )
1532 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1533 ((GraphicsPath
*) path
.GetNativePath())->SetFillMode( fillStyle
== wxODDEVEN_RULE
? FillModeAlternate
: FillModeWinding
);
1534 m_context
->FillPath( ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush() ,
1535 (GraphicsPath
*) path
.GetNativePath());
1539 bool wxGDIPlusContext::SetAntialiasMode(wxAntialiasMode antialias
)
1541 if (m_antialias
== antialias
)
1544 m_antialias
= antialias
;
1546 SmoothingMode antialiasMode
;
1549 case wxANTIALIAS_DEFAULT
:
1550 antialiasMode
= SmoothingModeHighQuality
;
1552 case wxANTIALIAS_NONE
:
1553 antialiasMode
= SmoothingModeNone
;
1558 m_context
->SetSmoothingMode(antialiasMode
);
1562 bool wxGDIPlusContext::SetInterpolationQuality(wxInterpolationQuality interpolation
)
1564 if (m_interpolation
== interpolation
)
1567 InterpolationMode interpolationMode
= InterpolationModeDefault
;
1568 switch (interpolation
)
1570 case wxINTERPOLATION_DEFAULT
:
1571 interpolationMode
= InterpolationModeDefault
;
1574 case wxINTERPOLATION_NONE
:
1575 interpolationMode
= InterpolationModeNearestNeighbor
;
1578 case wxINTERPOLATION_FAST
:
1579 interpolationMode
= InterpolationModeLowQuality
;
1582 case wxINTERPOLATION_GOOD
:
1583 interpolationMode
= InterpolationModeHighQuality
;
1586 case wxINTERPOLATION_BEST
:
1587 interpolationMode
= InterpolationModeHighQualityBicubic
;
1594 if ( m_context
->SetInterpolationMode(interpolationMode
) != Gdiplus::Ok
)
1597 m_interpolation
= interpolation
;
1602 bool wxGDIPlusContext::SetCompositionMode(wxCompositionMode op
)
1604 if ( m_composition
== op
)
1609 if (m_composition
== wxCOMPOSITION_DEST
)
1612 CompositingMode cop
;
1615 case wxCOMPOSITION_SOURCE
:
1616 cop
= CompositingModeSourceCopy
;
1618 case wxCOMPOSITION_OVER
:
1619 cop
= CompositingModeSourceOver
;
1625 m_context
->SetCompositingMode(cop
);
1629 void wxGDIPlusContext::BeginLayer(wxDouble
/* opacity */)
1634 void wxGDIPlusContext::EndLayer()
1639 void wxGDIPlusContext::Rotate( wxDouble angle
)
1641 m_context
->RotateTransform( RadToDeg(angle
) );
1644 void wxGDIPlusContext::Translate( wxDouble dx
, wxDouble dy
)
1646 m_context
->TranslateTransform( dx
, dy
);
1649 void wxGDIPlusContext::Scale( wxDouble xScale
, wxDouble yScale
)
1651 m_context
->ScaleTransform(xScale
,yScale
);
1654 void wxGDIPlusContext::PushState()
1656 GraphicsState state
= m_context
->Save();
1657 m_stateStack
.push(state
);
1660 void wxGDIPlusContext::PopState()
1662 wxCHECK_RET( !m_stateStack
.empty(), wxT("No state to pop") );
1664 GraphicsState state
= m_stateStack
.top();
1666 m_context
->Restore(state
);
1669 void wxGDIPlusContext::DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1671 if (m_composition
== wxCOMPOSITION_DEST
)
1674 Bitmap
* image
= static_cast<wxGDIPlusBitmapData
*>(bmp
.GetRefData())->GetGDIPlusBitmap();
1677 if( image
->GetWidth() != (UINT
) w
|| image
->GetHeight() != (UINT
) h
)
1679 Rect
drawRect((REAL
) x
, (REAL
)y
, (REAL
)w
, (REAL
)h
);
1680 m_context
->SetPixelOffsetMode( PixelOffsetModeNone
);
1681 m_context
->DrawImage(image
, drawRect
, 0 , 0 , image
->GetWidth(), image
->GetHeight(), UnitPixel
) ;
1682 m_context
->SetPixelOffsetMode( PixelOffsetModeHalf
);
1685 m_context
->DrawImage(image
,(REAL
) x
,(REAL
) y
,(REAL
) w
,(REAL
) h
) ;
1689 void wxGDIPlusContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1691 wxGraphicsBitmap bitmap
= GetRenderer()->CreateBitmap(bmp
);
1692 DrawBitmap(bitmap
, x
, y
, w
, h
);
1695 void wxGDIPlusContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1697 if (m_composition
== wxCOMPOSITION_DEST
)
1700 // the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only
1701 // find out by looking at the bitmap data whether there really was alpha in it
1702 HICON hIcon
= (HICON
)icon
.GetHICON();
1704 // IconInfo creates the bitmaps for color and mask, we must dispose of them after use
1705 if (!GetIconInfo(hIcon
,&iconInfo
))
1708 Bitmap
interim(iconInfo
.hbmColor
,NULL
);
1710 Bitmap
* image
= NULL
;
1712 // if it's not 32 bit, it doesn't have an alpha channel, note that since the conversion doesn't
1713 // work correctly, asking IsAlphaPixelFormat at this point fails as well
1714 if( GetPixelFormatSize(interim
.GetPixelFormat())!= 32 )
1716 image
= Bitmap::FromHICON(hIcon
);
1720 size_t width
= interim
.GetWidth();
1721 size_t height
= interim
.GetHeight();
1722 Rect
bounds(0,0,width
,height
);
1725 interim
.LockBits(&bounds
, ImageLockModeRead
,
1726 interim
.GetPixelFormat(),&data
);
1728 bool hasAlpha
= false;
1729 for ( size_t y
= 0 ; y
< height
&& !hasAlpha
; ++y
)
1731 for( size_t x
= 0 ; x
< width
&& !hasAlpha
; ++x
)
1733 ARGB
*dest
= (ARGB
*)((BYTE
*)data
.Scan0
+ data
.Stride
*y
+ x
*4);
1734 if ( ( *dest
& Color::AlphaMask
) != 0 )
1741 image
= new Bitmap(data
.Width
, data
.Height
, data
.Stride
,
1742 PixelFormat32bppARGB
, (BYTE
*) data
.Scan0
);
1746 image
= Bitmap::FromHICON(hIcon
);
1749 interim
.UnlockBits(&data
);
1752 m_context
->DrawImage(image
,(REAL
) x
,(REAL
) y
,(REAL
) w
,(REAL
) h
) ;
1755 DeleteObject(iconInfo
.hbmColor
);
1756 DeleteObject(iconInfo
.hbmMask
);
1759 void wxGDIPlusContext::DoDrawText(const wxString
& str
,
1760 wxDouble x
, wxDouble y
)
1762 if (m_composition
== wxCOMPOSITION_DEST
)
1765 wxCHECK_RET( !m_font
.IsNull(),
1766 wxT("wxGDIPlusContext::DrawText - no valid font set") );
1771 wxGDIPlusFontData
* const
1772 fontData
= (wxGDIPlusFontData
*)m_font
.GetRefData();
1774 m_context
->DrawString
1776 str
.wc_str(*wxConvUI
), // string to draw, always Unicode
1777 -1, // length: string is NUL-terminated
1778 fontData
->GetGDIPlusFont(),
1780 GetDrawTextStringFormat(),
1781 fontData
->GetGDIPlusBrush()
1785 void wxGDIPlusContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1786 wxDouble
*descent
, wxDouble
*externalLeading
) const
1788 wxCHECK_RET( !m_font
.IsNull(), wxT("wxGDIPlusContext::GetTextExtent - no valid font set") );
1790 wxWCharBuffer s
= str
.wc_str( *wxConvUI
);
1791 FontFamily ffamily
;
1792 Font
* f
= ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont();
1794 f
->GetFamily(&ffamily
) ;
1796 REAL factorY
= m_fontScaleRatio
;
1798 // Notice that we must use the real font style or the results would be
1799 // incorrect for italic/bold fonts.
1800 const INT style
= f
->GetStyle();
1801 const REAL size
= f
->GetSize();
1802 const REAL emHeight
= ffamily
.GetEmHeight(style
);
1803 REAL rDescent
= ffamily
.GetCellDescent(style
) * size
/ emHeight
;
1804 REAL rAscent
= ffamily
.GetCellAscent(style
) * size
/ emHeight
;
1805 REAL rHeight
= ffamily
.GetLineSpacing(style
) * size
/ emHeight
;
1808 *height
= rHeight
* factorY
;
1810 *descent
= rDescent
* factorY
;
1811 if ( externalLeading
)
1812 *externalLeading
= (rHeight
- rAscent
- rDescent
) * factorY
;
1813 // measuring empty strings is not guaranteed, so do it by hand
1821 RectF
layoutRect(0,0, 100000.0f
, 100000.0f
);
1824 m_context
->MeasureString((const wchar_t *) s
, wcslen(s
) , f
, layoutRect
, GetDrawTextStringFormat(), &bounds
) ;
1826 *width
= bounds
.Width
;
1828 *height
= bounds
.Height
;
1832 void wxGDIPlusContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1835 widths
.Add(0, text
.length());
1837 wxCHECK_RET( !m_font
.IsNull(), wxT("wxGDIPlusContext::GetPartialTextExtents - no valid font set") );
1842 Font
* f
= ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont();
1843 wxWCharBuffer ws
= text
.wc_str( *wxConvUI
);
1844 size_t len
= wcslen( ws
) ;
1845 wxASSERT_MSG(text
.length() == len
, wxT("GetPartialTextExtents not yet implemented for multichar situations"));
1847 RectF
layoutRect(0,0, 100000.0f
, 100000.0f
);
1848 StringFormat
strFormat( GetDrawTextStringFormat() );
1850 size_t startPosition
= 0;
1851 size_t remainder
= len
;
1852 const size_t maxSpan
= 32;
1853 CharacterRange
* ranges
= new CharacterRange
[maxSpan
] ;
1854 Region
* regions
= new Region
[maxSpan
];
1856 while( remainder
> 0 )
1858 size_t span
= wxMin( maxSpan
, remainder
);
1860 for( size_t i
= 0 ; i
< span
; ++i
)
1862 ranges
[i
].First
= 0 ;
1863 ranges
[i
].Length
= startPosition
+i
+1 ;
1865 strFormat
.SetMeasurableCharacterRanges(span
,ranges
);
1866 m_context
->MeasureCharacterRanges(ws
, -1 , f
,layoutRect
, &strFormat
,span
,regions
) ;
1869 for ( size_t i
= 0 ; i
< span
; ++i
)
1871 regions
[i
].GetBounds(&bbox
,m_context
);
1872 widths
[startPosition
+i
] = bbox
.Width
;
1875 startPosition
+= span
;
1882 bool wxGDIPlusContext::ShouldOffset() const
1884 if ( !m_enableOffset
)
1888 if ( !m_pen
.IsNull() )
1890 penwidth
= (int)((wxGDIPlusPenData
*)m_pen
.GetRefData())->GetWidth();
1891 if ( penwidth
== 0 )
1894 return ( penwidth
% 2 ) == 1;
1897 void* wxGDIPlusContext::GetNativeContext()
1902 // concatenates this transform with the current transform of this context
1903 void wxGDIPlusContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1905 m_context
->MultiplyTransform((Matrix
*) matrix
.GetNativeMatrix());
1908 // sets the transform of this context
1909 void wxGDIPlusContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1911 m_context
->SetTransform((Matrix
*) matrix
.GetNativeMatrix());
1914 // gets the matrix of this context
1915 wxGraphicsMatrix
wxGDIPlusContext::GetTransform() const
1917 wxGraphicsMatrix matrix
= CreateMatrix();
1918 m_context
->GetTransform((Matrix
*) matrix
.GetNativeMatrix());
1922 void wxGDIPlusContext::GetSize( wxDouble
* width
, wxDouble
*height
)
1928 //-----------------------------------------------------------------------------
1929 // wxGDIPlusPrintingContext implementation
1930 //-----------------------------------------------------------------------------
1932 wxGDIPlusPrintingContext::wxGDIPlusPrintingContext( wxGraphicsRenderer
* renderer
,
1934 : wxGDIPlusContext(renderer
, dc
)
1936 Graphics
* context
= GetGraphics();
1938 //m_context->SetPageUnit(UnitDocument);
1940 // Setup page scale, based on DPI ratio.
1941 // Antecedent should be 100dpi when the default page unit
1942 // (UnitDisplay) is used. Page unit UnitDocument would require 300dpi
1943 // instead. Note that calling SetPageScale() does not have effect on
1944 // non-printing DCs (that is, any other than wxPrinterDC or
1945 // wxEnhMetaFileDC).
1946 REAL dpiRatio
= 100.0 / context
->GetDpiY();
1947 context
->SetPageScale(dpiRatio
);
1949 // We use this modifier when measuring fonts. It is needed because the
1950 // page scale is modified above.
1951 m_fontScaleRatio
= context
->GetDpiY() / 72.0;
1954 //-----------------------------------------------------------------------------
1955 // wxGDIPlusRenderer implementation
1956 //-----------------------------------------------------------------------------
1958 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRenderer
,wxGraphicsRenderer
)
1960 static wxGDIPlusRenderer gs_GDIPlusRenderer
;
1962 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
1964 return &gs_GDIPlusRenderer
;
1967 bool wxGDIPlusRenderer::EnsureIsLoaded()
1969 // load gdiplus.dll if not yet loaded, but don't bother doing it again
1970 // if we already tried and failed (we don't want to spend lot of time
1971 // returning NULL from wxGraphicsContext::Create(), which may be called
1972 // relatively frequently):
1973 if ( m_loaded
== -1 )
1978 return m_loaded
== 1;
1981 // call EnsureIsLoaded() and return returnOnFail value if it fails
1982 #define ENSURE_LOADED_OR_RETURN(returnOnFail) \
1983 if ( !EnsureIsLoaded() ) \
1984 return (returnOnFail)
1987 void wxGDIPlusRenderer::Load()
1989 GdiplusStartupInput input
;
1990 GdiplusStartupOutput output
;
1991 if ( GdiplusStartup(&m_gditoken
,&input
,&output
) == Gdiplus::Ok
)
1993 wxLogTrace("gdiplus", "successfully initialized GDI+");
1998 wxLogTrace("gdiplus", "failed to initialize GDI+, missing gdiplus.dll?");
2003 void wxGDIPlusRenderer::Unload()
2007 GdiplusShutdown(m_gditoken
);
2010 m_loaded
= -1; // next Load() will try again
2013 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxWindowDC
& dc
)
2015 ENSURE_LOADED_OR_RETURN(NULL
);
2016 wxGDIPlusContext
* context
= new wxGDIPlusContext(this, dc
);
2017 context
->EnableOffset(true);
2021 #if wxUSE_PRINTING_ARCHITECTURE
2022 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxPrinterDC
& dc
)
2024 ENSURE_LOADED_OR_RETURN(NULL
);
2025 wxGDIPlusContext
* context
= new wxGDIPlusPrintingContext(this, dc
);
2030 #if wxUSE_ENH_METAFILE
2031 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxEnhMetaFileDC
& dc
)
2033 ENSURE_LOADED_OR_RETURN(NULL
);
2034 wxGDIPlusContext
* context
= new wxGDIPlusPrintingContext(this, dc
);
2039 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxMemoryDC
& dc
)
2041 ENSURE_LOADED_OR_RETURN(NULL
);
2042 wxGDIPlusContext
* context
= new wxGDIPlusContext(this, dc
);
2043 context
->EnableOffset(true);
2048 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromImage(wxImage
& image
)
2050 ENSURE_LOADED_OR_RETURN(NULL
);
2051 wxGDIPlusContext
* context
= new wxGDIPlusImageContext(this, image
);
2052 context
->EnableOffset(true);
2056 #endif // wxUSE_IMAGE
2058 wxGraphicsContext
* wxGDIPlusRenderer::CreateMeasuringContext()
2060 ENSURE_LOADED_OR_RETURN(NULL
);
2061 return new wxGDIPlusMeasuringContext(this);
2064 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromNativeContext( void * context
)
2066 ENSURE_LOADED_OR_RETURN(NULL
);
2067 return new wxGDIPlusContext(this,(Graphics
*) context
);
2071 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window
)
2073 ENSURE_LOADED_OR_RETURN(NULL
);
2074 return new wxGDIPlusContext(this,(HWND
) window
);
2077 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( wxWindow
* window
)
2079 ENSURE_LOADED_OR_RETURN(NULL
);
2080 return new wxGDIPlusContext(this, (HWND
) window
->GetHWND() );
2085 wxGraphicsPath
wxGDIPlusRenderer::CreatePath()
2087 ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath
);
2089 m
.SetRefData( new wxGDIPlusPathData(this));
2096 wxGraphicsMatrix
wxGDIPlusRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2097 wxDouble tx
, wxDouble ty
)
2100 ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix
);
2102 wxGDIPlusMatrixData
* data
= new wxGDIPlusMatrixData( this );
2103 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2108 wxGraphicsPen
wxGDIPlusRenderer::CreatePen(const wxPen
& pen
)
2110 ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen
);
2111 if ( !pen
.IsOk() || pen
.GetStyle() == wxTRANSPARENT
)
2112 return wxNullGraphicsPen
;
2116 p
.SetRefData(new wxGDIPlusPenData( this, pen
));
2121 wxGraphicsBrush
wxGDIPlusRenderer::CreateBrush(const wxBrush
& brush
)
2123 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2124 if ( !brush
.IsOk() || brush
.GetStyle() == wxTRANSPARENT
)
2125 return wxNullGraphicsBrush
;
2129 p
.SetRefData(new wxGDIPlusBrushData( this, brush
));
2135 wxGDIPlusRenderer::CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
2136 wxDouble x2
, wxDouble y2
,
2137 const wxGraphicsGradientStops
& stops
)
2139 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2141 wxGDIPlusBrushData
* d
= new wxGDIPlusBrushData( this );
2142 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, stops
);
2148 wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
2149 wxDouble xc
, wxDouble yc
,
2151 const wxGraphicsGradientStops
& stops
)
2153 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2155 wxGDIPlusBrushData
* d
= new wxGDIPlusBrushData( this );
2156 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,stops
);
2162 wxGDIPlusRenderer::CreateFont( const wxFont
&font
,
2163 const wxColour
&col
)
2165 ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont
);
2169 p
.SetRefData(new wxGDIPlusFontData( this, font
, col
));
2173 return wxNullGraphicsFont
;
2177 wxGDIPlusRenderer::CreateFont(double size
,
2178 const wxString
& facename
,
2180 const wxColour
& col
)
2182 ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont
);
2184 // Convert wxFont flags to GDI+ style:
2185 int style
= FontStyleRegular
;
2186 if ( flags
& wxFONTFLAG_ITALIC
)
2187 style
|= FontStyleItalic
;
2188 if ( flags
& wxFONTFLAG_UNDERLINED
)
2189 style
|= FontStyleUnderline
;
2190 if ( flags
& wxFONTFLAG_BOLD
)
2191 style
|= FontStyleBold
;
2192 if ( flags
& wxFONTFLAG_STRIKETHROUGH
)
2193 style
|= FontStyleStrikeout
;
2197 f
.SetRefData(new wxGDIPlusFontData(this, facename
, size
, style
, col
));
2201 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmap( const wxBitmap
&bitmap
)
2203 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2204 if ( bitmap
.IsOk() )
2207 p
.SetRefData(new wxGDIPlusBitmapData( this , bitmap
));
2211 return wxNullGraphicsBitmap
;
2216 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmapFromImage(const wxImage
& image
)
2218 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2221 // Notice that we rely on conversion from wxImage to wxBitmap here but
2222 // we could probably do it more efficiently by converting from wxImage
2223 // to GDI+ Bitmap directly, i.e. copying wxImage pixels to the buffer
2224 // returned by Bitmap::LockBits(). However this would require writing
2225 // code specific for this task while like this we can reuse existing
2226 // code (see also wxGDIPlusBitmapData::ConvertToImage()).
2227 wxGraphicsBitmap gb
;
2228 gb
.SetRefData(new wxGDIPlusBitmapData(this, image
));
2232 return wxNullGraphicsBitmap
;
2236 wxImage
wxGDIPlusRenderer::CreateImageFromBitmap(const wxGraphicsBitmap
& bmp
)
2238 ENSURE_LOADED_OR_RETURN(wxNullImage
);
2239 const wxGDIPlusBitmapData
* const
2240 data
= static_cast<wxGDIPlusBitmapData
*>(bmp
.GetGraphicsData());
2242 return data
? data
->ConvertToImage() : wxNullImage
;
2245 #endif // wxUSE_IMAGE
2248 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap
)
2250 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2251 if ( bitmap
!= NULL
)
2254 p
.SetRefData(new wxGDIPlusBitmapData( this , (Bitmap
*) bitmap
));
2258 return wxNullGraphicsBitmap
;
2261 wxGraphicsBitmap
wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
2263 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2264 Bitmap
* image
= static_cast<wxGDIPlusBitmapData
*>(bitmap
.GetRefData())->GetGDIPlusBitmap();
2268 p
.SetRefData(new wxGDIPlusBitmapData( this , image
->Clone( (REAL
) x
, (REAL
) y
, (REAL
) w
, (REAL
) h
, PixelFormat32bppPARGB
) ));
2272 return wxNullGraphicsBitmap
;
2275 // Shutdown GDI+ at app exit, before possible dll unload
2276 class wxGDIPlusRendererModule
: public wxModule
2279 virtual bool OnInit() { return true; }
2280 virtual void OnExit()
2282 wxDELETE(gs_drawTextStringFormat
);
2284 gs_GDIPlusRenderer
.Unload();
2288 DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule
)
2291 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule
, wxModule
)
2293 // ----------------------------------------------------------------------------
2294 // wxMSW-specific parts of wxGCDC
2295 // ----------------------------------------------------------------------------
2297 WXHDC
wxGCDC::AcquireHDC()
2299 wxGraphicsContext
* const gc
= GetGraphicsContext();
2304 // we can't get the HDC if it is not a GDI+ context
2305 wxGraphicsRenderer
* r1
= gc
->GetRenderer();
2306 wxGraphicsRenderer
* r2
= wxGraphicsRenderer::GetCairoRenderer();
2311 Graphics
* const g
= static_cast<Graphics
*>(gc
->GetNativeContext());
2312 return g
? g
->GetHDC() : NULL
;
2315 void wxGCDC::ReleaseHDC(WXHDC hdc
)
2320 wxGraphicsContext
* const gc
= GetGraphicsContext();
2321 wxCHECK_RET( gc
, "can't release HDC because there is no wxGraphicsContext" );
2324 // we can't get the HDC if it is not a GDI+ context
2325 wxGraphicsRenderer
* r1
= gc
->GetRenderer();
2326 wxGraphicsRenderer
* r2
= wxGraphicsRenderer::GetCairoRenderer();
2331 Graphics
* const g
= static_cast<Graphics
*>(gc
->GetNativeContext());
2332 wxCHECK_RET( g
, "can't release HDC because there is no Graphics" );
2334 g
->ReleaseHDC((HDC
)hdc
);
2337 #endif // wxUSE_GRAPHICS_CONTEXT