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/private/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"
102 #include "wx/gtk/dc.h"
106 #include <cairo-win32.h>
110 #include "wx/mac/private.h"
111 #include <cairo-quartz.h>
112 #include <cairo-atsui.h>
115 class WXDLLIMPEXP_CORE wxCairoPathData
: public wxGraphicsPathData
118 wxCairoPathData(wxGraphicsRenderer
* renderer
, cairo_t
* path
= NULL
);
121 virtual wxGraphicsObjectRefData
*Clone() const;
124 // These are the path primitives from which everything else can be constructed
127 // begins a new subpath at (x,y)
128 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
130 // adds a straight line from the current point to (x,y)
131 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
133 // adds a cubic Bezier curve from the current point, using two control points and an end point
134 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
137 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
138 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
) ;
140 // gets the last point of the current path, (0,0) if not yet set
141 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
144 virtual void AddPath( const wxGraphicsPathData
* path
);
146 // closes the current sub-path
147 virtual void CloseSubpath();
150 // These are convenience functions which - if not available natively will be assembled
151 // using the primitives from above
156 // appends a rectangle as a new closed subpath
157 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) ;
158 // appends an ellipsis as a new closed subpath fitting the passed rectangle
159 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
161 // 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)
162 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
165 // returns the native path
166 virtual void * GetNativePath() const ;
168 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
169 virtual void UnGetNativePath(void *p
) const;
171 // transforms each point of this path by the matrix
172 virtual void Transform( const wxGraphicsMatrixData
* matrix
) ;
174 // gets the bounding box enclosing all points (possibly including control points)
175 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const;
177 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxWINDING_RULE
) const;
180 cairo_t
* m_pathContext
;
183 class WXDLLIMPEXP_CORE wxCairoMatrixData
: public wxGraphicsMatrixData
186 wxCairoMatrixData(wxGraphicsRenderer
* renderer
, const cairo_matrix_t
* matrix
= NULL
) ;
187 virtual ~wxCairoMatrixData() ;
189 virtual wxGraphicsObjectRefData
*Clone() const ;
191 // concatenates the matrix
192 virtual void Concat( const wxGraphicsMatrixData
*t
);
194 // sets the matrix to the respective values
195 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
196 wxDouble tx
=0.0, wxDouble ty
=0.0);
198 // gets the component valuess of the matrix
199 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
200 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
202 // makes this the inverse matrix
203 virtual void Invert();
205 // returns true if the elements of the transformation matrix are equal ?
206 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
208 // return true if this is the identity matrix
209 virtual bool IsIdentity() const;
215 // add the translation to this matrix
216 virtual void Translate( wxDouble dx
, wxDouble dy
);
218 // add the scale to this matrix
219 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
221 // add the rotation to this matrix (radians)
222 virtual void Rotate( wxDouble angle
);
225 // apply the transforms
228 // applies that matrix to the point
229 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
231 // applies the matrix except for translations
232 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
234 // returns the native representation
235 virtual void * GetNativeMatrix() const;
237 cairo_matrix_t m_matrix
;
240 class WXDLLIMPEXP_CORE wxCairoPenData
: public wxGraphicsObjectRefData
243 wxCairoPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
248 virtual void Apply( wxGraphicsContext
* context
);
249 virtual wxDouble
GetWidth() { return m_width
; }
259 cairo_line_cap_t m_cap
;
260 cairo_line_join_t m_join
;
263 const double *m_lengths
;
264 double *m_userLengths
;
269 class WXDLLIMPEXP_CORE wxCairoBrushData
: public wxGraphicsObjectRefData
272 wxCairoBrushData( wxGraphicsRenderer
* renderer
);
273 wxCairoBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
274 ~wxCairoBrushData ();
276 virtual void Apply( wxGraphicsContext
* context
);
277 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
278 const wxColour
&c1
, const wxColour
&c2
);
279 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
280 const wxColour
&oColor
, const wxColour
&cColor
);
291 cairo_pattern_t
* m_brushPattern
;
294 class wxCairoFontData
: public wxGraphicsObjectRefData
297 wxCairoFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
300 virtual void Apply( wxGraphicsContext
* context
);
302 const PangoFontDescription
* GetFont() const { return m_font
; }
311 cairo_font_face_t
*m_font
;
312 #elif defined(__WXGTK__)
313 PangoFontDescription
* m_font
;
315 wxCharBuffer m_fontName
;
316 cairo_font_slant_t m_slant
;
317 cairo_font_weight_t m_weight
;
321 class WXDLLIMPEXP_CORE wxCairoContext
: public wxGraphicsContext
323 DECLARE_NO_COPY_CLASS(wxCairoContext
)
326 wxCairoContext( wxGraphicsRenderer
* renderer
, const wxWindowDC
& dc
);
327 wxCairoContext( wxGraphicsRenderer
* renderer
, const wxMemoryDC
& dc
);
329 wxCairoContext( wxGraphicsRenderer
* renderer
, GdkDrawable
*drawable
);
331 wxCairoContext( wxGraphicsRenderer
* renderer
, cairo_t
*context
);
332 wxCairoContext( wxGraphicsRenderer
* renderer
, wxWindow
*window
);
334 virtual ~wxCairoContext();
336 virtual bool ShouldOffset() const
339 if ( !m_pen
.IsNull() )
341 penwidth
= (int)((wxCairoPenData
*)m_pen
.GetRefData())->GetWidth();
345 return ( penwidth
% 2 ) == 1;
348 virtual void Clip( const wxRegion
®ion
);
350 // clips drawings to the rect
351 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
353 // resets the clipping to original extent
354 virtual void ResetClip();
356 virtual void * GetNativeContext();
358 virtual void StrokePath( const wxGraphicsPath
& p
);
359 virtual void FillPath( const wxGraphicsPath
& p
, int fillStyle
= wxWINDING_RULE
);
361 virtual void Translate( wxDouble dx
, wxDouble dy
);
362 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
363 virtual void Rotate( wxDouble angle
);
365 // concatenates this transform with the current transform of this context
366 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
368 // sets the transform of this context
369 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
371 // gets the matrix of this context
372 virtual wxGraphicsMatrix
GetTransform() const;
374 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
375 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
376 virtual void PushState();
377 virtual void PopState();
379 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
380 virtual void GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
381 wxDouble
*descent
, wxDouble
*externalLeading
) const;
382 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
385 void Init(cairo_t
*context
);
390 //-----------------------------------------------------------------------------
391 // wxCairoPenData implementation
392 //-----------------------------------------------------------------------------
394 wxCairoPenData::~wxCairoPenData()
396 delete[] m_userLengths
;
399 void wxCairoPenData::Init()
402 m_userLengths
= NULL
;
407 wxCairoPenData::wxCairoPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
)
408 : wxGraphicsObjectRefData(renderer
)
412 m_width
= m_pen
.GetWidth();
416 m_red
= m_pen
.GetColour().Red()/255.0;
417 m_green
= m_pen
.GetColour().Green()/255.0;
418 m_blue
= m_pen
.GetColour().Blue()/255.0;
419 m_alpha
= m_pen
.GetColour().Alpha()/255.0;
421 switch ( m_pen
.GetCap() )
424 m_cap
= CAIRO_LINE_CAP_ROUND
;
427 case wxCAP_PROJECTING
:
428 m_cap
= CAIRO_LINE_CAP_SQUARE
;
432 m_cap
= CAIRO_LINE_CAP_BUTT
;
436 m_cap
= CAIRO_LINE_CAP_BUTT
;
440 switch ( m_pen
.GetJoin() )
443 m_join
= CAIRO_LINE_JOIN_BEVEL
;
447 m_join
= CAIRO_LINE_JOIN_MITER
;
451 m_join
= CAIRO_LINE_JOIN_ROUND
;
455 m_join
= CAIRO_LINE_JOIN_MITER
;
459 const double dashUnit
= m_width
< 1.0 ? 1.0 : m_width
;
460 const double dotted
[] =
462 dashUnit
, dashUnit
+ 2.0
464 static const double short_dashed
[] =
468 static const double dashed
[] =
472 static const double dotted_dashed
[] =
474 9.0 , 6.0 , 3.0 , 3.0
477 switch ( m_pen
.GetStyle() )
483 m_count
= WXSIZEOF(dotted
);
484 m_userLengths
= new double[ m_count
] ;
485 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
486 m_lengths
= m_userLengths
;
491 m_count
= WXSIZEOF(dashed
);
495 m_lengths
= short_dashed
;
496 m_count
= WXSIZEOF(short_dashed
);
500 m_lengths
= dotted_dashed
;
501 m_count
= WXSIZEOF(dotted_dashed
);
507 m_count
= m_pen
.GetDashes( &wxdashes
) ;
508 if ((wxdashes
!= NULL
) && (m_count
> 0))
510 m_userLengths
= new double[m_count
] ;
511 for ( int i
= 0 ; i
< m_count
; ++i
)
513 m_userLengths
[i
] = wxdashes
[i
] * dashUnit
;
515 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
516 m_userLengths
[i
] = dashUnit
+ 2.0 ;
517 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
518 m_userLengths
[i
] = dashUnit
;
521 m_lengths
= m_userLengths
;
527 wxBitmap* bmp = pen.GetStipple();
528 if ( bmp && bmp->Ok() )
530 wxDELETE( m_penImage );
531 wxDELETE( m_penBrush );
532 m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
533 m_penBrush = new TextureBrush(m_penImage);
534 m_pen->SetBrush( m_penBrush );
540 if ( m_pen
.GetStyle() >= wxFIRST_HATCH
&& m_pen
.GetStyle() <= wxLAST_HATCH
)
543 wxDELETE( m_penBrush );
544 HatchStyle style = HatchStyleHorizontal;
545 switch( pen.GetStyle() )
547 case wxBDIAGONAL_HATCH :
548 style = HatchStyleBackwardDiagonal;
550 case wxCROSSDIAG_HATCH :
551 style = HatchStyleDiagonalCross;
553 case wxFDIAGONAL_HATCH :
554 style = HatchStyleForwardDiagonal;
557 style = HatchStyleCross;
559 case wxHORIZONTAL_HATCH :
560 style = HatchStyleHorizontal;
562 case wxVERTICAL_HATCH :
563 style = HatchStyleVertical;
567 m_penBrush = new HatchBrush(style,Color( pen.GetColour().Alpha() , pen.GetColour().Red() ,
568 pen.GetColour().Green() , pen.GetColour().Blue() ), Color.Transparent );
569 m_pen->SetBrush( m_penBrush )
576 void wxCairoPenData::Apply( wxGraphicsContext
* context
)
578 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
579 cairo_set_line_width(ctext
,m_width
);
580 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
581 cairo_set_line_cap(ctext
,m_cap
);
582 cairo_set_line_join(ctext
,m_join
);
583 cairo_set_dash(ctext
,(double*)m_lengths
,m_count
,0.0);
586 //-----------------------------------------------------------------------------
587 // wxCairoBrushData implementation
588 //-----------------------------------------------------------------------------
590 wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer
* renderer
)
591 : wxGraphicsObjectRefData( renderer
)
596 wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
)
597 : wxGraphicsObjectRefData(renderer
)
601 m_red
= brush
.GetColour().Red()/255.0;
602 m_green
= brush
.GetColour().Green()/255.0;
603 m_blue
= brush
.GetColour().Blue()/255.0;
604 m_alpha
= brush
.GetColour().Alpha()/255.0;
606 if ( brush.GetStyle() == wxSOLID)
608 m_brush = new SolidBrush( Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
609 brush.GetColour().Green() , brush.GetColour().Blue() ) );
611 else if ( brush.IsHatch() )
613 HatchStyle style = HatchStyleHorizontal;
614 switch( brush.GetStyle() )
616 case wxBDIAGONAL_HATCH :
617 style = HatchStyleBackwardDiagonal;
619 case wxCROSSDIAG_HATCH :
620 style = HatchStyleDiagonalCross;
622 case wxFDIAGONAL_HATCH :
623 style = HatchStyleForwardDiagonal;
626 style = HatchStyleCross;
628 case wxHORIZONTAL_HATCH :
629 style = HatchStyleHorizontal;
631 case wxVERTICAL_HATCH :
632 style = HatchStyleVertical;
636 m_brush = new HatchBrush(style,Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
637 brush.GetColour().Green() , brush.GetColour().Blue() ), Color.Transparent );
641 wxBitmap* bmp = brush.GetStipple();
642 if ( bmp && bmp->Ok() )
644 wxDELETE( m_brushImage );
645 m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
646 m_brush = new TextureBrush(m_brushImage);
652 wxCairoBrushData::~wxCairoBrushData ()
655 cairo_pattern_destroy(m_brushPattern
);
658 void wxCairoBrushData::Apply( wxGraphicsContext
* context
)
660 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
661 if ( m_brushPattern
)
663 cairo_set_source(ctext
,m_brushPattern
);
667 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
671 void wxCairoBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
672 const wxColour
&c1
, const wxColour
&c2
)
674 m_brushPattern
= cairo_pattern_create_linear(x1
,y1
,x2
,y2
);
675 cairo_pattern_add_color_stop_rgba(m_brushPattern
,0.0,c1
.Red()/255.0,
676 c1
.Green()/255.0, c1
.Blue()/255.0,c1
.Alpha()/255.0);
677 cairo_pattern_add_color_stop_rgba(m_brushPattern
,1.0,c2
.Red()/255.0,
678 c2
.Green()/255.0, c2
.Blue()/255.0,c2
.Alpha()/255.0);
679 wxASSERT_MSG(cairo_pattern_status(m_brushPattern
) == CAIRO_STATUS_SUCCESS
, wxT("Couldn't create cairo pattern"));
682 void wxCairoBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
683 const wxColour
&oColor
, const wxColour
&cColor
)
685 m_brushPattern
= cairo_pattern_create_radial(xo
,yo
,0.0,xc
,yc
,radius
);
686 cairo_pattern_add_color_stop_rgba(m_brushPattern
,0.0,oColor
.Red()/255.0,
687 oColor
.Green()/255.0, oColor
.Blue()/255.0,oColor
.Alpha()/255.0);
688 cairo_pattern_add_color_stop_rgba(m_brushPattern
,1.0,cColor
.Red()/255.0,
689 cColor
.Green()/255.0, cColor
.Blue()/255.0,cColor
.Alpha()/255.0);
690 wxASSERT_MSG(cairo_pattern_status(m_brushPattern
) == CAIRO_STATUS_SUCCESS
, wxT("Couldn't create cairo pattern"));
693 void wxCairoBrushData::Init()
695 m_brushPattern
= NULL
;
698 //-----------------------------------------------------------------------------
699 // wxCairoFontData implementation
700 //-----------------------------------------------------------------------------
702 wxCairoFontData::wxCairoFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
,
703 const wxColour
& col
) : wxGraphicsObjectRefData(renderer
)
705 m_red
= col
.Red()/255.0;
706 m_green
= col
.Green()/255.0;
707 m_blue
= col
.Blue()/255.0;
708 m_alpha
= col
.Alpha()/255.0;
709 m_size
= font
.GetPointSize();
712 m_font
= cairo_atsui_font_face_create_for_atsu_font_id( font
.MacGetATSUFontID() );
713 #elif defined(__WXGTK__)
714 m_font
= pango_font_description_copy( font
.GetNativeFontInfo()->description
);
716 m_fontName
= font
.GetFaceName().mb_str(wxConvUTF8
);
717 m_slant
= font
.GetStyle() == wxFONTSTYLE_ITALIC
? CAIRO_FONT_SLANT_ITALIC
:CAIRO_FONT_SLANT_NORMAL
;
718 m_weight
= font
.GetWeight() == wxFONTWEIGHT_BOLD
? CAIRO_FONT_WEIGHT_BOLD
:CAIRO_FONT_WEIGHT_NORMAL
;
722 wxCairoFontData::~wxCairoFontData()
725 cairo_font_face_destroy( m_font
);
726 #elif defined(__WXGTK__)
727 pango_font_description_free( m_font
);
732 void wxCairoFontData::Apply( wxGraphicsContext
* context
)
734 cairo_t
* ctext
= (cairo_t
*) context
->GetNativeContext();
735 cairo_set_source_rgba(ctext
,m_red
,m_green
, m_blue
,m_alpha
);
737 // the rest is done using Pango layouts
738 #elif defined(__WXMAC__)
739 cairo_set_font_face(ctext
, m_font
);
740 cairo_set_font_size(ctext
, m_size
);
742 cairo_select_font_face(ctext
, m_fontName
, m_slant
, m_weights
);
743 cairo_set_font_size(ctext
, m_size
);
747 //-----------------------------------------------------------------------------
748 // wxCairoPathData implementation
749 //-----------------------------------------------------------------------------
751 wxCairoPathData::wxCairoPathData( wxGraphicsRenderer
* renderer
, cairo_t
* pathcontext
)
752 : wxGraphicsPathData(renderer
)
756 m_pathContext
= pathcontext
;
760 cairo_surface_t
* surface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,1,1);
761 m_pathContext
= cairo_create(surface
);
762 cairo_surface_destroy (surface
);
766 wxCairoPathData::~wxCairoPathData()
768 cairo_destroy(m_pathContext
);
771 wxGraphicsObjectRefData
*wxCairoPathData::Clone() const
773 cairo_surface_t
* surface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,1,1);
774 cairo_t
* pathcontext
= cairo_create(surface
);
775 cairo_surface_destroy (surface
);
777 cairo_path_t
* path
= cairo_copy_path(m_pathContext
);
778 cairo_append_path(pathcontext
, path
);
779 cairo_path_destroy(path
);
780 return new wxCairoPathData( GetRenderer() ,pathcontext
);
784 void* wxCairoPathData::GetNativePath() const
786 return cairo_copy_path(m_pathContext
) ;
789 void wxCairoPathData::UnGetNativePath(void *p
) const
791 cairo_path_destroy((cairo_path_t
*)p
);
798 void wxCairoPathData::MoveToPoint( wxDouble x
, wxDouble y
)
800 cairo_move_to(m_pathContext
,x
,y
);
803 void wxCairoPathData::AddLineToPoint( wxDouble x
, wxDouble y
)
805 cairo_line_to(m_pathContext
,x
,y
);
808 void wxCairoPathData::AddPath( const wxGraphicsPathData
* path
)
810 cairo_path_t
* p
= (cairo_path_t
*)path
->GetNativePath();
811 cairo_append_path(m_pathContext
, p
);
815 void wxCairoPathData::CloseSubpath()
817 cairo_close_path(m_pathContext
);
820 void wxCairoPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
822 cairo_curve_to(m_pathContext
,cx1
,cy1
,cx2
,cy2
,x
,y
);
825 // gets the last point of the current path, (0,0) if not yet set
826 void wxCairoPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
829 cairo_get_current_point(m_pathContext
,&dx
,&dy
);
836 void wxCairoPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, double startAngle
, double endAngle
, bool clockwise
)
838 // as clockwise means positive in our system (y pointing downwards)
839 // TODO make this interpretation dependent of the
841 if ( clockwise
||(endAngle
-startAngle
)>=2*M_PI
)
842 cairo_arc(m_pathContext
,x
,y
,r
,startAngle
,endAngle
);
844 cairo_arc_negative(m_pathContext
,x
,y
,r
,startAngle
,endAngle
);
847 // transforms each point of this path by the matrix
848 void wxCairoPathData::Transform( const wxGraphicsMatrixData
* matrix
)
850 // as we don't have a true path object, we have to apply the inverse
851 // matrix to the context
852 cairo_matrix_t m
= *((cairo_matrix_t
*) matrix
->GetNativeMatrix());
853 cairo_matrix_invert( &m
);
854 cairo_transform(m_pathContext
,&m
);
857 // gets the bounding box enclosing all points (possibly including control points)
858 void wxCairoPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
862 cairo_stroke_extents( m_pathContext
, &x1
, &y1
, &x2
, &y2
);
886 bool wxCairoPathData::Contains( wxDouble x
, wxDouble y
, int WXUNUSED(fillStyle
) ) const
888 return cairo_in_stroke( m_pathContext
, x
, y
) != 0;
891 //-----------------------------------------------------------------------------
892 // wxCairoMatrixData implementation
893 //-----------------------------------------------------------------------------
895 wxCairoMatrixData::wxCairoMatrixData(wxGraphicsRenderer
* renderer
, const cairo_matrix_t
* matrix
)
896 : wxGraphicsMatrixData(renderer
)
902 wxCairoMatrixData::~wxCairoMatrixData()
907 wxGraphicsObjectRefData
*wxCairoMatrixData::Clone() const
909 return new wxCairoMatrixData(GetRenderer(),&m_matrix
);
912 // concatenates the matrix
913 void wxCairoMatrixData::Concat( const wxGraphicsMatrixData
*t
)
915 cairo_matrix_multiply( &m_matrix
, &m_matrix
, (cairo_matrix_t
*) t
->GetNativeMatrix());
918 // sets the matrix to the respective values
919 void wxCairoMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
920 wxDouble tx
, wxDouble ty
)
922 cairo_matrix_init( &m_matrix
, a
, b
, c
, d
, tx
, ty
);
925 // gets the component valuess of the matrix
926 void wxCairoMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
927 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
929 if (a
) *a
= m_matrix
.xx
;
930 if (b
) *b
= m_matrix
.yx
;
931 if (c
) *c
= m_matrix
.xy
;
932 if (d
) *d
= m_matrix
.yy
;
933 if (tx
) *tx
= m_matrix
.x0
;
934 if (ty
) *ty
= m_matrix
.y0
;
937 // makes this the inverse matrix
938 void wxCairoMatrixData::Invert()
940 cairo_matrix_invert( &m_matrix
);
943 // returns true if the elements of the transformation matrix are equal ?
944 bool wxCairoMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
946 const cairo_matrix_t
* tm
= (cairo_matrix_t
*) t
->GetNativeMatrix();
948 m_matrix
.xx
== tm
->xx
&&
949 m_matrix
.yx
== tm
->yx
&&
950 m_matrix
.xy
== tm
->xy
&&
951 m_matrix
.yy
== tm
->yy
&&
952 m_matrix
.x0
== tm
->x0
&&
953 m_matrix
.y0
== tm
->y0
) ;
956 // return true if this is the identity matrix
957 bool wxCairoMatrixData::IsIdentity() const
959 return ( m_matrix
.xx
== 1 && m_matrix
.yy
== 1 &&
960 m_matrix
.yx
== 0 && m_matrix
.xy
== 0 && m_matrix
.x0
== 0 && m_matrix
.y0
== 0);
967 // add the translation to this matrix
968 void wxCairoMatrixData::Translate( wxDouble dx
, wxDouble dy
)
970 cairo_matrix_translate( &m_matrix
, dx
, dy
) ;
973 // add the scale to this matrix
974 void wxCairoMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
976 cairo_matrix_scale( &m_matrix
, xScale
, yScale
) ;
979 // add the rotation to this matrix (radians)
980 void wxCairoMatrixData::Rotate( wxDouble angle
)
982 cairo_matrix_rotate( &m_matrix
, angle
) ;
986 // apply the transforms
989 // applies that matrix to the point
990 void wxCairoMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
992 double lx
= *x
, ly
= *y
;
993 cairo_matrix_transform_point( &m_matrix
, &lx
, &ly
);
998 // applies the matrix except for translations
999 void wxCairoMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
1001 double lx
= *dx
, ly
= *dy
;
1002 cairo_matrix_transform_distance( &m_matrix
, &lx
, &ly
);
1007 // returns the native representation
1008 void * wxCairoMatrixData::GetNativeMatrix() const
1010 return (void*) &m_matrix
;
1013 //-----------------------------------------------------------------------------
1014 // wxCairoContext implementation
1015 //-----------------------------------------------------------------------------
1017 class wxCairoOffsetHelper
1020 wxCairoOffsetHelper( cairo_t
* ctx
, bool offset
)
1025 cairo_translate( m_ctx
, 0.5, 0.5 );
1027 ~wxCairoOffsetHelper( )
1030 cairo_translate( m_ctx
, -0.5, -0.5 );
1037 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, const wxWindowDC
& dc
)
1038 : wxGraphicsContext(renderer
)
1041 wxGTKDCImpl
*impldc
= (wxGTKDCImpl
*) dc
.GetImpl();
1042 Init( gdk_cairo_create( impldc
->GetGDKWindow() ) );
1046 dc
.GetSize( &width
, &height
);
1047 CGContextRef cgcontext
= (CGContextRef
)dc
.GetWindow()->MacGetCGContextRef();
1048 cairo_surface_t
* surface
= cairo_quartz_surface_create_for_cg_context(cgcontext
, width
, height
);
1049 Init( cairo_create( surface
) );
1050 cairo_surface_destroy( surface
);
1054 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, const wxMemoryDC
& dc
)
1055 : wxGraphicsContext(renderer
)
1058 wxGTKDCImpl
*impldc
= (wxGTKDCImpl
*) dc
.GetImpl();
1059 Init( gdk_cairo_create( impldc
->GetGDKWindow() ) );
1063 dc
.GetSize( &width
, &height
);
1064 CGContextRef cgcontext
= (CGContextRef
)dc
.GetWindow()->MacGetCGContextRef();
1065 cairo_surface_t
* surface
= cairo_quartz_surface_create_for_cg_context(cgcontext
, width
, height
);
1066 Init( cairo_create( surface
) );
1067 cairo_surface_destroy( surface
);
1072 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, GdkDrawable
*drawable
)
1073 : wxGraphicsContext(renderer
)
1075 Init( gdk_cairo_create( drawable
) );
1079 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, cairo_t
*context
)
1080 : wxGraphicsContext(renderer
)
1085 wxCairoContext::wxCairoContext( wxGraphicsRenderer
* renderer
, wxWindow
*window
)
1086 : wxGraphicsContext(renderer
)
1089 // something along these lines (copied from dcclient)
1091 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
1092 // code should still be able to create wxClientDCs for them, so we will
1093 // use the parent window here then.
1094 if (window
->m_wxwindow
== NULL
)
1096 window
= window
->GetParent();
1099 wxASSERT_MSG( window
->m_wxwindow
, wxT("wxCairoContext needs a widget") );
1101 Init(gdk_cairo_create(window
->GTKGetDrawingWindow()));
1105 wxCairoContext::~wxCairoContext()
1111 cairo_destroy(m_context
);
1115 void wxCairoContext::Init(cairo_t
*context
)
1117 m_context
= context
;
1123 void wxCairoContext::Clip( const wxRegion
& region
)
1125 // Create a path with all the rectangles in the region
1126 wxGraphicsPath path
= GetRenderer()->CreatePath();
1127 wxRegionIterator
ri(region
);
1130 path
.AddRectangle(ri
.GetX(), ri
.GetY(), ri
.GetW(), ri
.GetH());
1134 // Put it in the context
1135 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1136 cairo_append_path(m_context
, cp
);
1138 // clip to that path
1139 cairo_clip(m_context
);
1140 path
.UnGetNativePath(cp
);
1143 void wxCairoContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1145 // Create a path with this rectangle
1146 wxGraphicsPath path
= GetRenderer()->CreatePath();
1147 path
.AddRectangle(x
,y
,w
,h
);
1149 // Put it in the context
1150 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1151 cairo_append_path(m_context
, cp
);
1153 // clip to that path
1154 cairo_clip(m_context
);
1155 path
.UnGetNativePath(cp
);
1158 void wxCairoContext::ResetClip()
1160 cairo_reset_clip(m_context
);
1164 void wxCairoContext::StrokePath( const wxGraphicsPath
& path
)
1166 if ( !m_pen
.IsNull() )
1168 wxCairoOffsetHelper
helper( m_context
, ShouldOffset() ) ;
1169 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1170 cairo_append_path(m_context
,cp
);
1171 ((wxCairoPenData
*)m_pen
.GetRefData())->Apply(this);
1172 cairo_stroke(m_context
);
1173 path
.UnGetNativePath(cp
);
1177 void wxCairoContext::FillPath( const wxGraphicsPath
& path
, int fillStyle
)
1179 if ( !m_brush
.IsNull() )
1181 wxCairoOffsetHelper
helper( m_context
, ShouldOffset() ) ;
1182 cairo_path_t
* cp
= (cairo_path_t
*) path
.GetNativePath() ;
1183 cairo_append_path(m_context
,cp
);
1184 ((wxCairoBrushData
*)m_brush
.GetRefData())->Apply(this);
1185 cairo_set_fill_rule(m_context
,fillStyle
==wxODDEVEN_RULE
? CAIRO_FILL_RULE_EVEN_ODD
: CAIRO_FILL_RULE_WINDING
);
1186 cairo_fill(m_context
);
1187 path
.UnGetNativePath(cp
);
1191 void wxCairoContext::Rotate( wxDouble angle
)
1193 cairo_rotate(m_context
,angle
);
1196 void wxCairoContext::Translate( wxDouble dx
, wxDouble dy
)
1198 cairo_translate(m_context
,dx
,dy
);
1201 void wxCairoContext::Scale( wxDouble xScale
, wxDouble yScale
)
1203 cairo_scale(m_context
,xScale
,yScale
);
1206 // concatenates this transform with the current transform of this context
1207 void wxCairoContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1209 cairo_transform(m_context
,(const cairo_matrix_t
*) matrix
.GetNativeMatrix());
1212 // sets the transform of this context
1213 void wxCairoContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1215 cairo_set_matrix(m_context
,(const cairo_matrix_t
*) matrix
.GetNativeMatrix());
1218 // gets the matrix of this context
1219 wxGraphicsMatrix
wxCairoContext::GetTransform() const
1221 wxGraphicsMatrix matrix
= CreateMatrix();
1222 cairo_get_matrix(m_context
,(cairo_matrix_t
*) matrix
.GetNativeMatrix());
1228 void wxCairoContext::PushState()
1230 cairo_save(m_context
);
1233 void wxCairoContext::PopState()
1235 cairo_restore(m_context
);
1238 void wxCairoContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1240 wxCHECK_RET( bmp
.IsOk(), wxT("Invalid bitmap in wxCairoContext::DrawBitmap"));
1242 cairo_surface_t
* surface
;
1243 int bw
= bmp
.GetWidth();
1244 int bh
= bmp
.GetHeight();
1245 wxBitmap bmpSource
= bmp
; // we need a non-const instance
1246 unsigned char* buffer
= new unsigned char[bw
*bh
*4];
1247 wxUint32
* data
= (wxUint32
*)buffer
;
1249 // Create a surface object and copy the bitmap pixel data to it. if the
1250 // image has alpha (or a mask represented as alpha) then we'll use a
1251 // different format and iterator than if it doesn't...
1252 if (bmpSource
.HasAlpha() || bmpSource
.GetMask())
1254 surface
= cairo_image_surface_create_for_data(
1255 buffer
, CAIRO_FORMAT_ARGB32
, bw
, bh
, bw
*4);
1256 wxAlphaPixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1257 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1259 wxAlphaPixelData::Iterator
p(pixData
);
1260 for (int y
=0; y
<bh
; y
++)
1262 wxAlphaPixelData::Iterator rowStart
= p
;
1263 for (int x
=0; x
<bw
; x
++)
1265 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1266 // with alpha in the upper 8 bits, then red, then green, then
1267 // blue. The 32-bit quantities are stored native-endian.
1268 // Pre-multiplied alpha is used.
1269 unsigned char alpha
= p
.Alpha();
1273 *data
= ( alpha
<< 24
1274 | (p
.Red() * alpha
/255) << 16
1275 | (p
.Green() * alpha
/255) << 8
1276 | (p
.Blue() * alpha
/255) );
1281 p
.OffsetY(pixData
, 1);
1286 surface
= cairo_image_surface_create_for_data(
1287 buffer
, CAIRO_FORMAT_RGB24
, bw
, bh
, bw
*4);
1288 wxNativePixelData
pixData(bmpSource
, wxPoint(0,0), wxSize(bw
, bh
));
1289 wxCHECK_RET( pixData
, wxT("Failed to gain raw access to bitmap data."));
1291 wxNativePixelData::Iterator
p(pixData
);
1292 for (int y
=0; y
<bh
; y
++)
1294 wxNativePixelData::Iterator rowStart
= p
;
1295 for (int x
=0; x
<bw
; x
++)
1297 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1298 // the upper 8 bits unused. Red, Green, and Blue are stored in
1299 // the remaining 24 bits in that order. The 32-bit quantities
1300 // are stored native-endian.
1301 *data
= ( p
.Red() << 16 | p
.Green() << 8 | p
.Blue() );
1306 p
.OffsetY(pixData
, 1);
1313 // In case we're scaling the image by using a width and height different
1314 // than the bitmap's size create a pattern transformation on the surface and
1315 // draw the transformed pattern.
1316 cairo_pattern_t
* pattern
= cairo_pattern_create_for_surface(surface
);
1317 wxDouble scaleX
= w
/ bw
;
1318 wxDouble scaleY
= h
/ bh
;
1319 cairo_scale(m_context
, scaleX
, scaleY
);
1321 // prepare to draw the image
1322 cairo_translate(m_context
, x
, y
);
1323 cairo_set_source(m_context
, pattern
);
1324 // use the original size here since the context is scaled already...
1325 cairo_rectangle(m_context
, 0, 0, bw
, bh
);
1326 // fill the rectangle using the pattern
1327 cairo_fill(m_context
);
1330 cairo_pattern_destroy(pattern
);
1331 cairo_surface_destroy(surface
);
1336 void wxCairoContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1338 // An icon is a bitmap on wxGTK, so do this the easy way. When we want to
1339 // start using the Cairo backend on other platforms then we may need to
1340 // fiddle with this...
1341 DrawBitmap(icon
, x
, y
, w
, h
);
1345 void wxCairoContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1347 if ( m_font
.IsNull() || str
.empty())
1351 const wxCharBuffer data
= str
.utf8_str();
1354 size_t datalen
= strlen(data
);
1355 ((wxCairoFontData
*)m_font
.GetRefData())->Apply(this);
1357 PangoLayout
*layout
= pango_cairo_create_layout (m_context
);
1358 pango_layout_set_font_description( layout
, ((wxCairoFontData
*)m_font
.GetRefData())->GetFont());
1359 pango_layout_set_text(layout
, data
, datalen
);
1360 cairo_move_to(m_context
, x
, y
);
1361 pango_cairo_show_layout (m_context
, layout
);
1363 g_object_unref (layout
);
1365 ((wxCairoFontData
*)m_font
.GetRefData())->Apply(this);
1366 // Cairo's x,y for drawing text is at the baseline, so we need to adjust
1367 // the position we move to by the ascent.
1368 cairo_font_extents_t fe
;
1369 cairo_font_extents(m_context
, &fe
);
1370 cairo_move_to(m_context
, x
, y
+fe
.ascent
);
1372 const wxWX2MBbuf
buf(str
.mb_str(wxConvUTF8
));
1373 cairo_show_text(m_context
,buf
);
1377 void wxCairoContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1378 wxDouble
*descent
, wxDouble
*externalLeading
) const
1386 if ( externalLeading
)
1387 *externalLeading
= 0;
1389 if ( m_font
.IsNull() || str
.empty())
1395 PangoLayout
*layout
= pango_cairo_create_layout (m_context
);
1396 pango_layout_set_font_description( layout
, ((wxCairoFontData
*)m_font
.GetRefData())->GetFont());
1397 const wxCharBuffer data
= str
.utf8_str();
1402 pango_layout_set_text( layout
, data
, strlen(data
) );
1403 pango_layout_get_pixel_size (layout
, &w
, &h
);
1410 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
1411 int baseline
= pango_layout_iter_get_baseline(iter
);
1412 pango_layout_iter_free(iter
);
1413 *descent
= h
- PANGO_PIXELS(baseline
);
1415 g_object_unref (layout
);
1417 ((wxCairoFontData
*)m_font
.GetRefData())->Apply((wxCairoContext
*)this);
1421 const wxWX2MBbuf
buf(str
.mb_str(wxConvUTF8
));
1422 cairo_text_extents_t te
;
1423 cairo_text_extents(m_context
, buf
, &te
);
1427 if (height
|| descent
|| externalLeading
)
1429 cairo_font_extents_t fe
;
1430 cairo_font_extents(m_context
, &fe
);
1432 // some backends have negative descents
1434 if ( fe
.descent
< 0 )
1435 fe
.descent
= -fe
.descent
;
1437 if ( fe
.height
< (fe
.ascent
+ fe
.descent
) )
1439 // some backends are broken re height ... (eg currently ATSUI)
1440 fe
.height
= fe
.ascent
+ fe
.descent
;
1444 *height
= fe
.height
;
1446 *descent
= fe
.descent
;
1447 if ( externalLeading
)
1448 *externalLeading
= wxMax(0, fe
.height
- (fe
.ascent
+ fe
.descent
));
1453 void wxCairoContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1456 widths
.Add(0, text
.length());
1464 void * wxCairoContext::GetNativeContext()
1469 //-----------------------------------------------------------------------------
1470 // wxCairoRenderer declaration
1471 //-----------------------------------------------------------------------------
1473 class WXDLLIMPEXP_CORE wxCairoRenderer
: public wxGraphicsRenderer
1476 wxCairoRenderer() {}
1478 virtual ~wxCairoRenderer() {}
1482 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
1483 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
);
1485 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
1487 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
1489 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
1491 virtual wxGraphicsContext
* CreateMeasuringContext();
1495 virtual wxGraphicsPath
CreatePath();
1499 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
1500 wxDouble tx
=0.0, wxDouble ty
=0.0);
1503 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
1505 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
1507 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1508 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
1509 const wxColour
&c1
, const wxColour
&c2
) ;
1511 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1512 // with radius r and color cColor
1513 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
1514 const wxColour
&oColor
, const wxColour
&cColor
) ;
1517 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
1520 DECLARE_DYNAMIC_CLASS_NO_COPY(wxCairoRenderer
)
1523 //-----------------------------------------------------------------------------
1524 // wxCairoRenderer implementation
1525 //-----------------------------------------------------------------------------
1527 IMPLEMENT_DYNAMIC_CLASS(wxCairoRenderer
,wxGraphicsRenderer
)
1529 static wxCairoRenderer gs_cairoGraphicsRenderer
;
1530 // temporary hack to allow creating a cairo context on any platform
1531 extern wxGraphicsRenderer
* gCairoRenderer
;
1532 wxGraphicsRenderer
* gCairoRenderer
= &gs_cairoGraphicsRenderer
;
1535 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
1537 return &gs_cairoGraphicsRenderer
;
1541 wxGraphicsContext
* wxCairoRenderer::CreateContext( const wxWindowDC
& dc
)
1543 return new wxCairoContext(this,dc
);
1546 wxGraphicsContext
* wxCairoRenderer::CreateContext( const wxMemoryDC
& dc
)
1548 return new wxCairoContext(this,dc
);
1551 wxGraphicsContext
* wxCairoRenderer::CreateContextFromNativeContext( void * context
)
1553 return new wxCairoContext(this,(cairo_t
*)context
);
1557 wxGraphicsContext
* wxCairoRenderer::CreateContextFromNativeWindow( void * window
)
1560 return new wxCairoContext(this,(GdkDrawable
*)window
);
1566 wxGraphicsContext
* wxCairoRenderer::CreateMeasuringContext()
1572 wxGraphicsContext
* wxCairoRenderer::CreateContext( wxWindow
* window
)
1574 return new wxCairoContext(this, window
);
1579 wxGraphicsPath
wxCairoRenderer::CreatePath()
1581 wxGraphicsPath path
;
1582 path
.SetRefData( new wxCairoPathData(this) );
1589 wxGraphicsMatrix
wxCairoRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
1590 wxDouble tx
, wxDouble ty
)
1594 wxCairoMatrixData
* data
= new wxCairoMatrixData( this );
1595 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
1600 wxGraphicsPen
wxCairoRenderer::CreatePen(const wxPen
& pen
)
1602 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
1603 return wxNullGraphicsPen
;
1607 p
.SetRefData(new wxCairoPenData( this, pen
));
1612 wxGraphicsBrush
wxCairoRenderer::CreateBrush(const wxBrush
& brush
)
1614 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
1615 return wxNullGraphicsBrush
;
1619 p
.SetRefData(new wxCairoBrushData( this, brush
));
1624 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1625 wxGraphicsBrush
wxCairoRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
1626 const wxColour
&c1
, const wxColour
&c2
)
1629 wxCairoBrushData
* d
= new wxCairoBrushData( this );
1630 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
1635 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1636 // with radius r and color cColor
1637 wxGraphicsBrush
wxCairoRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
1638 const wxColour
&oColor
, const wxColour
&cColor
)
1641 wxCairoBrushData
* d
= new wxCairoBrushData( this );
1642 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
1648 wxGraphicsFont
wxCairoRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
1653 p
.SetRefData(new wxCairoFontData( this , font
, col
));
1657 return wxNullGraphicsFont
;
1660 #endif // wxUSE_GRAPHICS_CONTEXT