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"
18 #if wxUSE_GRAPHICS_CONTEXT
24 #include "wx/window.h"
27 #include "wx/dialog.h"
29 #include "wx/bitmap.h"
30 #include "wx/dcmemory.h"
33 #include "wx/dcprint.h"
34 #include "wx/module.h"
37 #include "wx/graphics.h"
38 #include "wx/rawbmp.h"
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
48 const double RAD2DEG
= 180.0 / M_PI
;
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 static inline double dmin(double a
, double b
)
58 static inline double dmax(double a
, double b
)
63 static inline double DegToRad(double deg
)
65 return (deg
* M_PI
) / 180.0;
67 static inline double RadToDeg(double deg
)
69 return (deg
* 180.0) / M_PI
;
72 //-----------------------------------------------------------------------------
73 // device context implementation
75 // more and more of the dc functionality should be implemented by calling
76 // the appropricate wxCairoContext, but we will have to do that step by step
77 // also coordinate conversions should be moved to native matrix ops
78 //-----------------------------------------------------------------------------
80 // we always stock two context states, one at entry, to be able to preserve the
81 // state we were called with, the other one after changing to HI Graphics orientation
82 // (this one is used for getting back clippings etc)
84 //-----------------------------------------------------------------------------
85 // wxGraphicsPath implementation
86 //-----------------------------------------------------------------------------
88 // TODO remove this dependency (gdiplus needs the macros)
91 #define max(a,b) (((a) > (b)) ? (a) : (b))
95 #define min(a,b) (((a) < (b)) ? (a) : (b))
101 #include "wx/fontutil.h"
105 #include <cairo-win32.h>
109 #include "wx/mac/private.h"
110 #include <cairo-quartz.h>
111 #include <cairo-atsui.h>
114 class WXDLLIMPEXP_CORE wxCairoPathData
: public wxGraphicsPathData
117 wxCairoPathData(wxGraphicsRenderer
* renderer
, cairo_t
* path
= NULL
);
120 virtual wxGraphicsObjectRefData
*Clone() const;
123 // These are the path primitives from which everything else can be constructed
126 // begins a new subpath at (x,y)
127 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
129 // adds a straight line from the current point to (x,y)
130 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
132 // adds a cubic Bezier curve from the current point, using two control points and an end point
133 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
136 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
137 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
) ;
139 // gets the last point of the current path, (0,0) if not yet set
140 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
143 virtual void AddPath( const wxGraphicsPathData
* path
);
145 // closes the current sub-path
146 virtual void CloseSubpath();
149 // These are convenience functions which - if not available natively will be assembled
150 // using the primitives from above
155 // appends a rectangle as a new closed subpath
156 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) ;
157 // appends an ellipsis as a new closed subpath fitting the passed rectangle
158 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
160 // 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)
161 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
164 // returns the native path
165 virtual void * GetNativePath() const ;
167 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
168 virtual void UnGetNativePath(void *p
) const;
170 // transforms each point of this path by the matrix
171 virtual void Transform( const wxGraphicsMatrixData
* matrix
) ;
173 // gets the bounding box enclosing all points (possibly including control points)
174 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const;
176 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxWINDING_RULE
) const;
179 cairo_t
* m_pathContext
;
182 class WXDLLIMPEXP_CORE wxCairoMatrixData
: public wxGraphicsMatrixData
185 wxCairoMatrixData(wxGraphicsRenderer
* renderer
, const cairo_matrix_t
* matrix
= NULL
) ;
186 virtual ~wxCairoMatrixData() ;
188 virtual wxGraphicsObjectRefData
*Clone() const ;
190 // concatenates the matrix
191 virtual void Concat( const wxGraphicsMatrixData
*t
);
193 // sets the matrix to the respective values
194 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
195 wxDouble tx
=0.0, wxDouble ty
=0.0);
197 // gets the component valuess of the matrix
198 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
199 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
201 // makes this the inverse matrix
202 virtual void Invert();
204 // returns true if the elements of the transformation matrix are equal ?
205 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
207 // return true if this is the identity matrix
208 virtual bool IsIdentity() const;
214 // add the translation to this matrix
215 virtual void Translate( wxDouble dx
, wxDouble dy
);
217 // add the scale to this matrix
218 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
220 // add the rotation to this matrix (radians)
221 virtual void Rotate( wxDouble angle
);
224 // apply the transforms
227 // applies that matrix to the point
228 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
230 // applies the matrix except for translations
231 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
233 // returns the native representation
234 virtual void * GetNativeMatrix() const;
236 cairo_matrix_t m_matrix
;
239 class WXDLLIMPEXP_CORE wxCairoPenData
: public wxGraphicsObjectRefData
242 wxCairoPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
247 virtual void Apply( wxGraphicsContext
* context
);
248 virtual wxDouble
GetWidth() { return m_width
; }
258 cairo_line_cap_t m_cap
;
259 cairo_line_join_t m_join
;
262 const double *m_lengths
;
263 double *m_userLengths
;
268 class WXDLLIMPEXP_CORE wxCairoBrushData
: public wxGraphicsObjectRefData
271 wxCairoBrushData( wxGraphicsRenderer
* renderer
);
272 wxCairoBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
273 ~wxCairoBrushData ();
275 virtual void Apply( wxGraphicsContext
* context
);
276 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
277 const wxColour
&c1
, const wxColour
&c2
);
278 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
279 const wxColour
&oColor
, const wxColour
&cColor
);
290 cairo_pattern_t
* m_brushPattern
;
293 class wxCairoFontData
: public wxGraphicsObjectRefData
296 wxCairoFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
299 virtual void Apply( wxGraphicsContext
* context
);
301 const PangoFontDescription
* GetFont() const { return m_font
; }
310 cairo_font_face_t
*m_font
;
311 #elif defined(__WXGTK__)
312 PangoFontDescription
* m_font
;
314 wxCharBuffer m_fontName
;
315 cairo_font_slant_t m_slant
;
316 cairo_font_weight_t m_weight
;
320 class WXDLLIMPEXP_CORE wxCairoContext
: public wxGraphicsContext
322 DECLARE_NO_COPY_CLASS(wxCairoContext
)
325 wxCairoContext( wxGraphicsRenderer
* renderer
, const wxWindowDC
& dc
);
327 wxCairoContext( wxGraphicsRenderer
* renderer
, GdkDrawable
*drawable
);
329 wxCairoContext( wxGraphicsRenderer
* renderer
, cairo_t
*context
);
330 wxCairoContext( wxGraphicsRenderer
* renderer
, wxWindow
*window
);
332 virtual ~wxCairoContext();
334 virtual bool ShouldOffset() const
337 if ( !m_pen
.IsNull() )
339 penwidth
= (int)((wxCairoPenData
*)m_pen
.GetRefData())->GetWidth();
343 return ( penwidth
% 2 ) == 1;
346 virtual void Clip( const wxRegion
®ion
);
348 // clips drawings to the rect
349 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
351 // resets the clipping to original extent
352 virtual void ResetClip();
354 virtual void * GetNativeContext();
356 virtual void StrokePath( const wxGraphicsPath
& p
);
357 virtual void FillPath( const wxGraphicsPath
& p
, int fillStyle
= wxWINDING_RULE
);
359 virtual void Translate( wxDouble dx
, wxDouble dy
);
360 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
361 virtual void Rotate( wxDouble angle
);
363 // concatenates this transform with the current transform of this context
364 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
366 // sets the transform of this context
367 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
369 // gets the matrix of this context
370 virtual wxGraphicsMatrix
GetTransform() const;
372 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
373 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
374 virtual void PushState();
375 virtual void PopState();
377 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
378 virtual void GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
379 wxDouble
*descent
, wxDouble
*externalLeading
) const;
380 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
383 void Init(cairo_t
*context
);
388 //-----------------------------------------------------------------------------
389 // wxCairoPenData implementation
390 //-----------------------------------------------------------------------------
392 wxCairoPenData::~wxCairoPenData()
394 delete[] m_userLengths
;
397 void wxCairoPenData::Init()
400 m_userLengths
= NULL
;
405 wxCairoPenData::wxCairoPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
)
406 : wxGraphicsObjectRefData(renderer
)
410 m_width
= m_pen
.GetWidth();
414 m_red
= m_pen
.GetColour().Red()/255.0;
415 m_green
= m_pen
.GetColour().Green()/255.0;
416 m_blue
= m_pen
.GetColour().Blue()/255.0;
417 m_alpha
= m_pen
.GetColour().Alpha()/255.0;
419 switch ( m_pen
.GetCap() )
422 m_cap
= CAIRO_LINE_CAP_ROUND
;
425 case wxCAP_PROJECTING
:
426 m_cap
= CAIRO_LINE_CAP_SQUARE
;
430 m_cap
= CAIRO_LINE_CAP_BUTT
;
434 m_cap
= CAIRO_LINE_CAP_BUTT
;
438 switch ( m_pen
.GetJoin() )
441 m_join
= CAIRO_LINE_JOIN_BEVEL
;
445 m_join
= CAIRO_LINE_JOIN_MITER
;
449 m_join
= CAIRO_LINE_JOIN_ROUND
;
453 m_join
= CAIRO_LINE_JOIN_MITER
;
457 const double dashUnit
= m_width
< 1.0 ? 1.0 : m_width
;
458 const double dotted
[] =
460 dashUnit
, dashUnit
+ 2.0
462 static const double short_dashed
[] =
466 static const double dashed
[] =
470 static const double dotted_dashed
[] =
472 9.0 , 6.0 , 3.0 , 3.0
475 switch ( m_pen
.GetStyle() )
481 m_count
= WXSIZEOF(dotted
);
482 m_userLengths
= new double[ m_count
] ;
483 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
484 m_lengths
= m_userLengths
;
489 m_count
= WXSIZEOF(dashed
);
493 m_lengths
= short_dashed
;
494 m_count
= WXSIZEOF(short_dashed
);
498 m_lengths
= dotted_dashed
;
499 m_count
= WXSIZEOF(dotted_dashed
);
505 m_count
= m_pen
.GetDashes( &wxdashes
) ;
506 if ((wxdashes
!= NULL
) && (m_count
> 0))
508 m_userLengths
= new double[m_count
] ;
509 for ( int i
= 0 ; i
< m_count
; ++i
)
511 m_userLengths
[i
] = wxdashes
[i
] * dashUnit
;
513 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
514 m_userLengths
[i
] = dashUnit
+ 2.0 ;
515 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
516 m_userLengths
[i
] = dashUnit
;
519 m_lengths
= m_userLengths
;
525 wxBitmap* bmp = pen.GetStipple();
526 if ( bmp && bmp->Ok() )
528 wxDELETE( m_penImage );
529 wxDELETE( m_penBrush );
530 m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
531 m_penBrush = new TextureBrush(m_penImage);
532 m_pen->SetBrush( m_penBrush );
538 if ( m_pen
.GetStyle() >= wxFIRST_HATCH
&& m_pen
.GetStyle() <= wxLAST_HATCH
)
541 wxDELETE( m_penBrush );
542 HatchStyle style = HatchStyleHorizontal;
543 switch( pen.GetStyle() )
545 case wxBDIAGONAL_HATCH :
546 style = HatchStyleBackwardDiagonal;
548 case wxCROSSDIAG_HATCH :
549 style = HatchStyleDiagonalCross;
551 case wxFDIAGONAL_HATCH :
552 style = HatchStyleForwardDiagonal;
555 style = HatchStyleCross;
557 case wxHORIZONTAL_HATCH :
558 style = HatchStyleHorizontal;
560 case wxVERTICAL_HATCH :
561 style = HatchStyleVertical;
565 m_penBrush = new HatchBrush(style,Color( pen.GetColour().Alpha() , pen.GetColour().Red() ,
566 pen.GetColour().Green() , pen.GetColour().Blue() ), Color.Transparent );
567 m_pen->SetBrush( m_penBrush )
574 void wxCairoPenData::Apply( wxGraphicsContext
* context
)
576 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
577 cairo_set_line_width(ctext
,m_width
);
578 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
579 cairo_set_line_cap(ctext
,m_cap
);
580 cairo_set_line_join(ctext
,m_join
);
581 cairo_set_dash(ctext
,(double*)m_lengths
,m_count
,0.0);
584 //-----------------------------------------------------------------------------
585 // wxCairoBrushData implementation
586 //-----------------------------------------------------------------------------
588 wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer
* renderer
)
589 : wxGraphicsObjectRefData( renderer
)
594 wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
)
595 : wxGraphicsObjectRefData(renderer
)
599 m_red
= brush
.GetColour().Red()/255.0;
600 m_green
= brush
.GetColour().Green()/255.0;
601 m_blue
= brush
.GetColour().Blue()/255.0;
602 m_alpha
= brush
.GetColour().Alpha()/255.0;
604 if ( brush.GetStyle() == wxSOLID)
606 m_brush = new SolidBrush( Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
607 brush.GetColour().Green() , brush.GetColour().Blue() ) );
609 else if ( brush.IsHatch() )
611 HatchStyle style = HatchStyleHorizontal;
612 switch( brush.GetStyle() )
614 case wxBDIAGONAL_HATCH :
615 style = HatchStyleBackwardDiagonal;
617 case wxCROSSDIAG_HATCH :
618 style = HatchStyleDiagonalCross;
620 case wxFDIAGONAL_HATCH :
621 style = HatchStyleForwardDiagonal;
624 style = HatchStyleCross;
626 case wxHORIZONTAL_HATCH :
627 style = HatchStyleHorizontal;
629 case wxVERTICAL_HATCH :
630 style = HatchStyleVertical;
634 m_brush = new HatchBrush(style,Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
635 brush.GetColour().Green() , brush.GetColour().Blue() ), Color.Transparent );
639 wxBitmap* bmp = brush.GetStipple();
640 if ( bmp && bmp->Ok() )
642 wxDELETE( m_brushImage );
643 m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
644 m_brush = new TextureBrush(m_brushImage);
650 wxCairoBrushData::~wxCairoBrushData ()
653 cairo_pattern_destroy(m_brushPattern
);
656 void wxCairoBrushData::Apply( wxGraphicsContext
* context
)
658 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
659 if ( m_brushPattern
)
661 cairo_set_source(ctext
,m_brushPattern
);
665 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
669 void wxCairoBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
670 const wxColour
&c1
, const wxColour
&c2
)
672 m_brushPattern
= cairo_pattern_create_linear(x1
,y1
,x2
,y2
);
673 cairo_pattern_add_color_stop_rgba(m_brushPattern
,0.0,c1
.Red()/255.0,
674 c1
.Green()/255.0, c1
.Blue()/255.0,c1
.Alpha()/255.0);
675 cairo_pattern_add_color_stop_rgba(m_brushPattern
,1.0,c2
.Red()/255.0,
676 c2
.Green()/255.0, c2
.Blue()/255.0,c2
.Alpha()/255.0);
677 wxASSERT_MSG(cairo_pattern_status(m_brushPattern
) == CAIRO_STATUS_SUCCESS
, wxT("Couldn't create cairo pattern"));
680 void wxCairoBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
681 const wxColour
&oColor
, const wxColour
&cColor
)
683 m_brushPattern
= cairo_pattern_create_radial(xo
,yo
,0.0,xc
,yc
,radius
);
684 cairo_pattern_add_color_stop_rgba(m_brushPattern
,0.0,oColor
.Red()/255.0,
685 oColor
.Green()/255.0, oColor
.Blue()/255.0,oColor
.Alpha()/255.0);
686 cairo_pattern_add_color_stop_rgba(m_brushPattern
,1.0,cColor
.Red()/255.0,
687 cColor
.Green()/255.0, cColor
.Blue()/255.0,cColor
.Alpha()/255.0);
688 wxASSERT_MSG(cairo_pattern_status(m_brushPattern
) == CAIRO_STATUS_SUCCESS
, wxT("Couldn't create cairo pattern"));
691 void wxCairoBrushData::Init()
693 m_brushPattern
= NULL
;
696 //-----------------------------------------------------------------------------
697 // wxCairoFontData implementation
698 //-----------------------------------------------------------------------------
700 wxCairoFontData::wxCairoFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
,
701 const wxColour
& col
) : wxGraphicsObjectRefData(renderer
)
703 m_red
= col
.Red()/255.0;
704 m_green
= col
.Green()/255.0;
705 m_blue
= col
.Blue()/255.0;
706 m_alpha
= col
.Alpha()/255.0;
707 m_size
= font
.GetPointSize();
710 m_font
= cairo_atsui_font_face_create_for_atsu_font_id( font
.MacGetATSUFontID() );
711 #elif defined(__WXGTK__)
712 m_font
= pango_font_description_copy( font
.GetNativeFontInfo()->description
);
714 m_fontName
= font
.GetFaceName().mb_str(wxConvUTF8
);
715 m_slant
= font
.GetStyle() == wxFONTSTYLE_ITALIC
? CAIRO_FONT_SLANT_ITALIC
:CAIRO_FONT_SLANT_NORMAL
;
716 m_weight
= font
.GetWeight() == wxFONTWEIGHT_BOLD
? CAIRO_FONT_WEIGHT_BOLD
:CAIRO_FONT_WEIGHT_NORMAL
;
720 wxCairoFontData::~wxCairoFontData()
723 cairo_font_face_destroy( m_font
);
724 #elif defined(__WXGTK__)
725 pango_font_description_free( m_font
);
730 void wxCairoFontData::Apply( wxGraphicsContext
* context
)
732 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
733 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
735 // the rest is done using Pango layouts
736 #elif defined(__WXMAC__)
737 cairo_set_font_face(ctext
, m_font
);
738 cairo_set_font_size(ctext
, m_size
);
740 cairo_select_font_face(ctext
, m_fontName
, m_slant
, m_weights
);
741 cairo_set_font_size(ctext
, m_size
);
745 //-----------------------------------------------------------------------------
746 // wxCairoPathData implementation
747 //-----------------------------------------------------------------------------
749 wxCairoPathData::wxCairoPathData( wxGraphicsRenderer
* renderer
, cairo_t
* pathcontext
)
750 : wxGraphicsPathData(renderer
)
754 m_pathContext
= pathcontext
;
758 cairo_surface_t
* surface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,1,1);
759 m_pathContext
= cairo_create(surface
);
760 cairo_surface_destroy (surface
);
764 wxCairoPathData::~wxCairoPathData()
766 cairo_destroy(m_pathContext
);
769 wxGraphicsObjectRefData
*wxCairoPathData::Clone() const
771 cairo_surface_t
* surface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,1,1);
772 cairo_t
* pathcontext
= cairo_create(surface
);
773 cairo_surface_destroy (surface
);
775 cairo_path_t
* path
= cairo_copy_path(m_pathContext
);
776 cairo_append_path(pathcontext
, path
);
777 cairo_path_destroy(path
);
778 return new wxCairoPathData( GetRenderer() ,pathcontext
);
782 void* wxCairoPathData::GetNativePath() const
784 return cairo_copy_path(m_pathContext
) ;
787 void wxCairoPathData::UnGetNativePath(void *p
) const
789 cairo_path_destroy((cairo_path_t
*)p
);
796 void wxCairoPathData::MoveToPoint( wxDouble x
, wxDouble y
)
798 cairo_move_to(m_pathContext
,x
,y
);
801 void wxCairoPathData::AddLineToPoint( wxDouble x
, wxDouble y
)
803 cairo_line_to(m_pathContext
,x
,y
);
806 void wxCairoPathData::AddPath( const wxGraphicsPathData
* path
)
808 cairo_path_t
* p
= (cairo_path_t
*)path
->GetNativePath();
809 cairo_append_path(m_pathContext
, p
);
813 void wxCairoPathData::CloseSubpath()
815 cairo_close_path(m_pathContext
);
818 void wxCairoPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
820 cairo_curve_to(m_pathContext
,cx1
,cy1
,cx2
,cy2
,x
,y
);
823 // gets the last point of the current path, (0,0) if not yet set
824 void wxCairoPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
827 cairo_get_current_point(m_pathContext
,&dx
,&dy
);
834 void wxCairoPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, double startAngle
, double endAngle
, bool clockwise
)
836 // as clockwise means positive in our system (y pointing downwards)
837 // TODO make this interpretation dependent of the
839 if ( clockwise
||(endAngle
-startAngle
)>=2*M_PI
)
840 cairo_arc(m_pathContext
,x
,y
,r
,startAngle
,endAngle
);
842 cairo_arc_negative(m_pathContext
,x
,y
,r
,startAngle
,endAngle
);
845 // transforms each point of this path by the matrix
846 void wxCairoPathData::Transform( const wxGraphicsMatrixData
* matrix
)
848 // as we don't have a true path object, we have to apply the inverse
849 // matrix to the context
850 cairo_matrix_t m
= *((cairo_matrix_t
*) matrix
->GetNativeMatrix());
851 cairo_matrix_invert( &m
);
852 cairo_transform(m_pathContext
,&m
);
855 // gets the bounding box enclosing all points (possibly including control points)
856 void wxCairoPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
860 cairo_stroke_extents( m_pathContext
, &x1
, &y1
, &x2
, &y2
);
884 bool wxCairoPathData::Contains( wxDouble x
, wxDouble y
, int WXUNUSED(fillStyle
) ) const
886 return cairo_in_stroke( m_pathContext
, x
, y
) != 0;
889 //-----------------------------------------------------------------------------
890 // wxCairoMatrixData implementation
891 //-----------------------------------------------------------------------------
893 wxCairoMatrixData::wxCairoMatrixData(wxGraphicsRenderer
* renderer
, const cairo_matrix_t
* matrix
)
894 : wxGraphicsMatrixData(renderer
)
900 wxCairoMatrixData::~wxCairoMatrixData()
905 wxGraphicsObjectRefData
*wxCairoMatrixData::Clone() const
907 return new wxCairoMatrixData(GetRenderer(),&m_matrix
);
910 // concatenates the matrix
911 void wxCairoMatrixData::Concat( const wxGraphicsMatrixData
*t
)
913 cairo_matrix_multiply( &m_matrix
, &m_matrix
, (cairo_matrix_t
*) t
->GetNativeMatrix());
916 // sets the matrix to the respective values
917 void wxCairoMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
918 wxDouble tx
, wxDouble ty
)
920 cairo_matrix_init( &m_matrix
, a
, b
, c
, d
, tx
, ty
);
923 // gets the component valuess of the matrix
924 void wxCairoMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
925 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
927 if (a
) *a
= m_matrix
.xx
;
928 if (b
) *b
= m_matrix
.yx
;
929 if (c
) *c
= m_matrix
.xy
;
930 if (d
) *d
= m_matrix
.yy
;
931 if (tx
) *tx
= m_matrix
.x0
;
932 if (ty
) *ty
= m_matrix
.y0
;
935 // makes this the inverse matrix
936 void wxCairoMatrixData::Invert()
938 cairo_matrix_invert( &m_matrix
);
941 // returns true if the elements of the transformation matrix are equal ?
942 bool wxCairoMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
944 const cairo_matrix_t
* tm
= (cairo_matrix_t
*) t
->GetNativeMatrix();
946 m_matrix
.xx
== tm
->xx
&&
947 m_matrix
.yx
== tm
->yx
&&
948 m_matrix
.xy
== tm
->xy
&&
949 m_matrix
.yy
== tm
->yy
&&
950 m_matrix
.x0
== tm
->x0
&&
951 m_matrix
.y0
== tm
->y0
) ;
954 // return true if this is the identity matrix
955 bool wxCairoMatrixData::IsIdentity() const
957 return ( m_matrix
.xx
== 1 && m_matrix
.yy
== 1 &&
958 m_matrix
.yx
== 0 && m_matrix
.xy
== 0 && m_matrix
.x0
== 0 && m_matrix
.y0
== 0);
965 // add the translation to this matrix
966 void wxCairoMatrixData::Translate( wxDouble dx
, wxDouble dy
)
968 cairo_matrix_translate( &m_matrix
, dx
, dy
) ;
971 // add the scale to this matrix
972 void wxCairoMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
974 cairo_matrix_scale( &m_matrix
, xScale
, yScale
) ;
977 // add the rotation to this matrix (radians)
978 void wxCairoMatrixData::Rotate( wxDouble angle
)
980 cairo_matrix_rotate( &m_matrix
, angle
) ;
984 // apply the transforms
987 // applies that matrix to the point
988 void wxCairoMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
990 double lx
= *x
, ly
= *y
;
991 cairo_matrix_transform_point( &m_matrix
, &lx
, &ly
);
996 // applies the matrix except for translations
997 void wxCairoMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
999 double lx
= *dx
, ly
= *dy
;
1000 cairo_matrix_transform_distance( &m_matrix
, &lx
, &ly
);
1005 // returns the native representation
1006 void * wxCairoMatrixData::GetNativeMatrix() const
1008 return (void*) &m_matrix
;
1011 //-----------------------------------------------------------------------------
1012 // wxCairoContext implementation
1013 //-----------------------------------------------------------------------------
1015 class wxCairoOffsetHelper
1018 wxCairoOffsetHelper( cairo_t
* ctx
, bool offset
)
1023 cairo_translate( m_ctx
, 0.5, 0.5 );
1025 ~wxCairoOffsetHelper( )
1028 cairo_translate( m_ctx
, -0.5, -0.5 );
1035 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, const wxWindowDC
& dc
)
1036 : wxGraphicsContext(renderer
)
1039 Init( gdk_cairo_create( dc
.m_window
) );
1043 dc
.GetSize( &width
, &height
);
1044 CGContextRef cgcontext
= (CGContextRef
)dc
.GetWindow()->MacGetCGContextRef();
1045 cairo_surface_t
* surface
= cairo_quartz_surface_create_for_cg_context(cgcontext
, width
, height
);
1046 Init( cairo_create( surface
) );
1047 cairo_surface_destroy( surface
);
1052 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, GdkDrawable
*drawable
)
1053 : wxGraphicsContext(renderer
)
1055 Init( gdk_cairo_create( drawable
) );
1059 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, cairo_t
*context
)
1060 : wxGraphicsContext(renderer
)
1065 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, wxWindow
*window
)
1066 : wxGraphicsContext(renderer
)
1069 // something along these lines (copied from dcclient)
1071 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
1072 // code should still be able to create wxClientDCs for them, so we will
1073 // use the parent window here then.
1074 if (window
->m_wxwindow
== NULL
)
1076 window
= window
->GetParent();
1079 wxASSERT_MSG( window
->m_wxwindow
, wxT("wxCairoContext needs a widget") );
1081 Init(gdk_cairo_create(window
->GTKGetDrawingWindow()));
1085 wxCairoContext::~wxCairoContext()
1091 cairo_destroy(m_context
);
1095 void wxCairoContext::Init(cairo_t
*context
)
1097 m_context
= context
;
1103 void wxCairoContext::Clip( const wxRegion
& region
)
1105 // Create a path with all the rectangles in the region
1106 wxGraphicsPath path
= GetRenderer()->CreatePath();
1107 wxRegionIterator
ri(region
);
1110 path
.AddRectangle(ri
.GetX(), ri
.GetY(), ri
.GetW(), ri
.GetH());
1114 // Put it in the context
1115 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1116 cairo_append_path(m_context
, cp
);
1118 // clip to that path
1119 cairo_clip(m_context
);
1120 path
.UnGetNativePath(cp
);
1123 void wxCairoContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1125 // Create a path with this rectangle
1126 wxGraphicsPath path
= GetRenderer()->CreatePath();
1127 path
.AddRectangle(x
,y
,w
,h
);
1129 // Put it in the context
1130 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1131 cairo_append_path(m_context
, cp
);
1133 // clip to that path
1134 cairo_clip(m_context
);
1135 path
.UnGetNativePath(cp
);
1138 void wxCairoContext::ResetClip()
1140 cairo_reset_clip(m_context
);
1144 void wxCairoContext::StrokePath( const wxGraphicsPath
& path
)
1146 if ( !m_pen
.IsNull() )
1148 wxCairoOffsetHelper
helper( m_context
, ShouldOffset() ) ;
1149 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1150 cairo_append_path(m_context
,cp
);
1151 ((wxCairoPenData
*)m_pen
.GetRefData())->Apply(this);
1152 cairo_stroke(m_context
);
1153 path
.UnGetNativePath(cp
);
1157 void wxCairoContext::FillPath( const wxGraphicsPath
& path
, int fillStyle
)
1159 if ( !m_brush
.IsNull() )
1161 wxCairoOffsetHelper
helper( m_context
, ShouldOffset() ) ;
1162 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1163 cairo_append_path(m_context
,cp
);
1164 ((wxCairoBrushData
*)m_brush
.GetRefData())->Apply(this);
1165 cairo_set_fill_rule(m_context
,fillStyle
==wxODDEVEN_RULE
? CAIRO_FILL_RULE_EVEN_ODD
: CAIRO_FILL_RULE_WINDING
);
1166 cairo_fill(m_context
);
1167 path
.UnGetNativePath(cp
);
1171 void wxCairoContext::Rotate( wxDouble angle
)
1173 cairo_rotate(m_context
,angle
);
1176 void wxCairoContext::Translate( wxDouble dx
, wxDouble dy
)
1178 cairo_translate(m_context
,dx
,dy
);
1181 void wxCairoContext::Scale( wxDouble xScale
, wxDouble yScale
)
1183 cairo_scale(m_context
,xScale
,yScale
);
1186 // concatenates this transform with the current transform of this context
1187 void wxCairoContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1189 cairo_transform(m_context
,(const cairo_matrix_t
*) matrix
.GetNativeMatrix());
1192 // sets the transform of this context
1193 void wxCairoContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1195 cairo_set_matrix(m_context
,(const cairo_matrix_t
*) matrix
.GetNativeMatrix());
1198 // gets the matrix of this context
1199 wxGraphicsMatrix
wxCairoContext::GetTransform() const
1201 wxGraphicsMatrix matrix
= CreateMatrix();
1202 cairo_get_matrix(m_context
,(cairo_matrix_t
*) matrix
.GetNativeMatrix());
1208 void wxCairoContext::PushState()
1210 cairo_save(m_context
);
1213 void wxCairoContext::PopState()
1215 cairo_restore(m_context
);
1218 void wxCairoContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1220 wxCHECK_RET( bmp
.IsOk(), wxT("Invalid bitmap in wxCairoContext::DrawBitmap"));
1222 cairo_surface_t
* surface
;
1223 int bw
= bmp
.GetWidth();
1224 int bh
= bmp
.GetHeight();
1225 wxBitmap bmpSource
= bmp
; // we need a non-const instance
1226 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1227 wxUint32
* data
= (wxUint32
*)buffer
;
1229 // Create a surface object and copy the bitmap pixel data to it. if the
1230 // image has alpha (or a mask represented as alpha) then we'll use a
1231 // different format and iterator than if it doesn't...
1232 if (bmpSource
.HasAlpha() || bmpSource
.GetMask())
1234 surface
= cairo_image_surface_create_for_data(
1235 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1236 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1237 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1239 wxAlphaPixelData::Iterator
p(pixData
);
1240 for (int y
=0; y
<bh
; y
++)
1242 wxAlphaPixelData::Iterator rowStart
= p
;
1243 for (int x
=0; x
<bw
; x
++)
1245 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1246 // with alpha in the upper 8 bits, then red, then green, then
1247 // blue. The 32-bit quantities are stored native-endian.
1248 // Pre-multiplied alpha is used.
1249 unsigned char alpha
= p
.Alpha();
1253 *data
= ( alpha
<< 24
1254 | (p
.Red() * alpha
/255) << 16
1255 | (p
.Green() * alpha
/255) << 8
1256 | (p
.Blue() * alpha
/255) );
1261 p
.OffsetY(pixData
, 1);
1266 surface
= cairo_image_surface_create_for_data(
1267 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1268 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1269 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1271 wxNativePixelData::Iterator
p(pixData
);
1272 for (int y
=0; y
<bh
; y
++)
1274 wxNativePixelData::Iterator rowStart
= p
;
1275 for (int x
=0; x
<bw
; x
++)
1277 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1278 // the upper 8 bits unused. Red, Green, and Blue are stored in
1279 // the remaining 24 bits in that order. The 32-bit quantities
1280 // are stored native-endian.
1281 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1286 p
.OffsetY(pixData
, 1);
1293 // In case we're scaling the image by using a width and height different
1294 // than the bitmap's size create a pattern transformation on the surface and
1295 // draw the transformed pattern.
1296 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1297 wxDouble scaleX
= w
/ bw
;
1298 wxDouble scaleY
= h
/ bh
;
1299 cairo_scale(m_context
, scaleX
, scaleY
);
1301 // prepare to draw the image
1302 cairo_translate(m_context
, x
, y
);
1303 cairo_set_source(m_context
, pattern
);
1304 // use the original size here since the context is scaled already...
1305 cairo_rectangle(m_context
, 0, 0, bw
, bh
);
1306 // fill the rectangle using the pattern
1307 cairo_fill(m_context
);
1310 cairo_pattern_destroy(pattern
);
1311 cairo_surface_destroy(surface
);
1316 void wxCairoContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1318 // An icon is a bitmap on wxGTK, so do this the easy way. When we want to
1319 // start using the Cairo backend on other platforms then we may need to
1320 // fiddle with this...
1321 DrawBitmap(icon
, x
, y
, w
, h
);
1325 void wxCairoContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1327 if ( m_font
.IsNull() || str
.empty())
1331 const wxCharBuffer data
= str
.utf8_str();
1334 size_t datalen
= strlen(data
);
1335 ((wxCairoFontData
*)m_font
.GetRefData())->Apply(this);
1337 PangoLayout
*layout
= pango_cairo_create_layout (m_context
);
1338 pango_layout_set_font_description( layout
, ((wxCairoFontData
*)m_font
.GetRefData())->GetFont());
1339 pango_layout_set_text(layout
, data
, datalen
);
1340 cairo_move_to(m_context
, x
, y
);
1341 pango_cairo_show_layout (m_context
, layout
);
1343 g_object_unref (layout
);
1345 ((wxCairoFontData
*)m_font
.GetRefData())->Apply(this);
1346 // Cairo's x,y for drawing text is at the baseline, so we need to adjust
1347 // the position we move to by the ascent.
1348 cairo_font_extents_t fe
;
1349 cairo_font_extents(m_context
, &fe
);
1350 cairo_move_to(m_context
, x
, y
+fe
.ascent
);
1352 const wxWX2MBbuf
buf(str
.mb_str(wxConvUTF8
));
1353 cairo_show_text(m_context
,buf
);
1357 void wxCairoContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1358 wxDouble
*descent
, wxDouble
*externalLeading
) const
1366 if ( externalLeading
)
1367 *externalLeading
= 0;
1369 if ( m_font
.IsNull() || str
.empty())
1375 PangoLayout
*layout
= pango_cairo_create_layout (m_context
);
1376 pango_layout_set_font_description( layout
, ((wxCairoFontData
*)m_font
.GetRefData())->GetFont());
1377 const wxCharBuffer data
= str
.utf8_str();
1382 pango_layout_set_text( layout
, data
, strlen(data
) );
1383 pango_layout_get_pixel_size (layout
, &w
, &h
);
1390 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
1391 int baseline
= pango_layout_iter_get_baseline(iter
);
1392 pango_layout_iter_free(iter
);
1393 *descent
= h
- PANGO_PIXELS(baseline
);
1395 g_object_unref (layout
);
1397 ((wxCairoFontData
*)m_font
.GetRefData())->Apply((wxCairoContext
*)this);
1401 const wxWX2MBbuf
buf(str
.mb_str(wxConvUTF8
));
1402 cairo_text_extents_t te
;
1403 cairo_text_extents(m_context
, buf
, &te
);
1407 if (height
|| descent
|| externalLeading
)
1409 cairo_font_extents_t fe
;
1410 cairo_font_extents(m_context
, &fe
);
1412 // some backends have negative descents
1414 if ( fe
.descent
< 0 )
1415 fe
.descent
= -fe
.descent
;
1417 if ( fe
.height
< (fe
.ascent
+ fe
.descent
) )
1419 // some backends are broken re height ... (eg currently ATSUI)
1420 fe
.height
= fe
.ascent
+ fe
.descent
;
1424 *height
= fe
.height
;
1426 *descent
= fe
.descent
;
1427 if ( externalLeading
)
1428 *externalLeading
= wxMax(0, fe
.height
- (fe
.ascent
+ fe
.descent
));
1433 void wxCairoContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1436 widths
.Add(0, text
.length());
1444 void * wxCairoContext::GetNativeContext()
1449 //-----------------------------------------------------------------------------
1450 // wxCairoRenderer declaration
1451 //-----------------------------------------------------------------------------
1453 class WXDLLIMPEXP_CORE wxCairoRenderer
: public wxGraphicsRenderer
1456 wxCairoRenderer() {}
1458 virtual ~wxCairoRenderer() {}
1462 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
1465 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
);
1468 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
1470 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
1472 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
1474 virtual wxGraphicsContext
* CreateMeasuringContext();
1478 virtual wxGraphicsPath
CreatePath();
1482 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
1483 wxDouble tx
=0.0, wxDouble ty
=0.0);
1486 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
1488 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
1490 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1491 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
1492 const wxColour
&c1
, const wxColour
&c2
) ;
1494 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1495 // with radius r and color cColor
1496 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
1497 const wxColour
&oColor
, const wxColour
&cColor
) ;
1500 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
1503 DECLARE_DYNAMIC_CLASS_NO_COPY(wxCairoRenderer
)
1506 //-----------------------------------------------------------------------------
1507 // wxCairoRenderer implementation
1508 //-----------------------------------------------------------------------------
1510 IMPLEMENT_DYNAMIC_CLASS(wxCairoRenderer
,wxGraphicsRenderer
)
1512 static wxCairoRenderer gs_cairoGraphicsRenderer
;
1513 // temporary hack to allow creating a cairo context on any platform
1514 extern wxGraphicsRenderer
* gCairoRenderer
;
1515 wxGraphicsRenderer
* gCairoRenderer
= &gs_cairoGraphicsRenderer
;
1518 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
1520 return &gs_cairoGraphicsRenderer
;
1524 wxGraphicsContext
* wxCairoRenderer::CreateContext( const wxWindowDC
& dc
)
1526 return new wxCairoContext(this,dc
);
1530 wxGraphicsContext
* wxCairoRenderer::CreateContext( const wxMemoryDC
& dc
)
1536 wxGraphicsContext
* wxCairoRenderer::CreateContextFromNativeContext( void * context
)
1538 return new wxCairoContext(this,(cairo_t
*)context
);
1542 wxGraphicsContext
* wxCairoRenderer::CreateContextFromNativeWindow( void * window
)
1545 return new wxCairoContext(this,(GdkDrawable
*)window
);
1551 wxGraphicsContext
* wxCairoRenderer::CreateMeasuringContext()
1557 wxGraphicsContext
* wxCairoRenderer::CreateContext( wxWindow
* window
)
1559 return new wxCairoContext(this, window
);
1564 wxGraphicsPath
wxCairoRenderer::CreatePath()
1566 wxGraphicsPath path
;
1567 path
.SetRefData( new wxCairoPathData(this) );
1574 wxGraphicsMatrix
wxCairoRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
1575 wxDouble tx
, wxDouble ty
)
1579 wxCairoMatrixData
* data
= new wxCairoMatrixData( this );
1580 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
1585 wxGraphicsPen
wxCairoRenderer::CreatePen(const wxPen
& pen
)
1587 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
1588 return wxNullGraphicsPen
;
1592 p
.SetRefData(new wxCairoPenData( this, pen
));
1597 wxGraphicsBrush
wxCairoRenderer::CreateBrush(const wxBrush
& brush
)
1599 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
1600 return wxNullGraphicsBrush
;
1604 p
.SetRefData(new wxCairoBrushData( this, brush
));
1609 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1610 wxGraphicsBrush
wxCairoRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
1611 const wxColour
&c1
, const wxColour
&c2
)
1614 wxCairoBrushData
* d
= new wxCairoBrushData( this );
1615 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
1620 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1621 // with radius r and color cColor
1622 wxGraphicsBrush
wxCairoRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
1623 const wxColour
&oColor
, const wxColour
&cColor
)
1626 wxCairoBrushData
* d
= new wxCairoBrushData( this );
1627 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
1633 wxGraphicsFont
wxCairoRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
1638 p
.SetRefData(new wxCairoFontData( this , font
, col
));
1642 return wxNullGraphicsFont
;
1645 #endif // wxUSE_GRAPHICS_CONTEXT