1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/graphicc.cpp
3 // Purpose: cairo device context class
4 // Author: Stefan Csomor
8 // Copyright: (c) 2006 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
22 #include "wx/window.h"
25 #include "wx/dialog.h"
27 #include "wx/bitmap.h"
28 #include "wx/dcmemory.h"
31 #include "wx/dcprint.h"
32 #include "wx/module.h"
39 #include "wx/graphics.h"
40 #include "wx/rawbmp.h"
42 #if wxUSE_GRAPHICS_CONTEXT
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 const double RAD2DEG
= 180.0 / M_PI
;
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 static inline double dmin(double a
, double b
)
62 static inline double dmax(double a
, double b
)
67 static inline double DegToRad(double deg
)
69 return (deg
* M_PI
) / 180.0;
71 static inline double RadToDeg(double deg
)
73 return (deg
* 180.0) / M_PI
;
76 //-----------------------------------------------------------------------------
77 // device context implementation
79 // more and more of the dc functionality should be implemented by calling
80 // the appropricate wxCairoContext, but we will have to do that step by step
81 // also coordinate conversions should be moved to native matrix ops
82 //-----------------------------------------------------------------------------
84 // we always stock two context states, one at entry, to be able to preserve the
85 // state we were called with, the other one after changing to HI Graphics orientation
86 // (this one is used for getting back clippings etc)
88 //-----------------------------------------------------------------------------
89 // wxGraphicsPath implementation
90 //-----------------------------------------------------------------------------
92 // TODO remove this dependency (gdiplus needs the macros)
95 #define max(a,b) (((a) > (b)) ? (a) : (b))
99 #define min(a,b) (((a) < (b)) ? (a) : (b))
104 #include "wx/gtk/win_gtk.h"
109 #include <cairo-win32.h>
113 #include "wx/mac/private.h"
114 #include <cairo-quartz.h>
115 #include <cairo-atsui.h>
118 class WXDLLIMPEXP_CORE wxCairoPathData
: public wxGraphicsPathData
121 wxCairoPathData(wxGraphicsRenderer
* renderer
, cairo_t
* path
= NULL
);
124 virtual wxGraphicsObjectRefData
*Clone() const;
127 // These are the path primitives from which everything else can be constructed
130 // begins a new subpath at (x,y)
131 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
133 // adds a straight line from the current point to (x,y)
134 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
136 // adds a cubic Bezier curve from the current point, using two control points and an end point
137 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
140 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
141 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
) ;
143 // gets the last point of the current path, (0,0) if not yet set
144 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
147 virtual void AddPath( const wxGraphicsPathData
* path
);
149 // closes the current sub-path
150 virtual void CloseSubpath();
153 // These are convenience functions which - if not available natively will be assembled
154 // using the primitives from above
159 // appends a rectangle as a new closed subpath
160 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) ;
161 // appends an ellipsis as a new closed subpath fitting the passed rectangle
162 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
164 // 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)
165 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
168 // returns the native path
169 virtual void * GetNativePath() const ;
171 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
172 virtual void UnGetNativePath(void *p
) const;
174 // transforms each point of this path by the matrix
175 virtual void Transform( const wxGraphicsMatrixData
* matrix
) ;
177 // gets the bounding box enclosing all points (possibly including control points)
178 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const;
180 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxWINDING_RULE
) const;
183 cairo_t
* m_pathContext
;
186 class WXDLLIMPEXP_CORE wxCairoMatrixData
: public wxGraphicsMatrixData
189 wxCairoMatrixData(wxGraphicsRenderer
* renderer
, const cairo_matrix_t
* matrix
= NULL
) ;
190 virtual ~wxCairoMatrixData() ;
192 virtual wxGraphicsObjectRefData
*Clone() const ;
194 // concatenates the matrix
195 virtual void Concat( const wxGraphicsMatrixData
*t
);
197 // sets the matrix to the respective values
198 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
199 wxDouble tx
=0.0, wxDouble ty
=0.0);
201 // gets the component valuess of the matrix
202 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
203 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
205 // makes this the inverse matrix
206 virtual void Invert();
208 // returns true if the elements of the transformation matrix are equal ?
209 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
211 // return true if this is the identity matrix
212 virtual bool IsIdentity() const;
218 // add the translation to this matrix
219 virtual void Translate( wxDouble dx
, wxDouble dy
);
221 // add the scale to this matrix
222 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
224 // add the rotation to this matrix (radians)
225 virtual void Rotate( wxDouble angle
);
228 // apply the transforms
231 // applies that matrix to the point
232 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
234 // applies the matrix except for translations
235 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
237 // returns the native representation
238 virtual void * GetNativeMatrix() const;
240 cairo_matrix_t m_matrix
;
243 class WXDLLIMPEXP_CORE wxCairoPenData
: public wxGraphicsObjectRefData
246 wxCairoPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
251 virtual void Apply( wxGraphicsContext
* context
);
252 virtual wxDouble
GetWidth() { return m_width
; }
262 cairo_line_cap_t m_cap
;
263 cairo_line_join_t m_join
;
266 const double *m_lengths
;
267 double *m_userLengths
;
272 class WXDLLIMPEXP_CORE wxCairoBrushData
: public wxGraphicsObjectRefData
275 wxCairoBrushData( wxGraphicsRenderer
* renderer
);
276 wxCairoBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
277 ~wxCairoBrushData ();
279 virtual void Apply( wxGraphicsContext
* context
);
280 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
281 const wxColour
&c1
, const wxColour
&c2
);
282 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
283 const wxColour
&oColor
, const wxColour
&cColor
);
294 cairo_pattern_t
* m_brushPattern
;
297 class wxCairoFontData
: public wxGraphicsObjectRefData
300 wxCairoFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
303 virtual void Apply( wxGraphicsContext
* context
);
305 wxCharBuffer m_fontName
;
307 cairo_font_slant_t m_slant
;
308 cairo_font_weight_t m_weight
;
313 cairo_font_face_t
*m_font
;
317 class WXDLLIMPEXP_CORE wxCairoContext
: public wxGraphicsContext
319 DECLARE_NO_COPY_CLASS(wxCairoContext
)
322 wxCairoContext( wxGraphicsRenderer
* renderer
, const wxWindowDC
& dc
);
324 wxCairoContext( wxGraphicsRenderer
* renderer
, GdkDrawable
*drawable
);
326 wxCairoContext( wxGraphicsRenderer
* renderer
, cairo_t
*context
);
327 wxCairoContext( wxGraphicsRenderer
* renderer
, wxWindow
*window
);
329 virtual ~wxCairoContext();
331 virtual bool ShouldOffset() const
334 if ( !m_pen
.IsNull() )
336 penwidth
= (int)((wxCairoPenData
*)m_pen
.GetRefData())->GetWidth();
340 return ( penwidth
% 2 ) == 1;
343 virtual void Clip( const wxRegion
®ion
);
345 // clips drawings to the rect
346 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
348 // resets the clipping to original extent
349 virtual void ResetClip();
351 virtual void * GetNativeContext();
353 virtual void StrokePath( const wxGraphicsPath
& p
);
354 virtual void FillPath( const wxGraphicsPath
& p
, int fillStyle
= wxWINDING_RULE
);
356 virtual void Translate( wxDouble dx
, wxDouble dy
);
357 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
358 virtual void Rotate( wxDouble angle
);
360 // concatenates this transform with the current transform of this context
361 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
363 // sets the transform of this context
364 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
366 // gets the matrix of this context
367 virtual wxGraphicsMatrix
GetTransform() const;
369 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
370 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
371 virtual void PushState();
372 virtual void PopState();
374 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
375 virtual void GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
376 wxDouble
*descent
, wxDouble
*externalLeading
) const;
377 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
380 void Init(cairo_t
*context
);
385 //-----------------------------------------------------------------------------
386 // wxCairoPenData implementation
387 //-----------------------------------------------------------------------------
389 wxCairoPenData
::~wxCairoPenData()
391 delete[] m_userLengths
;
394 void wxCairoPenData
::Init()
397 m_userLengths
= NULL
;
402 wxCairoPenData
::wxCairoPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
)
403 : wxGraphicsObjectRefData(renderer
)
407 m_width
= m_pen
.GetWidth();
411 m_red
= m_pen
.GetColour().Red()/255.0;
412 m_green
= m_pen
.GetColour().Green()/255.0;
413 m_blue
= m_pen
.GetColour().Blue()/255.0;
414 m_alpha
= m_pen
.GetColour().Alpha()/255.0;
416 switch ( m_pen
.GetCap() )
419 m_cap
= CAIRO_LINE_CAP_ROUND
;
422 case wxCAP_PROJECTING
:
423 m_cap
= CAIRO_LINE_CAP_SQUARE
;
427 m_cap
= CAIRO_LINE_CAP_BUTT
;
431 m_cap
= CAIRO_LINE_CAP_BUTT
;
435 switch ( m_pen
.GetJoin() )
438 m_join
= CAIRO_LINE_JOIN_BEVEL
;
442 m_join
= CAIRO_LINE_JOIN_MITER
;
446 m_join
= CAIRO_LINE_JOIN_ROUND
;
450 m_join
= CAIRO_LINE_JOIN_MITER
;
454 const double dashUnit
= m_width
< 1.0 ?
1.0 : m_width
;
455 const double dotted
[] =
457 dashUnit
, dashUnit
+ 2.0
459 static const double short_dashed
[] =
463 static const double dashed
[] =
467 static const double dotted_dashed
[] =
469 9.0 , 6.0 , 3.0 , 3.0
472 switch ( m_pen
.GetStyle() )
478 m_count
= WXSIZEOF(dotted
);
479 m_userLengths
= new double[ m_count
] ;
480 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
481 m_lengths
= m_userLengths
;
486 m_count
= WXSIZEOF(dashed
);
491 m_count
= WXSIZEOF(short_dashed
);
496 m_count
= WXSIZEOF(dotted_dashed
);
502 m_count
= m_pen
.GetDashes( &wxdashes
) ;
503 if ((wxdashes
!= NULL
) && (m_count
> 0))
505 m_userLengths
= new double[m_count
] ;
506 for ( int i
= 0 ; i
< m_count
; ++i
)
508 m_userLengths
[i
] = wxdashes
[i
] * dashUnit
;
510 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
511 m_userLengths
[i
] = dashUnit
+ 2.0 ;
512 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
513 m_userLengths
[i
] = dashUnit
;
516 m_lengths
= m_userLengths
;
522 wxBitmap* bmp = pen.GetStipple();
523 if ( bmp && bmp->Ok() )
525 wxDELETE( m_penImage );
526 wxDELETE( m_penBrush );
527 m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
528 m_penBrush = new TextureBrush(m_penImage);
529 m_pen->SetBrush( m_penBrush );
535 if ( m_pen
.GetStyle() >= wxFIRST_HATCH
&& m_pen
.GetStyle() <= wxLAST_HATCH
)
538 wxDELETE( m_penBrush );
539 HatchStyle style = HatchStyleHorizontal;
540 switch( pen.GetStyle() )
542 case wxBDIAGONAL_HATCH :
543 style = HatchStyleBackwardDiagonal;
545 case wxCROSSDIAG_HATCH :
546 style = HatchStyleDiagonalCross;
548 case wxFDIAGONAL_HATCH :
549 style = HatchStyleForwardDiagonal;
552 style = HatchStyleCross;
554 case wxHORIZONTAL_HATCH :
555 style = HatchStyleHorizontal;
557 case wxVERTICAL_HATCH :
558 style = HatchStyleVertical;
562 m_penBrush = new HatchBrush(style,Color( pen.GetColour().Alpha() , pen.GetColour().Red() ,
563 pen.GetColour().Green() , pen.GetColour().Blue() ), Color.Transparent );
564 m_pen->SetBrush( m_penBrush )
571 void wxCairoPenData
::Apply( wxGraphicsContext
* context
)
573 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
574 cairo_set_line_width(ctext
,m_width
);
575 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
576 cairo_set_line_cap(ctext
,m_cap
);
577 cairo_set_line_join(ctext
,m_join
);
578 cairo_set_dash(ctext
,(double*)m_lengths
,m_count
,0.0);
581 //-----------------------------------------------------------------------------
582 // wxCairoBrushData implementation
583 //-----------------------------------------------------------------------------
585 wxCairoBrushData
::wxCairoBrushData( wxGraphicsRenderer
* renderer
)
586 : wxGraphicsObjectRefData( renderer
)
591 wxCairoBrushData
::wxCairoBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
)
592 : wxGraphicsObjectRefData(renderer
)
596 m_red
= brush
.GetColour().Red()/255.0;
597 m_green
= brush
.GetColour().Green()/255.0;
598 m_blue
= brush
.GetColour().Blue()/255.0;
599 m_alpha
= brush
.GetColour().Alpha()/255.0;
601 if ( brush.GetStyle() == wxSOLID)
603 m_brush = new SolidBrush( Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
604 brush.GetColour().Green() , brush.GetColour().Blue() ) );
606 else if ( brush.IsHatch() )
608 HatchStyle style = HatchStyleHorizontal;
609 switch( brush.GetStyle() )
611 case wxBDIAGONAL_HATCH :
612 style = HatchStyleBackwardDiagonal;
614 case wxCROSSDIAG_HATCH :
615 style = HatchStyleDiagonalCross;
617 case wxFDIAGONAL_HATCH :
618 style = HatchStyleForwardDiagonal;
621 style = HatchStyleCross;
623 case wxHORIZONTAL_HATCH :
624 style = HatchStyleHorizontal;
626 case wxVERTICAL_HATCH :
627 style = HatchStyleVertical;
631 m_brush = new HatchBrush(style,Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
632 brush.GetColour().Green() , brush.GetColour().Blue() ), Color.Transparent );
636 wxBitmap* bmp = brush.GetStipple();
637 if ( bmp && bmp->Ok() )
639 wxDELETE( m_brushImage );
640 m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
641 m_brush = new TextureBrush(m_brushImage);
647 wxCairoBrushData
::~wxCairoBrushData ()
650 cairo_pattern_destroy(m_brushPattern
);
653 void wxCairoBrushData
::Apply( wxGraphicsContext
* context
)
655 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
656 if ( m_brushPattern
)
658 cairo_set_source(ctext
,m_brushPattern
);
662 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
666 void wxCairoBrushData
::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
667 const wxColour
&c1
, const wxColour
&c2
)
669 m_brushPattern
= cairo_pattern_create_linear(x1
,y1
,x2
,y2
);
670 cairo_pattern_add_color_stop_rgba(m_brushPattern
,0.0,c1
.Red()/255.0,
671 c1
.Green()/255.0, c1
.Blue()/255.0,c1
.Alpha()/255.0);
672 cairo_pattern_add_color_stop_rgba(m_brushPattern
,1.0,c2
.Red()/255.0,
673 c2
.Green()/255.0, c2
.Blue()/255.0,c2
.Alpha()/255.0);
674 wxASSERT_MSG(cairo_pattern_status(m_brushPattern
) == CAIRO_STATUS_SUCCESS
, wxT("Couldn't create cairo pattern"));
677 void wxCairoBrushData
::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
678 const wxColour
&oColor
, const wxColour
&cColor
)
680 m_brushPattern
= cairo_pattern_create_radial(xo
,yo
,0.0,xc
,yc
,radius
);
681 cairo_pattern_add_color_stop_rgba(m_brushPattern
,0.0,oColor
.Red()/255.0,
682 oColor
.Green()/255.0, oColor
.Blue()/255.0,oColor
.Alpha()/255.0);
683 cairo_pattern_add_color_stop_rgba(m_brushPattern
,1.0,cColor
.Red()/255.0,
684 cColor
.Green()/255.0, cColor
.Blue()/255.0,cColor
.Alpha()/255.0);
685 wxASSERT_MSG(cairo_pattern_status(m_brushPattern
) == CAIRO_STATUS_SUCCESS
, wxT("Couldn't create cairo pattern"));
688 void wxCairoBrushData
::Init()
690 m_brushPattern
= NULL
;
693 //-----------------------------------------------------------------------------
694 // wxCairoFontData implementation
695 //-----------------------------------------------------------------------------
697 wxCairoFontData
::wxCairoFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
,
698 const wxColour
& col
) : wxGraphicsObjectRefData(renderer
)
700 m_red
= col
.Red()/255.0;
701 m_green
= col
.Green()/255.0;
702 m_blue
= col
.Blue()/255.0;
703 m_alpha
= col
.Alpha()/255.0;
705 m_size
= font
.GetPointSize();
706 m_fontName
= font
.GetFaceName().mb_str(wxConvUTF8
);
707 m_slant
= font
.GetStyle() == wxFONTSTYLE_ITALIC ? CAIRO_FONT_SLANT_ITALIC
:CAIRO_FONT_SLANT_NORMAL
;
708 m_weight
= font
.GetWeight() == wxFONTWEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD
:CAIRO_FONT_WEIGHT_NORMAL
;
710 m_font
= cairo_atsui_font_face_create_for_atsu_font_id( font
.MacGetATSUFontID() );
715 // Pango implementation uses the native descriptor
721 wxCairoFontData
::~wxCairoFontData()
723 cairo_font_face_destroy( m_font
);
726 void wxCairoFontData
::Apply( wxGraphicsContext
* context
)
729 // Pango handled differently
731 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
732 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
733 cairo_set_font_face(ctext
, m_font
);
739 //-----------------------------------------------------------------------------
740 // wxCairoPathData implementation
741 //-----------------------------------------------------------------------------
743 wxCairoPathData
::wxCairoPathData( wxGraphicsRenderer
* renderer
, cairo_t
* pathcontext
)
744 : wxGraphicsPathData(renderer
)
748 m_pathContext
= pathcontext
;
752 cairo_surface_t
* surface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,1,1);
753 m_pathContext
= cairo_create(surface
);
754 cairo_surface_destroy (surface
);
758 wxCairoPathData
::~wxCairoPathData()
760 cairo_destroy(m_pathContext
);
763 wxGraphicsObjectRefData
*wxCairoPathData
::Clone() const
765 cairo_surface_t
* surface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,1,1);
766 cairo_t
* pathcontext
= cairo_create(surface
);
767 cairo_surface_destroy (surface
);
769 cairo_path_t
* path
= cairo_copy_path(m_pathContext
);
770 cairo_append_path(pathcontext
, path
);
771 cairo_path_destroy(path
);
772 return new wxCairoPathData( GetRenderer() ,pathcontext
);
776 void* wxCairoPathData
::GetNativePath() const
778 return cairo_copy_path(m_pathContext
) ;
781 void wxCairoPathData
::UnGetNativePath(void *p
) const
783 cairo_path_destroy((cairo_path_t
*)p
);
790 void wxCairoPathData
::MoveToPoint( wxDouble x
, wxDouble y
)
792 cairo_move_to(m_pathContext
,x
,y
);
795 void wxCairoPathData
::AddLineToPoint( wxDouble x
, wxDouble y
)
797 cairo_line_to(m_pathContext
,x
,y
);
800 void wxCairoPathData
::AddPath( const wxGraphicsPathData
* path
)
802 cairo_path_t
* p
= (cairo_path_t
*)path
->GetNativePath();
803 cairo_append_path(m_pathContext
, p
);
807 void wxCairoPathData
::CloseSubpath()
809 cairo_close_path(m_pathContext
);
812 void wxCairoPathData
::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
814 cairo_curve_to(m_pathContext
,cx1
,cy1
,cx2
,cy2
,x
,y
);
817 // gets the last point of the current path, (0,0) if not yet set
818 void wxCairoPathData
::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
821 cairo_get_current_point(m_pathContext
,&dx
,&dy
);
828 void wxCairoPathData
::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, double startAngle
, double endAngle
, bool clockwise
)
830 // as clockwise means positive in our system (y pointing downwards)
831 // TODO make this interpretation dependent of the
833 if ( clockwise
||(endAngle
-startAngle
)>=2*M_PI
)
834 cairo_arc(m_pathContext
,x
,y
,r
,startAngle
,endAngle
);
836 cairo_arc_negative(m_pathContext
,x
,y
,r
,startAngle
,endAngle
);
839 // transforms each point of this path by the matrix
840 void wxCairoPathData
::Transform( const wxGraphicsMatrixData
* matrix
)
842 // as we don't have a true path object, we have to apply the inverse
843 // matrix to the context
844 cairo_matrix_t m
= *((cairo_matrix_t
*) matrix
->GetNativeMatrix());
845 cairo_matrix_invert( &m
);
846 cairo_transform(m_pathContext
,&m
);
849 // gets the bounding box enclosing all points (possibly including control points)
850 void wxCairoPathData
::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
854 cairo_stroke_extents( m_pathContext
, &x1
, &y1
, &x2
, &y2
);
878 bool wxCairoPathData
::Contains( wxDouble x
, wxDouble y
, int fillStyle
) const
880 return cairo_in_stroke( m_pathContext
, x
, y
) != 0;
883 //-----------------------------------------------------------------------------
884 // wxCairoMatrixData implementation
885 //-----------------------------------------------------------------------------
887 wxCairoMatrixData
::wxCairoMatrixData(wxGraphicsRenderer
* renderer
, const cairo_matrix_t
* matrix
)
888 : wxGraphicsMatrixData(renderer
)
894 wxCairoMatrixData
::~wxCairoMatrixData()
899 wxGraphicsObjectRefData
*wxCairoMatrixData
::Clone() const
901 return new wxCairoMatrixData(GetRenderer(),&m_matrix
);
904 // concatenates the matrix
905 void wxCairoMatrixData
::Concat( const wxGraphicsMatrixData
*t
)
907 cairo_matrix_multiply( &m_matrix
, &m_matrix
, (cairo_matrix_t
*) t
->GetNativeMatrix());
910 // sets the matrix to the respective values
911 void wxCairoMatrixData
::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
912 wxDouble tx
, wxDouble ty
)
914 cairo_matrix_init( &m_matrix
, a
, b
, c
, d
, tx
, ty
);
917 // gets the component valuess of the matrix
918 void wxCairoMatrixData
::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
919 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
921 if (a
) *a
= m_matrix
.xx
;
922 if (b
) *b
= m_matrix
.yx
;
923 if (c
) *c
= m_matrix
.xy
;
924 if (d
) *d
= m_matrix
.yy
;
925 if (tx
) *tx
= m_matrix
.x0
;
926 if (ty
) *ty
= m_matrix
.y0
;
929 // makes this the inverse matrix
930 void wxCairoMatrixData
::Invert()
932 cairo_matrix_invert( &m_matrix
);
935 // returns true if the elements of the transformation matrix are equal ?
936 bool wxCairoMatrixData
::IsEqual( const wxGraphicsMatrixData
* t
) const
938 const cairo_matrix_t
* tm
= (cairo_matrix_t
*) t
->GetNativeMatrix();
940 m_matrix
.xx
== tm
->xx
&&
941 m_matrix
.yx
== tm
->yx
&&
942 m_matrix
.xy
== tm
->xy
&&
943 m_matrix
.yy
== tm
->yy
&&
944 m_matrix
.x0
== tm
->x0
&&
945 m_matrix
.y0
== tm
->y0
) ;
948 // return true if this is the identity matrix
949 bool wxCairoMatrixData
::IsIdentity() const
951 return ( m_matrix
.xx
== 1 && m_matrix
.yy
== 1 &&
952 m_matrix
.yx
== 0 && m_matrix
.xy
== 0 && m_matrix
.x0
== 0 && m_matrix
.y0
== 0);
959 // add the translation to this matrix
960 void wxCairoMatrixData
::Translate( wxDouble dx
, wxDouble dy
)
962 cairo_matrix_translate( &m_matrix
, dx
, dy
) ;
965 // add the scale to this matrix
966 void wxCairoMatrixData
::Scale( wxDouble xScale
, wxDouble yScale
)
968 cairo_matrix_scale( &m_matrix
, xScale
, yScale
) ;
971 // add the rotation to this matrix (radians)
972 void wxCairoMatrixData
::Rotate( wxDouble angle
)
974 cairo_matrix_rotate( &m_matrix
, angle
) ;
978 // apply the transforms
981 // applies that matrix to the point
982 void wxCairoMatrixData
::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
984 double lx
= *x
, ly
= *y
;
985 cairo_matrix_transform_point( &m_matrix
, &lx
, &ly
);
990 // applies the matrix except for translations
991 void wxCairoMatrixData
::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
993 double lx
= *dx
, ly
= *dy
;
994 cairo_matrix_transform_distance( &m_matrix
, &lx
, &ly
);
999 // returns the native representation
1000 void * wxCairoMatrixData
::GetNativeMatrix() const
1002 return (void*) &m_matrix
;
1005 //-----------------------------------------------------------------------------
1006 // wxCairoContext implementation
1007 //-----------------------------------------------------------------------------
1009 class wxCairoOffsetHelper
1012 wxCairoOffsetHelper( cairo_t
* ctx
, bool offset
)
1017 cairo_translate( m_ctx
, 0.5, 0.5 );
1019 ~wxCairoOffsetHelper( )
1022 cairo_translate( m_ctx
, -0.5, -0.5 );
1029 wxCairoContext
::wxCairoContext( wxGraphicsRenderer
* renderer
, const wxWindowDC
& dc
)
1030 : wxGraphicsContext(renderer
)
1033 Init( gdk_cairo_create( dc
.m_window
) );
1037 dc
.GetSize( &width
, &height
);
1038 CGContextRef cgcontext
= (CGContextRef
)dc
.GetWindow()->MacGetCGContextRef();
1039 cairo_surface_t
* surface
= cairo_quartz_surface_create_for_cg_context(cgcontext
, width
, height
);
1040 Init( cairo_create( surface
) );
1041 cairo_surface_destroy( surface
);
1046 wxCairoContext
::wxCairoContext( wxGraphicsRenderer
* renderer
, GdkDrawable
*drawable
)
1047 : wxGraphicsContext(renderer
)
1049 Init( gdk_cairo_create( drawable
) );
1053 wxCairoContext
::wxCairoContext( wxGraphicsRenderer
* renderer
, cairo_t
*context
)
1054 : wxGraphicsContext(renderer
)
1059 wxCairoContext
::wxCairoContext( wxGraphicsRenderer
* renderer
, wxWindow
*window
)
1060 : wxGraphicsContext(renderer
)
1063 // something along these lines (copied from dcclient)
1065 GtkWidget
*widget
= window
->m_wxwindow
;
1067 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
1068 // code should still be able to create wxClientDCs for them, so we will
1069 // use the parent window here then.
1072 window
= window
->GetParent();
1073 widget
= window
->m_wxwindow
;
1076 wxASSERT_MSG( widget
, wxT("wxCairoContext needs a widget") );
1078 GtkPizza
*pizza
= GTK_PIZZA( widget
);
1079 GdkDrawable
* drawable
= pizza
->bin_window
;
1080 Init( gdk_cairo_create( drawable
) ) ;
1084 wxCairoContext
::~wxCairoContext()
1090 cairo_destroy(m_context
);
1094 void wxCairoContext
::Init(cairo_t
*context
)
1096 m_context
= context
;
1102 void wxCairoContext
::Clip( const wxRegion
& region
)
1104 // Create a path with all the rectangles in the region
1105 wxGraphicsPath path
= GetRenderer()->CreatePath();
1106 wxRegionIterator
ri(region
);
1109 path
.AddRectangle(ri
.GetX(), ri
.GetY(), ri
.GetW(), ri
.GetH());
1113 // Put it in the context
1114 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1115 cairo_append_path(m_context
, cp
);
1117 // clip to that path
1118 cairo_clip(m_context
);
1119 path
.UnGetNativePath(cp
);
1122 void wxCairoContext
::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1124 // Create a path with this rectangle
1125 wxGraphicsPath path
= GetRenderer()->CreatePath();
1126 path
.AddRectangle(x
,y
,w
,h
);
1128 // Put it in the context
1129 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1130 cairo_append_path(m_context
, cp
);
1132 // clip to that path
1133 // cairo_clip(m_context);
1134 path
.UnGetNativePath(cp
);
1137 void wxCairoContext
::ResetClip()
1139 cairo_reset_clip(m_context
);
1143 void wxCairoContext
::StrokePath( const wxGraphicsPath
& path
)
1145 if ( !m_pen
.IsNull() )
1147 wxCairoOffsetHelper
helper( m_context
, ShouldOffset() ) ;
1148 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1149 cairo_append_path(m_context
,cp
);
1150 ((wxCairoPenData
*)m_pen
.GetRefData())->Apply(this);
1151 cairo_stroke(m_context
);
1152 path
.UnGetNativePath(cp
);
1156 void wxCairoContext
::FillPath( const wxGraphicsPath
& path
, int fillStyle
)
1158 if ( !m_brush
.IsNull() )
1160 wxCairoOffsetHelper
helper( m_context
, ShouldOffset() ) ;
1161 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1162 cairo_append_path(m_context
,cp
);
1163 ((wxCairoBrushData
*)m_brush
.GetRefData())->Apply(this);
1164 cairo_set_fill_rule(m_context
,fillStyle
==wxODDEVEN_RULE ? CAIRO_FILL_RULE_EVEN_ODD
: CAIRO_FILL_RULE_WINDING
);
1165 cairo_fill(m_context
);
1166 path
.UnGetNativePath(cp
);
1170 void wxCairoContext
::Rotate( wxDouble angle
)
1172 cairo_rotate(m_context
,angle
);
1175 void wxCairoContext
::Translate( wxDouble dx
, wxDouble dy
)
1177 cairo_translate(m_context
,dx
,dy
);
1180 void wxCairoContext
::Scale( wxDouble xScale
, wxDouble yScale
)
1182 cairo_scale(m_context
,xScale
,yScale
);
1185 // concatenates this transform with the current transform of this context
1186 void wxCairoContext
::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1188 cairo_transform(m_context
,(const cairo_matrix_t
*) matrix
.GetNativeMatrix());
1191 // sets the transform of this context
1192 void wxCairoContext
::SetTransform( const wxGraphicsMatrix
& matrix
)
1194 cairo_set_matrix(m_context
,(const cairo_matrix_t
*) matrix
.GetNativeMatrix());
1197 // gets the matrix of this context
1198 wxGraphicsMatrix wxCairoContext
::GetTransform() const
1200 wxGraphicsMatrix matrix
= CreateMatrix();
1201 cairo_get_matrix(m_context
,(cairo_matrix_t
*) matrix
.GetNativeMatrix());
1207 void wxCairoContext
::PushState()
1209 cairo_save(m_context
);
1212 void wxCairoContext
::PopState()
1214 cairo_restore(m_context
);
1217 void wxCairoContext
::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1219 wxCHECK_RET( bmp
.IsOk(), wxT("Invalid bitmap in wxCairoContext::DrawBitmap"));
1221 cairo_surface_t
* surface
;
1222 int bw
= bmp
.GetWidth();
1223 int bh
= bmp
.GetHeight();
1224 wxBitmap bmpSource
= bmp
; // we need a non-const instance
1225 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1226 wxUint32
* data
= (wxUint32
*)buffer
;
1228 // Create a surface object and copy the bitmap pixel data to it. if the
1229 // image has alpha (or a mask represented as alpha) then we'll use a
1230 // different format and iterator than if it doesn't...
1231 if (bmpSource
.HasAlpha() || bmpSource
.GetMask())
1233 surface
= cairo_image_surface_create_for_data(
1234 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1235 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1236 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1238 wxAlphaPixelData
::Iterator
p(pixData
);
1239 for (int y
=0; y
<bh
; y
++)
1241 wxAlphaPixelData
::Iterator rowStart
= p
;
1242 for (int x
=0; x
<bw
; x
++)
1244 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1245 // with alpha in the upper 8 bits, then red, then green, then
1246 // blue. The 32-bit quantities are stored native-endian.
1247 // Pre-multiplied alpha is used.
1248 unsigned char alpha
= p
.Alpha();
1252 *data
= ( alpha
<< 24
1253 | (p
.Red() * alpha
/255) << 16
1254 | (p
.Green() * alpha
/255) << 8
1255 | (p
.Blue() * alpha
/255) );
1260 p
.OffsetY(pixData
, 1);
1265 surface
= cairo_image_surface_create_for_data(
1266 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1267 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1268 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1270 wxNativePixelData
::Iterator
p(pixData
);
1271 for (int y
=0; y
<bh
; y
++)
1273 wxNativePixelData
::Iterator rowStart
= p
;
1274 for (int x
=0; x
<bw
; x
++)
1276 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1277 // the upper 8 bits unused. Red, Green, and Blue are stored in
1278 // the remaining 24 bits in that order. The 32-bit quantities
1279 // are stored native-endian.
1280 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1285 p
.OffsetY(pixData
, 1);
1292 // In case we're scaling the image by using a width and height different
1293 // than the bitmap's size create a pattern transformation on the surface and
1294 // draw the transformed pattern.
1295 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1296 wxDouble scaleX
= w
/ bw
;
1297 wxDouble scaleY
= h
/ bh
;
1298 cairo_scale(m_context
, scaleX
, scaleY
);
1300 // prepare to draw the image
1301 cairo_translate(m_context
, x
, y
);
1302 cairo_set_source(m_context
, pattern
);
1303 // use the original size here since the context is scaled already...
1304 cairo_rectangle(m_context
, 0, 0, bw
, bh
);
1305 // fill the rectangle using the pattern
1306 cairo_fill(m_context
);
1309 cairo_pattern_destroy(pattern
);
1310 cairo_surface_destroy(surface
);
1315 void wxCairoContext
::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1317 // An icon is a bitmap on wxGTK, so do this the easy way. When we want to
1318 // start using the Cairo backend on other platforms then we may need to
1319 // fiddle with this...
1320 DrawBitmap(icon
, x
, y
, w
, h
);
1324 void wxCairoContext
::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1326 if ( m_font
.IsNull() || str
.empty())
1330 const wxCharBuffer data
= wxGTK_CONV( str
);
1333 size_t datalen
= strlen(data
);
1335 PangoLayout
*layout
= pango_cairo_create_layout (m_context
);
1336 pango_layout_set_font_description( m_layout
, m_wxFont
->GetNativeFontInfo()->description
);
1337 pango_layout_set_text (layout
, data
, datalen
);
1338 cairo_move_to(m_context
, x
, y
);
1339 pango_cairo_show_layout (m_context
, layout
);
1341 g_object_unref (layout
);
1343 ((wxCairoFontData
*)m_font
.GetRefData())->Apply(this);
1344 // Cairo's x,y for drawing text is at the baseline, so we need to adjust
1345 // the position we move to by the ascent.
1346 cairo_font_extents_t fe
;
1347 cairo_font_extents(m_context
, &fe
);
1348 cairo_move_to(m_context
, x
, y
+fe
.ascent
);
1350 const wxWX2MBbuf
buf(str
.mb_str(wxConvUTF8
));
1351 cairo_show_text(m_context
,buf
);
1355 void wxCairoContext
::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1356 wxDouble
*descent
, wxDouble
*externalLeading
) const
1364 if ( externalLeading
)
1365 *externalLeading
= 0;
1367 if ( m_font
.IsNull() || str
.empty())
1373 PangoLayout
*layout
= pango_cairo_create_layout (m_context
);
1374 pango_layout_set_font_description( layout
, m_wxFont
->GetNativeFontInfo()->description
);
1375 const wxCharBuffer dataUTF8
= wxGTK_CONV_FONT(str
, m_wxFont
);
1380 pango_layout_set_text( layout
, dataUTF8
, strlen(dataUTF8
) );
1381 pango_layout_get_pixel_size (layout
, &w
, &h
);
1388 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
1389 int baseline
= pango_layout_iter_get_baseline(iter
);
1390 pango_layout_iter_free(iter
);
1391 *descent
= h
- PANGO_PIXELS(baseline
);
1393 g_object_unref (layout
);
1395 ((wxCairoFontData
*)m_font
.GetRefData())->Apply((wxCairoContext
*)this);
1399 const wxWX2MBbuf
buf(str
.mb_str(wxConvUTF8
));
1400 cairo_text_extents_t te
;
1401 cairo_text_extents(m_context
, buf
, &te
);
1405 if (height
|| descent
|| externalLeading
)
1407 cairo_font_extents_t fe
;
1408 cairo_font_extents(m_context
, &fe
);
1411 *height
= fe
.height
;
1413 *descent
= fe
.descent
;
1414 if ( externalLeading
)
1415 *externalLeading
= wxMax(0, fe
.height
- (fe
.ascent
+ fe
.descent
));
1420 void wxCairoContext
::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1423 widths
.Add(0, text
.length());
1431 void * wxCairoContext
::GetNativeContext()
1436 //-----------------------------------------------------------------------------
1437 // wxCairoRenderer declaration
1438 //-----------------------------------------------------------------------------
1440 class WXDLLIMPEXP_CORE wxCairoRenderer
: public wxGraphicsRenderer
1443 wxCairoRenderer() {}
1445 virtual ~wxCairoRenderer() {}
1449 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
1452 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
);
1455 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
1457 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
1459 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
1461 virtual wxGraphicsContext
* CreateMeasuringContext();
1465 virtual wxGraphicsPath
CreatePath();
1469 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
1470 wxDouble tx
=0.0, wxDouble ty
=0.0);
1473 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
1475 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
1477 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1478 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
1479 const wxColour
&c1
, const wxColour
&c2
) ;
1481 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1482 // with radius r and color cColor
1483 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
1484 const wxColour
&oColor
, const wxColour
&cColor
) ;
1487 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
1490 DECLARE_DYNAMIC_CLASS_NO_COPY(wxCairoRenderer
)
1493 //-----------------------------------------------------------------------------
1494 // wxCairoRenderer implementation
1495 //-----------------------------------------------------------------------------
1497 IMPLEMENT_DYNAMIC_CLASS(wxCairoRenderer
,wxGraphicsRenderer
)
1499 static wxCairoRenderer gs_cairoGraphicsRenderer
;
1502 wxGraphicsRenderer
* wxGraphicsRenderer
::GetDefaultRenderer()
1504 return &gs_cairoGraphicsRenderer
;
1508 wxGraphicsContext
* wxCairoRenderer
::CreateContext( const wxWindowDC
& dc
)
1510 return new wxCairoContext(this,dc
);
1514 wxGraphicsContext
* wxCairoRenderer
::CreateContext( const wxMemoryDC
& dc
)
1520 wxGraphicsContext
* wxCairoRenderer
::CreateContextFromNativeContext( void * context
)
1522 return new wxCairoContext(this,(cairo_t
*)context
);
1526 wxGraphicsContext
* wxCairoRenderer
::CreateContextFromNativeWindow( void * window
)
1529 return new wxCairoContext(this,(GdkDrawable
*)window
);
1535 wxGraphicsContext
* wxCairoRenderer
::CreateMeasuringContext()
1541 wxGraphicsContext
* wxCairoRenderer
::CreateContext( wxWindow
* window
)
1543 return new wxCairoContext(this, window
);
1548 wxGraphicsPath wxCairoRenderer
::CreatePath()
1550 wxGraphicsPath path
;
1551 path
.SetRefData( new wxCairoPathData(this) );
1558 wxGraphicsMatrix wxCairoRenderer
::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
1559 wxDouble tx
, wxDouble ty
)
1563 wxCairoMatrixData
* data
= new wxCairoMatrixData( this );
1564 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
1569 wxGraphicsPen wxCairoRenderer
::CreatePen(const wxPen
& pen
)
1571 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
1572 return wxNullGraphicsPen
;
1576 p
.SetRefData(new wxCairoPenData( this, pen
));
1581 wxGraphicsBrush wxCairoRenderer
::CreateBrush(const wxBrush
& brush
)
1583 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
1584 return wxNullGraphicsBrush
;
1588 p
.SetRefData(new wxCairoBrushData( this, brush
));
1593 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1594 wxGraphicsBrush wxCairoRenderer
::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
1595 const wxColour
&c1
, const wxColour
&c2
)
1598 wxCairoBrushData
* d
= new wxCairoBrushData( this );
1599 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
1604 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1605 // with radius r and color cColor
1606 wxGraphicsBrush wxCairoRenderer
::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
1607 const wxColour
&oColor
, const wxColour
&cColor
)
1610 wxCairoBrushData
* d
= new wxCairoBrushData( this );
1611 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
1617 wxGraphicsFont wxCairoRenderer
::CreateFont( const wxFont
&font
, const wxColour
&col
)
1622 p
.SetRefData(new wxCairoFontData( this , font
, col
));
1626 return wxNullGraphicsFont
;
1629 #endif // wxUSE_GRAPHICS_CONTEXT