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"
106 #include "wx/fontutil.h"
110 #include <cairo-win32.h>
114 #include "wx/mac/private.h"
115 #include <cairo-quartz.h>
116 #include <cairo-atsui.h>
119 class WXDLLIMPEXP_CORE wxCairoPathData
: public wxGraphicsPathData
122 wxCairoPathData(wxGraphicsRenderer
* renderer
, cairo_t
* path
= NULL
);
125 virtual wxGraphicsObjectRefData
*Clone() const;
128 // These are the path primitives from which everything else can be constructed
131 // begins a new subpath at (x,y)
132 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
134 // adds a straight line from the current point to (x,y)
135 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
137 // adds a cubic Bezier curve from the current point, using two control points and an end point
138 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
141 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
142 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
) ;
144 // gets the last point of the current path, (0,0) if not yet set
145 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
148 virtual void AddPath( const wxGraphicsPathData
* path
);
150 // closes the current sub-path
151 virtual void CloseSubpath();
154 // These are convenience functions which - if not available natively will be assembled
155 // using the primitives from above
160 // appends a rectangle as a new closed subpath
161 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) ;
162 // appends an ellipsis as a new closed subpath fitting the passed rectangle
163 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
165 // 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)
166 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
169 // returns the native path
170 virtual void * GetNativePath() const ;
172 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
173 virtual void UnGetNativePath(void *p
) const;
175 // transforms each point of this path by the matrix
176 virtual void Transform( const wxGraphicsMatrixData
* matrix
) ;
178 // gets the bounding box enclosing all points (possibly including control points)
179 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const;
181 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxWINDING_RULE
) const;
184 cairo_t
* m_pathContext
;
187 class WXDLLIMPEXP_CORE wxCairoMatrixData
: public wxGraphicsMatrixData
190 wxCairoMatrixData(wxGraphicsRenderer
* renderer
, const cairo_matrix_t
* matrix
= NULL
) ;
191 virtual ~wxCairoMatrixData() ;
193 virtual wxGraphicsObjectRefData
*Clone() const ;
195 // concatenates the matrix
196 virtual void Concat( const wxGraphicsMatrixData
*t
);
198 // sets the matrix to the respective values
199 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
200 wxDouble tx
=0.0, wxDouble ty
=0.0);
202 // gets the component valuess of the matrix
203 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
204 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
206 // makes this the inverse matrix
207 virtual void Invert();
209 // returns true if the elements of the transformation matrix are equal ?
210 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
212 // return true if this is the identity matrix
213 virtual bool IsIdentity() const;
219 // add the translation to this matrix
220 virtual void Translate( wxDouble dx
, wxDouble dy
);
222 // add the scale to this matrix
223 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
225 // add the rotation to this matrix (radians)
226 virtual void Rotate( wxDouble angle
);
229 // apply the transforms
232 // applies that matrix to the point
233 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
235 // applies the matrix except for translations
236 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
238 // returns the native representation
239 virtual void * GetNativeMatrix() const;
241 cairo_matrix_t m_matrix
;
244 class WXDLLIMPEXP_CORE wxCairoPenData
: public wxGraphicsObjectRefData
247 wxCairoPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
252 virtual void Apply( wxGraphicsContext
* context
);
253 virtual wxDouble
GetWidth() { return m_width
; }
263 cairo_line_cap_t m_cap
;
264 cairo_line_join_t m_join
;
267 const double *m_lengths
;
268 double *m_userLengths
;
273 class WXDLLIMPEXP_CORE wxCairoBrushData
: public wxGraphicsObjectRefData
276 wxCairoBrushData( wxGraphicsRenderer
* renderer
);
277 wxCairoBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
278 ~wxCairoBrushData ();
280 virtual void Apply( wxGraphicsContext
* context
);
281 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
282 const wxColour
&c1
, const wxColour
&c2
);
283 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
284 const wxColour
&oColor
, const wxColour
&cColor
);
295 cairo_pattern_t
* m_brushPattern
;
298 class wxCairoFontData
: public wxGraphicsObjectRefData
301 wxCairoFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
304 virtual void Apply( wxGraphicsContext
* context
);
306 const PangoFontDescription
* GetFont() const { return m_font
; }
315 cairo_font_face_t
*m_font
;
316 #elif defined(__WXGTK__)
317 PangoFontDescription
* m_font
;
319 wxCharBuffer m_fontName
;
320 cairo_font_slant_t m_slant
;
321 cairo_font_weight_t m_weight
;
325 class WXDLLIMPEXP_CORE wxCairoContext
: public wxGraphicsContext
327 DECLARE_NO_COPY_CLASS(wxCairoContext
)
330 wxCairoContext( wxGraphicsRenderer
* renderer
, const wxWindowDC
& dc
);
332 wxCairoContext( wxGraphicsRenderer
* renderer
, GdkDrawable
*drawable
);
334 wxCairoContext( wxGraphicsRenderer
* renderer
, cairo_t
*context
);
335 wxCairoContext( wxGraphicsRenderer
* renderer
, wxWindow
*window
);
337 virtual ~wxCairoContext();
339 virtual bool ShouldOffset() const
342 if ( !m_pen
.IsNull() )
344 penwidth
= (int)((wxCairoPenData
*)m_pen
.GetRefData())->GetWidth();
348 return ( penwidth
% 2 ) == 1;
351 virtual void Clip( const wxRegion
®ion
);
353 // clips drawings to the rect
354 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
356 // resets the clipping to original extent
357 virtual void ResetClip();
359 virtual void * GetNativeContext();
361 virtual void StrokePath( const wxGraphicsPath
& p
);
362 virtual void FillPath( const wxGraphicsPath
& p
, int fillStyle
= wxWINDING_RULE
);
364 virtual void Translate( wxDouble dx
, wxDouble dy
);
365 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
366 virtual void Rotate( wxDouble angle
);
368 // concatenates this transform with the current transform of this context
369 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
371 // sets the transform of this context
372 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
374 // gets the matrix of this context
375 virtual wxGraphicsMatrix
GetTransform() const;
377 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
378 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
379 virtual void PushState();
380 virtual void PopState();
382 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
383 virtual void GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
384 wxDouble
*descent
, wxDouble
*externalLeading
) const;
385 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
388 void Init(cairo_t
*context
);
393 //-----------------------------------------------------------------------------
394 // wxCairoPenData implementation
395 //-----------------------------------------------------------------------------
397 wxCairoPenData::~wxCairoPenData()
399 delete[] m_userLengths
;
402 void wxCairoPenData::Init()
405 m_userLengths
= NULL
;
410 wxCairoPenData::wxCairoPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
)
411 : wxGraphicsObjectRefData(renderer
)
415 m_width
= m_pen
.GetWidth();
419 m_red
= m_pen
.GetColour().Red()/255.0;
420 m_green
= m_pen
.GetColour().Green()/255.0;
421 m_blue
= m_pen
.GetColour().Blue()/255.0;
422 m_alpha
= m_pen
.GetColour().Alpha()/255.0;
424 switch ( m_pen
.GetCap() )
427 m_cap
= CAIRO_LINE_CAP_ROUND
;
430 case wxCAP_PROJECTING
:
431 m_cap
= CAIRO_LINE_CAP_SQUARE
;
435 m_cap
= CAIRO_LINE_CAP_BUTT
;
439 m_cap
= CAIRO_LINE_CAP_BUTT
;
443 switch ( m_pen
.GetJoin() )
446 m_join
= CAIRO_LINE_JOIN_BEVEL
;
450 m_join
= CAIRO_LINE_JOIN_MITER
;
454 m_join
= CAIRO_LINE_JOIN_ROUND
;
458 m_join
= CAIRO_LINE_JOIN_MITER
;
462 const double dashUnit
= m_width
< 1.0 ? 1.0 : m_width
;
463 const double dotted
[] =
465 dashUnit
, dashUnit
+ 2.0
467 static const double short_dashed
[] =
471 static const double dashed
[] =
475 static const double dotted_dashed
[] =
477 9.0 , 6.0 , 3.0 , 3.0
480 switch ( m_pen
.GetStyle() )
486 m_count
= WXSIZEOF(dotted
);
487 m_userLengths
= new double[ m_count
] ;
488 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
489 m_lengths
= m_userLengths
;
494 m_count
= WXSIZEOF(dashed
);
498 m_lengths
= short_dashed
;
499 m_count
= WXSIZEOF(short_dashed
);
503 m_lengths
= dotted_dashed
;
504 m_count
= WXSIZEOF(dotted_dashed
);
510 m_count
= m_pen
.GetDashes( &wxdashes
) ;
511 if ((wxdashes
!= NULL
) && (m_count
> 0))
513 m_userLengths
= new double[m_count
] ;
514 for ( int i
= 0 ; i
< m_count
; ++i
)
516 m_userLengths
[i
] = wxdashes
[i
] * dashUnit
;
518 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
519 m_userLengths
[i
] = dashUnit
+ 2.0 ;
520 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
521 m_userLengths
[i
] = dashUnit
;
524 m_lengths
= m_userLengths
;
530 wxBitmap* bmp = pen.GetStipple();
531 if ( bmp && bmp->Ok() )
533 wxDELETE( m_penImage );
534 wxDELETE( m_penBrush );
535 m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
536 m_penBrush = new TextureBrush(m_penImage);
537 m_pen->SetBrush( m_penBrush );
543 if ( m_pen
.GetStyle() >= wxFIRST_HATCH
&& m_pen
.GetStyle() <= wxLAST_HATCH
)
546 wxDELETE( m_penBrush );
547 HatchStyle style = HatchStyleHorizontal;
548 switch( pen.GetStyle() )
550 case wxBDIAGONAL_HATCH :
551 style = HatchStyleBackwardDiagonal;
553 case wxCROSSDIAG_HATCH :
554 style = HatchStyleDiagonalCross;
556 case wxFDIAGONAL_HATCH :
557 style = HatchStyleForwardDiagonal;
560 style = HatchStyleCross;
562 case wxHORIZONTAL_HATCH :
563 style = HatchStyleHorizontal;
565 case wxVERTICAL_HATCH :
566 style = HatchStyleVertical;
570 m_penBrush = new HatchBrush(style,Color( pen.GetColour().Alpha() , pen.GetColour().Red() ,
571 pen.GetColour().Green() , pen.GetColour().Blue() ), Color.Transparent );
572 m_pen->SetBrush( m_penBrush )
579 void wxCairoPenData::Apply( wxGraphicsContext
* context
)
581 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
582 cairo_set_line_width(ctext
,m_width
);
583 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
584 cairo_set_line_cap(ctext
,m_cap
);
585 cairo_set_line_join(ctext
,m_join
);
586 cairo_set_dash(ctext
,(double*)m_lengths
,m_count
,0.0);
589 //-----------------------------------------------------------------------------
590 // wxCairoBrushData implementation
591 //-----------------------------------------------------------------------------
593 wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer
* renderer
)
594 : wxGraphicsObjectRefData( renderer
)
599 wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
)
600 : wxGraphicsObjectRefData(renderer
)
604 m_red
= brush
.GetColour().Red()/255.0;
605 m_green
= brush
.GetColour().Green()/255.0;
606 m_blue
= brush
.GetColour().Blue()/255.0;
607 m_alpha
= brush
.GetColour().Alpha()/255.0;
609 if ( brush.GetStyle() == wxSOLID)
611 m_brush = new SolidBrush( Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
612 brush.GetColour().Green() , brush.GetColour().Blue() ) );
614 else if ( brush.IsHatch() )
616 HatchStyle style = HatchStyleHorizontal;
617 switch( brush.GetStyle() )
619 case wxBDIAGONAL_HATCH :
620 style = HatchStyleBackwardDiagonal;
622 case wxCROSSDIAG_HATCH :
623 style = HatchStyleDiagonalCross;
625 case wxFDIAGONAL_HATCH :
626 style = HatchStyleForwardDiagonal;
629 style = HatchStyleCross;
631 case wxHORIZONTAL_HATCH :
632 style = HatchStyleHorizontal;
634 case wxVERTICAL_HATCH :
635 style = HatchStyleVertical;
639 m_brush = new HatchBrush(style,Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
640 brush.GetColour().Green() , brush.GetColour().Blue() ), Color.Transparent );
644 wxBitmap* bmp = brush.GetStipple();
645 if ( bmp && bmp->Ok() )
647 wxDELETE( m_brushImage );
648 m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
649 m_brush = new TextureBrush(m_brushImage);
655 wxCairoBrushData::~wxCairoBrushData ()
658 cairo_pattern_destroy(m_brushPattern
);
661 void wxCairoBrushData::Apply( wxGraphicsContext
* context
)
663 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
664 if ( m_brushPattern
)
666 cairo_set_source(ctext
,m_brushPattern
);
670 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
674 void wxCairoBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
675 const wxColour
&c1
, const wxColour
&c2
)
677 m_brushPattern
= cairo_pattern_create_linear(x1
,y1
,x2
,y2
);
678 cairo_pattern_add_color_stop_rgba(m_brushPattern
,0.0,c1
.Red()/255.0,
679 c1
.Green()/255.0, c1
.Blue()/255.0,c1
.Alpha()/255.0);
680 cairo_pattern_add_color_stop_rgba(m_brushPattern
,1.0,c2
.Red()/255.0,
681 c2
.Green()/255.0, c2
.Blue()/255.0,c2
.Alpha()/255.0);
682 wxASSERT_MSG(cairo_pattern_status(m_brushPattern
) == CAIRO_STATUS_SUCCESS
, wxT("Couldn't create cairo pattern"));
685 void wxCairoBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
686 const wxColour
&oColor
, const wxColour
&cColor
)
688 m_brushPattern
= cairo_pattern_create_radial(xo
,yo
,0.0,xc
,yc
,radius
);
689 cairo_pattern_add_color_stop_rgba(m_brushPattern
,0.0,oColor
.Red()/255.0,
690 oColor
.Green()/255.0, oColor
.Blue()/255.0,oColor
.Alpha()/255.0);
691 cairo_pattern_add_color_stop_rgba(m_brushPattern
,1.0,cColor
.Red()/255.0,
692 cColor
.Green()/255.0, cColor
.Blue()/255.0,cColor
.Alpha()/255.0);
693 wxASSERT_MSG(cairo_pattern_status(m_brushPattern
) == CAIRO_STATUS_SUCCESS
, wxT("Couldn't create cairo pattern"));
696 void wxCairoBrushData::Init()
698 m_brushPattern
= NULL
;
701 //-----------------------------------------------------------------------------
702 // wxCairoFontData implementation
703 //-----------------------------------------------------------------------------
705 wxCairoFontData::wxCairoFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
,
706 const wxColour
& col
) : wxGraphicsObjectRefData(renderer
)
708 m_red
= col
.Red()/255.0;
709 m_green
= col
.Green()/255.0;
710 m_blue
= col
.Blue()/255.0;
711 m_alpha
= col
.Alpha()/255.0;
712 m_size
= font
.GetPointSize();
715 m_font
= cairo_atsui_font_face_create_for_atsu_font_id( font
.MacGetATSUFontID() );
716 #elif defined(__WXGTK__)
717 m_font
= pango_font_description_copy( font
.GetNativeFontInfo()->description
);
719 m_fontName
= font
.GetFaceName().mb_str(wxConvUTF8
);
720 m_slant
= font
.GetStyle() == wxFONTSTYLE_ITALIC
? CAIRO_FONT_SLANT_ITALIC
:CAIRO_FONT_SLANT_NORMAL
;
721 m_weight
= font
.GetWeight() == wxFONTWEIGHT_BOLD
? CAIRO_FONT_WEIGHT_BOLD
:CAIRO_FONT_WEIGHT_NORMAL
;
725 wxCairoFontData::~wxCairoFontData()
728 cairo_font_face_destroy( m_font
);
729 #elif defined(__WXGTK__)
730 pango_font_description_free( m_font
);
735 void wxCairoFontData::Apply( wxGraphicsContext
* context
)
737 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
738 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
740 // the rest is done using Pango layouts
741 #elif defined(__WXMAC__)
742 cairo_set_font_face(ctext
, m_font
);
744 cairo_select_font_face(ctext
, m_fontName
, m_slant
, m_weights
);
745 cairo_set_font_size(ctext
, m_size
);
749 //-----------------------------------------------------------------------------
750 // wxCairoPathData implementation
751 //-----------------------------------------------------------------------------
753 wxCairoPathData::wxCairoPathData( wxGraphicsRenderer
* renderer
, cairo_t
* pathcontext
)
754 : wxGraphicsPathData(renderer
)
758 m_pathContext
= pathcontext
;
762 cairo_surface_t
* surface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,1,1);
763 m_pathContext
= cairo_create(surface
);
764 cairo_surface_destroy (surface
);
768 wxCairoPathData::~wxCairoPathData()
770 cairo_destroy(m_pathContext
);
773 wxGraphicsObjectRefData
*wxCairoPathData::Clone() const
775 cairo_surface_t
* surface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,1,1);
776 cairo_t
* pathcontext
= cairo_create(surface
);
777 cairo_surface_destroy (surface
);
779 cairo_path_t
* path
= cairo_copy_path(m_pathContext
);
780 cairo_append_path(pathcontext
, path
);
781 cairo_path_destroy(path
);
782 return new wxCairoPathData( GetRenderer() ,pathcontext
);
786 void* wxCairoPathData::GetNativePath() const
788 return cairo_copy_path(m_pathContext
) ;
791 void wxCairoPathData::UnGetNativePath(void *p
) const
793 cairo_path_destroy((cairo_path_t
*)p
);
800 void wxCairoPathData::MoveToPoint( wxDouble x
, wxDouble y
)
802 cairo_move_to(m_pathContext
,x
,y
);
805 void wxCairoPathData::AddLineToPoint( wxDouble x
, wxDouble y
)
807 cairo_line_to(m_pathContext
,x
,y
);
810 void wxCairoPathData::AddPath( const wxGraphicsPathData
* path
)
812 cairo_path_t
* p
= (cairo_path_t
*)path
->GetNativePath();
813 cairo_append_path(m_pathContext
, p
);
817 void wxCairoPathData::CloseSubpath()
819 cairo_close_path(m_pathContext
);
822 void wxCairoPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
824 cairo_curve_to(m_pathContext
,cx1
,cy1
,cx2
,cy2
,x
,y
);
827 // gets the last point of the current path, (0,0) if not yet set
828 void wxCairoPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
831 cairo_get_current_point(m_pathContext
,&dx
,&dy
);
838 void wxCairoPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, double startAngle
, double endAngle
, bool clockwise
)
840 // as clockwise means positive in our system (y pointing downwards)
841 // TODO make this interpretation dependent of the
843 if ( clockwise
||(endAngle
-startAngle
)>=2*M_PI
)
844 cairo_arc(m_pathContext
,x
,y
,r
,startAngle
,endAngle
);
846 cairo_arc_negative(m_pathContext
,x
,y
,r
,startAngle
,endAngle
);
849 // transforms each point of this path by the matrix
850 void wxCairoPathData::Transform( const wxGraphicsMatrixData
* matrix
)
852 // as we don't have a true path object, we have to apply the inverse
853 // matrix to the context
854 cairo_matrix_t m
= *((cairo_matrix_t
*) matrix
->GetNativeMatrix());
855 cairo_matrix_invert( &m
);
856 cairo_transform(m_pathContext
,&m
);
859 // gets the bounding box enclosing all points (possibly including control points)
860 void wxCairoPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
864 cairo_stroke_extents( m_pathContext
, &x1
, &y1
, &x2
, &y2
);
888 bool wxCairoPathData::Contains( wxDouble x
, wxDouble y
, int WXUNUSED(fillStyle
) ) const
890 return cairo_in_stroke( m_pathContext
, x
, y
) != 0;
893 //-----------------------------------------------------------------------------
894 // wxCairoMatrixData implementation
895 //-----------------------------------------------------------------------------
897 wxCairoMatrixData::wxCairoMatrixData(wxGraphicsRenderer
* renderer
, const cairo_matrix_t
* matrix
)
898 : wxGraphicsMatrixData(renderer
)
904 wxCairoMatrixData::~wxCairoMatrixData()
909 wxGraphicsObjectRefData
*wxCairoMatrixData::Clone() const
911 return new wxCairoMatrixData(GetRenderer(),&m_matrix
);
914 // concatenates the matrix
915 void wxCairoMatrixData::Concat( const wxGraphicsMatrixData
*t
)
917 cairo_matrix_multiply( &m_matrix
, &m_matrix
, (cairo_matrix_t
*) t
->GetNativeMatrix());
920 // sets the matrix to the respective values
921 void wxCairoMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
922 wxDouble tx
, wxDouble ty
)
924 cairo_matrix_init( &m_matrix
, a
, b
, c
, d
, tx
, ty
);
927 // gets the component valuess of the matrix
928 void wxCairoMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
929 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
931 if (a
) *a
= m_matrix
.xx
;
932 if (b
) *b
= m_matrix
.yx
;
933 if (c
) *c
= m_matrix
.xy
;
934 if (d
) *d
= m_matrix
.yy
;
935 if (tx
) *tx
= m_matrix
.x0
;
936 if (ty
) *ty
= m_matrix
.y0
;
939 // makes this the inverse matrix
940 void wxCairoMatrixData::Invert()
942 cairo_matrix_invert( &m_matrix
);
945 // returns true if the elements of the transformation matrix are equal ?
946 bool wxCairoMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
948 const cairo_matrix_t
* tm
= (cairo_matrix_t
*) t
->GetNativeMatrix();
950 m_matrix
.xx
== tm
->xx
&&
951 m_matrix
.yx
== tm
->yx
&&
952 m_matrix
.xy
== tm
->xy
&&
953 m_matrix
.yy
== tm
->yy
&&
954 m_matrix
.x0
== tm
->x0
&&
955 m_matrix
.y0
== tm
->y0
) ;
958 // return true if this is the identity matrix
959 bool wxCairoMatrixData::IsIdentity() const
961 return ( m_matrix
.xx
== 1 && m_matrix
.yy
== 1 &&
962 m_matrix
.yx
== 0 && m_matrix
.xy
== 0 && m_matrix
.x0
== 0 && m_matrix
.y0
== 0);
969 // add the translation to this matrix
970 void wxCairoMatrixData::Translate( wxDouble dx
, wxDouble dy
)
972 cairo_matrix_translate( &m_matrix
, dx
, dy
) ;
975 // add the scale to this matrix
976 void wxCairoMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
978 cairo_matrix_scale( &m_matrix
, xScale
, yScale
) ;
981 // add the rotation to this matrix (radians)
982 void wxCairoMatrixData::Rotate( wxDouble angle
)
984 cairo_matrix_rotate( &m_matrix
, angle
) ;
988 // apply the transforms
991 // applies that matrix to the point
992 void wxCairoMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
994 double lx
= *x
, ly
= *y
;
995 cairo_matrix_transform_point( &m_matrix
, &lx
, &ly
);
1000 // applies the matrix except for translations
1001 void wxCairoMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
1003 double lx
= *dx
, ly
= *dy
;
1004 cairo_matrix_transform_distance( &m_matrix
, &lx
, &ly
);
1009 // returns the native representation
1010 void * wxCairoMatrixData::GetNativeMatrix() const
1012 return (void*) &m_matrix
;
1015 //-----------------------------------------------------------------------------
1016 // wxCairoContext implementation
1017 //-----------------------------------------------------------------------------
1019 class wxCairoOffsetHelper
1022 wxCairoOffsetHelper( cairo_t
* ctx
, bool offset
)
1027 cairo_translate( m_ctx
, 0.5, 0.5 );
1029 ~wxCairoOffsetHelper( )
1032 cairo_translate( m_ctx
, -0.5, -0.5 );
1039 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, const wxWindowDC
& dc
)
1040 : wxGraphicsContext(renderer
)
1043 Init( gdk_cairo_create( dc
.m_window
) );
1047 dc
.GetSize( &width
, &height
);
1048 CGContextRef cgcontext
= (CGContextRef
)dc
.GetWindow()->MacGetCGContextRef();
1049 cairo_surface_t
* surface
= cairo_quartz_surface_create_for_cg_context(cgcontext
, width
, height
);
1050 Init( cairo_create( surface
) );
1051 cairo_surface_destroy( surface
);
1056 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, GdkDrawable
*drawable
)
1057 : wxGraphicsContext(renderer
)
1059 Init( gdk_cairo_create( drawable
) );
1063 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, cairo_t
*context
)
1064 : wxGraphicsContext(renderer
)
1069 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, wxWindow
*window
)
1070 : wxGraphicsContext(renderer
)
1073 // something along these lines (copied from dcclient)
1075 GtkWidget
*widget
= window
->m_wxwindow
;
1077 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
1078 // code should still be able to create wxClientDCs for them, so we will
1079 // use the parent window here then.
1082 window
= window
->GetParent();
1083 widget
= window
->m_wxwindow
;
1086 wxASSERT_MSG( widget
, wxT("wxCairoContext needs a widget") );
1088 wxPizza
*pizza
= WX_PIZZA( widget
);
1089 GdkDrawable
* drawable
= pizza
->m_backing_window
;
1090 Init( gdk_cairo_create( drawable
) ) ;
1094 wxCairoContext::~wxCairoContext()
1100 cairo_destroy(m_context
);
1104 void wxCairoContext::Init(cairo_t
*context
)
1106 m_context
= context
;
1112 void wxCairoContext::Clip( const wxRegion
& region
)
1114 // Create a path with all the rectangles in the region
1115 wxGraphicsPath path
= GetRenderer()->CreatePath();
1116 wxRegionIterator
ri(region
);
1119 path
.AddRectangle(ri
.GetX(), ri
.GetY(), ri
.GetW(), ri
.GetH());
1123 // Put it in the context
1124 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1125 cairo_append_path(m_context
, cp
);
1127 // clip to that path
1128 cairo_clip(m_context
);
1129 path
.UnGetNativePath(cp
);
1132 void wxCairoContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1134 // Create a path with this rectangle
1135 wxGraphicsPath path
= GetRenderer()->CreatePath();
1136 path
.AddRectangle(x
,y
,w
,h
);
1138 // Put it in the context
1139 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1140 cairo_append_path(m_context
, cp
);
1142 // clip to that path
1143 cairo_clip(m_context
);
1144 path
.UnGetNativePath(cp
);
1147 void wxCairoContext::ResetClip()
1149 cairo_reset_clip(m_context
);
1153 void wxCairoContext::StrokePath( const wxGraphicsPath
& path
)
1155 if ( !m_pen
.IsNull() )
1157 wxCairoOffsetHelper
helper( m_context
, ShouldOffset() ) ;
1158 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1159 cairo_append_path(m_context
,cp
);
1160 ((wxCairoPenData
*)m_pen
.GetRefData())->Apply(this);
1161 cairo_stroke(m_context
);
1162 path
.UnGetNativePath(cp
);
1166 void wxCairoContext::FillPath( const wxGraphicsPath
& path
, int fillStyle
)
1168 if ( !m_brush
.IsNull() )
1170 wxCairoOffsetHelper
helper( m_context
, ShouldOffset() ) ;
1171 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1172 cairo_append_path(m_context
,cp
);
1173 ((wxCairoBrushData
*)m_brush
.GetRefData())->Apply(this);
1174 cairo_set_fill_rule(m_context
,fillStyle
==wxODDEVEN_RULE
? CAIRO_FILL_RULE_EVEN_ODD
: CAIRO_FILL_RULE_WINDING
);
1175 cairo_fill(m_context
);
1176 path
.UnGetNativePath(cp
);
1180 void wxCairoContext::Rotate( wxDouble angle
)
1182 cairo_rotate(m_context
,angle
);
1185 void wxCairoContext::Translate( wxDouble dx
, wxDouble dy
)
1187 cairo_translate(m_context
,dx
,dy
);
1190 void wxCairoContext::Scale( wxDouble xScale
, wxDouble yScale
)
1192 cairo_scale(m_context
,xScale
,yScale
);
1195 // concatenates this transform with the current transform of this context
1196 void wxCairoContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1198 cairo_transform(m_context
,(const cairo_matrix_t
*) matrix
.GetNativeMatrix());
1201 // sets the transform of this context
1202 void wxCairoContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1204 cairo_set_matrix(m_context
,(const cairo_matrix_t
*) matrix
.GetNativeMatrix());
1207 // gets the matrix of this context
1208 wxGraphicsMatrix
wxCairoContext::GetTransform() const
1210 wxGraphicsMatrix matrix
= CreateMatrix();
1211 cairo_get_matrix(m_context
,(cairo_matrix_t
*) matrix
.GetNativeMatrix());
1217 void wxCairoContext::PushState()
1219 cairo_save(m_context
);
1222 void wxCairoContext::PopState()
1224 cairo_restore(m_context
);
1227 void wxCairoContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1229 wxCHECK_RET( bmp
.IsOk(), wxT("Invalid bitmap in wxCairoContext::DrawBitmap"));
1231 cairo_surface_t
* surface
;
1232 int bw
= bmp
.GetWidth();
1233 int bh
= bmp
.GetHeight();
1234 wxBitmap bmpSource
= bmp
; // we need a non-const instance
1235 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1236 wxUint32
* data
= (wxUint32
*)buffer
;
1238 // Create a surface object and copy the bitmap pixel data to it. if the
1239 // image has alpha (or a mask represented as alpha) then we'll use a
1240 // different format and iterator than if it doesn't...
1241 if (bmpSource
.HasAlpha() || bmpSource
.GetMask())
1243 surface
= cairo_image_surface_create_for_data(
1244 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1245 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1246 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1248 wxAlphaPixelData::Iterator
p(pixData
);
1249 for (int y
=0; y
<bh
; y
++)
1251 wxAlphaPixelData::Iterator rowStart
= p
;
1252 for (int x
=0; x
<bw
; x
++)
1254 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1255 // with alpha in the upper 8 bits, then red, then green, then
1256 // blue. The 32-bit quantities are stored native-endian.
1257 // Pre-multiplied alpha is used.
1258 unsigned char alpha
= p
.Alpha();
1262 *data
= ( alpha
<< 24
1263 | (p
.Red() * alpha
/255) << 16
1264 | (p
.Green() * alpha
/255) << 8
1265 | (p
.Blue() * alpha
/255) );
1270 p
.OffsetY(pixData
, 1);
1275 surface
= cairo_image_surface_create_for_data(
1276 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1277 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1278 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1280 wxNativePixelData::Iterator
p(pixData
);
1281 for (int y
=0; y
<bh
; y
++)
1283 wxNativePixelData::Iterator rowStart
= p
;
1284 for (int x
=0; x
<bw
; x
++)
1286 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1287 // the upper 8 bits unused. Red, Green, and Blue are stored in
1288 // the remaining 24 bits in that order. The 32-bit quantities
1289 // are stored native-endian.
1290 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1295 p
.OffsetY(pixData
, 1);
1302 // In case we're scaling the image by using a width and height different
1303 // than the bitmap's size create a pattern transformation on the surface and
1304 // draw the transformed pattern.
1305 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1306 wxDouble scaleX
= w
/ bw
;
1307 wxDouble scaleY
= h
/ bh
;
1308 cairo_scale(m_context
, scaleX
, scaleY
);
1310 // prepare to draw the image
1311 cairo_translate(m_context
, x
, y
);
1312 cairo_set_source(m_context
, pattern
);
1313 // use the original size here since the context is scaled already...
1314 cairo_rectangle(m_context
, 0, 0, bw
, bh
);
1315 // fill the rectangle using the pattern
1316 cairo_fill(m_context
);
1319 cairo_pattern_destroy(pattern
);
1320 cairo_surface_destroy(surface
);
1325 void wxCairoContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1327 // An icon is a bitmap on wxGTK, so do this the easy way. When we want to
1328 // start using the Cairo backend on other platforms then we may need to
1329 // fiddle with this...
1330 DrawBitmap(icon
, x
, y
, w
, h
);
1334 void wxCairoContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1336 if ( m_font
.IsNull() || str
.empty())
1340 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( str
);
1343 size_t datalen
= strlen(data
);
1344 ((wxCairoFontData
*)m_font
.GetRefData())->Apply(this);
1346 PangoLayout
*layout
= pango_cairo_create_layout (m_context
);
1347 pango_layout_set_font_description( layout
, ((wxCairoFontData
*)m_font
.GetRefData())->GetFont());
1348 pango_layout_set_text(layout
, data
, datalen
);
1349 cairo_move_to(m_context
, x
, y
);
1350 pango_cairo_show_layout (m_context
, layout
);
1352 g_object_unref (layout
);
1354 ((wxCairoFontData
*)m_font
.GetRefData())->Apply(this);
1355 // Cairo's x,y for drawing text is at the baseline, so we need to adjust
1356 // the position we move to by the ascent.
1357 cairo_font_extents_t fe
;
1358 cairo_font_extents(m_context
, &fe
);
1359 cairo_move_to(m_context
, x
, y
+fe
.ascent
);
1361 const wxWX2MBbuf
buf(str
.mb_str(wxConvUTF8
));
1362 cairo_show_text(m_context
,buf
);
1366 void wxCairoContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1367 wxDouble
*descent
, wxDouble
*externalLeading
) const
1375 if ( externalLeading
)
1376 *externalLeading
= 0;
1378 if ( m_font
.IsNull() || str
.empty())
1384 PangoLayout
*layout
= pango_cairo_create_layout (m_context
);
1385 pango_layout_set_font_description( layout
, ((wxCairoFontData
*)m_font
.GetRefData())->GetFont());
1386 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( str
);
1391 pango_layout_set_text( layout
, data
, strlen(data
) );
1392 pango_layout_get_pixel_size (layout
, &w
, &h
);
1399 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
1400 int baseline
= pango_layout_iter_get_baseline(iter
);
1401 pango_layout_iter_free(iter
);
1402 *descent
= h
- PANGO_PIXELS(baseline
);
1404 g_object_unref (layout
);
1406 ((wxCairoFontData
*)m_font
.GetRefData())->Apply((wxCairoContext
*)this);
1410 const wxWX2MBbuf
buf(str
.mb_str(wxConvUTF8
));
1411 cairo_text_extents_t te
;
1412 cairo_text_extents(m_context
, buf
, &te
);
1416 if (height
|| descent
|| externalLeading
)
1418 cairo_font_extents_t fe
;
1419 cairo_font_extents(m_context
, &fe
);
1422 *height
= fe
.height
;
1424 *descent
= fe
.descent
;
1425 if ( externalLeading
)
1426 *externalLeading
= wxMax(0, fe
.height
- (fe
.ascent
+ fe
.descent
));
1431 void wxCairoContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1434 widths
.Add(0, text
.length());
1442 void * wxCairoContext::GetNativeContext()
1447 //-----------------------------------------------------------------------------
1448 // wxCairoRenderer declaration
1449 //-----------------------------------------------------------------------------
1451 class WXDLLIMPEXP_CORE wxCairoRenderer
: public wxGraphicsRenderer
1454 wxCairoRenderer() {}
1456 virtual ~wxCairoRenderer() {}
1460 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
1463 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
);
1466 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
1468 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
1470 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
1472 virtual wxGraphicsContext
* CreateMeasuringContext();
1476 virtual wxGraphicsPath
CreatePath();
1480 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
1481 wxDouble tx
=0.0, wxDouble ty
=0.0);
1484 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
1486 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
1488 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1489 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
1490 const wxColour
&c1
, const wxColour
&c2
) ;
1492 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1493 // with radius r and color cColor
1494 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
1495 const wxColour
&oColor
, const wxColour
&cColor
) ;
1498 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
1501 DECLARE_DYNAMIC_CLASS_NO_COPY(wxCairoRenderer
)
1504 //-----------------------------------------------------------------------------
1505 // wxCairoRenderer implementation
1506 //-----------------------------------------------------------------------------
1508 IMPLEMENT_DYNAMIC_CLASS(wxCairoRenderer
,wxGraphicsRenderer
)
1510 static wxCairoRenderer gs_cairoGraphicsRenderer
;
1513 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
1515 return &gs_cairoGraphicsRenderer
;
1519 wxGraphicsContext
* wxCairoRenderer::CreateContext( const wxWindowDC
& dc
)
1521 return new wxCairoContext(this,dc
);
1525 wxGraphicsContext
* wxCairoRenderer::CreateContext( const wxMemoryDC
& dc
)
1531 wxGraphicsContext
* wxCairoRenderer::CreateContextFromNativeContext( void * context
)
1533 return new wxCairoContext(this,(cairo_t
*)context
);
1537 wxGraphicsContext
* wxCairoRenderer::CreateContextFromNativeWindow( void * window
)
1540 return new wxCairoContext(this,(GdkDrawable
*)window
);
1546 wxGraphicsContext
* wxCairoRenderer::CreateMeasuringContext()
1552 wxGraphicsContext
* wxCairoRenderer::CreateContext( wxWindow
* window
)
1554 return new wxCairoContext(this, window
);
1559 wxGraphicsPath
wxCairoRenderer::CreatePath()
1561 wxGraphicsPath path
;
1562 path
.SetRefData( new wxCairoPathData(this) );
1569 wxGraphicsMatrix
wxCairoRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
1570 wxDouble tx
, wxDouble ty
)
1574 wxCairoMatrixData
* data
= new wxCairoMatrixData( this );
1575 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
1580 wxGraphicsPen
wxCairoRenderer::CreatePen(const wxPen
& pen
)
1582 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
1583 return wxNullGraphicsPen
;
1587 p
.SetRefData(new wxCairoPenData( this, pen
));
1592 wxGraphicsBrush
wxCairoRenderer::CreateBrush(const wxBrush
& brush
)
1594 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
1595 return wxNullGraphicsBrush
;
1599 p
.SetRefData(new wxCairoBrushData( this, brush
));
1604 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1605 wxGraphicsBrush
wxCairoRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
1606 const wxColour
&c1
, const wxColour
&c2
)
1609 wxCairoBrushData
* d
= new wxCairoBrushData( this );
1610 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
1615 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1616 // with radius r and color cColor
1617 wxGraphicsBrush
wxCairoRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
1618 const wxColour
&oColor
, const wxColour
&cColor
)
1621 wxCairoBrushData
* d
= new wxCairoBrushData( this );
1622 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
1628 wxGraphicsFont
wxCairoRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
1633 p
.SetRefData(new wxCairoFontData( this , font
, col
));
1637 return wxNullGraphicsFont
;
1640 #endif // wxUSE_GRAPHICS_CONTEXT