Use #ifdef to check for __WXMSW__ and __WXGTK__ and not #if.
[wxWidgets.git] / src / generic / graphicc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/graphicc.cpp
3 // Purpose: cairo device context class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 2006-10-03
7 // RCS-ID: $Id$
8 // Copyright: (c) 2006 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/cairo.h"
19 #include "wx/graphics.h"
20
21 #if wxUSE_GRAPHICS_CONTEXT && wxUSE_CAIRO
22
23 #ifndef WX_PRECOMP
24 #include "wx/bitmap.h"
25 #include "wx/icon.h"
26 #include "wx/dcclient.h"
27 #include "wx/dcmemory.h"
28 #include "wx/dcprint.h"
29 #endif
30
31 #include "wx/private/graphics.h"
32 #include "wx/rawbmp.h"
33 #include "wx/vector.h"
34
35 using namespace std;
36
37 //-----------------------------------------------------------------------------
38 // device context implementation
39 //
40 // more and more of the dc functionality should be implemented by calling
41 // the appropricate wxCairoContext, but we will have to do that step by step
42 // also coordinate conversions should be moved to native matrix ops
43 //-----------------------------------------------------------------------------
44
45 // we always stock two context states, one at entry, to be able to preserve the
46 // state we were called with, the other one after changing to HI Graphics orientation
47 // (this one is used for getting back clippings etc)
48
49 //-----------------------------------------------------------------------------
50 // wxGraphicsPath implementation
51 //-----------------------------------------------------------------------------
52
53 // TODO remove this dependency (gdiplus needs the macros)
54
55 #ifndef max
56 #define max(a,b) (((a) > (b)) ? (a) : (b))
57 #endif
58
59 #ifndef min
60 #define min(a,b) (((a) < (b)) ? (a) : (b))
61 #endif
62
63 #include <cairo.h>
64 #ifdef __WXMSW__
65 #include <cairo-win32.h>
66 #endif
67
68 #ifdef __WXGTK__
69 #include <gtk/gtk.h>
70 #include "wx/fontutil.h"
71 #include "wx/gtk/dc.h"
72 #endif
73
74 #ifdef __WXMSW__
75 #include <cairo-win32.h>
76 #endif
77
78 #ifdef __WXMAC__
79 #include "wx/osx/private.h"
80 #include <cairo-quartz.h>
81 #include <cairo-atsui.h>
82 #endif
83
84 class WXDLLIMPEXP_CORE wxCairoPathData : public wxGraphicsPathData
85 {
86 public :
87 wxCairoPathData(wxGraphicsRenderer* renderer, cairo_t* path = NULL);
88 ~wxCairoPathData();
89
90 virtual wxGraphicsObjectRefData *Clone() const;
91
92 //
93 // These are the path primitives from which everything else can be constructed
94 //
95
96 // begins a new subpath at (x,y)
97 virtual void MoveToPoint( wxDouble x, wxDouble y );
98
99 // adds a straight line from the current point to (x,y)
100 virtual void AddLineToPoint( wxDouble x, wxDouble y );
101
102 // adds a cubic Bezier curve from the current point, using two control points and an end point
103 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y );
104
105
106 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
107 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) ;
108
109 // gets the last point of the current path, (0,0) if not yet set
110 virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const;
111
112 // adds another path
113 virtual void AddPath( const wxGraphicsPathData* path );
114
115 // closes the current sub-path
116 virtual void CloseSubpath();
117
118 //
119 // These are convenience functions which - if not available natively will be assembled
120 // using the primitives from above
121 //
122
123 /*
124
125 // appends a rectangle as a new closed subpath
126 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) ;
127 // appends an ellipsis as a new closed subpath fitting the passed rectangle
128 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
129
130 // 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)
131 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
132 */
133
134 // returns the native path
135 virtual void * GetNativePath() const ;
136
137 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
138 virtual void UnGetNativePath(void *p) const;
139
140 // transforms each point of this path by the matrix
141 virtual void Transform( const wxGraphicsMatrixData* matrix ) ;
142
143 // gets the bounding box enclosing all points (possibly including control points)
144 virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const;
145
146 virtual bool Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle = wxWINDING_RULE) const;
147
148 private :
149 cairo_t* m_pathContext;
150 };
151
152 class WXDLLIMPEXP_CORE wxCairoMatrixData : public wxGraphicsMatrixData
153 {
154 public :
155 wxCairoMatrixData(wxGraphicsRenderer* renderer, const cairo_matrix_t* matrix = NULL ) ;
156 virtual ~wxCairoMatrixData() ;
157
158 virtual wxGraphicsObjectRefData *Clone() const ;
159
160 // concatenates the matrix
161 virtual void Concat( const wxGraphicsMatrixData *t );
162
163 // sets the matrix to the respective values
164 virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
165 wxDouble tx=0.0, wxDouble ty=0.0);
166
167 // gets the component valuess of the matrix
168 virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL,
169 wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const;
170
171 // makes this the inverse matrix
172 virtual void Invert();
173
174 // returns true if the elements of the transformation matrix are equal ?
175 virtual bool IsEqual( const wxGraphicsMatrixData* t) const ;
176
177 // return true if this is the identity matrix
178 virtual bool IsIdentity() const;
179
180 //
181 // transformation
182 //
183
184 // add the translation to this matrix
185 virtual void Translate( wxDouble dx , wxDouble dy );
186
187 // add the scale to this matrix
188 virtual void Scale( wxDouble xScale , wxDouble yScale );
189
190 // add the rotation to this matrix (radians)
191 virtual void Rotate( wxDouble angle );
192
193 //
194 // apply the transforms
195 //
196
197 // applies that matrix to the point
198 virtual void TransformPoint( wxDouble *x, wxDouble *y ) const;
199
200 // applies the matrix except for translations
201 virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const;
202
203 // returns the native representation
204 virtual void * GetNativeMatrix() const;
205 private:
206 cairo_matrix_t m_matrix ;
207 } ;
208
209 class WXDLLIMPEXP_CORE wxCairoPenData : public wxGraphicsObjectRefData
210 {
211 public:
212 wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen );
213 ~wxCairoPenData();
214
215 void Init();
216
217 virtual void Apply( wxGraphicsContext* context );
218 virtual wxDouble GetWidth() { return m_width; }
219
220 private :
221 double m_width;
222
223 double m_red;
224 double m_green;
225 double m_blue;
226 double m_alpha;
227
228 cairo_line_cap_t m_cap;
229 cairo_line_join_t m_join;
230
231 int m_count;
232 const double *m_lengths;
233 double *m_userLengths;
234
235 wxPen m_pen;
236
237 wxDECLARE_NO_COPY_CLASS(wxCairoPenData);
238 };
239
240 class WXDLLIMPEXP_CORE wxCairoBrushData : public wxGraphicsObjectRefData
241 {
242 public:
243 wxCairoBrushData( wxGraphicsRenderer* renderer );
244 wxCairoBrushData( wxGraphicsRenderer* renderer, const wxBrush &brush );
245 ~wxCairoBrushData ();
246
247 virtual void Apply( wxGraphicsContext* context );
248 void CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
249 const wxColour&c1, const wxColour&c2 );
250 void CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
251 const wxColour &oColor, const wxColour &cColor );
252
253 protected:
254 virtual void Init();
255
256 private :
257 double m_red;
258 double m_green;
259 double m_blue;
260 double m_alpha;
261
262 cairo_pattern_t* m_brushPattern;
263 };
264
265 class wxCairoFontData : public wxGraphicsObjectRefData
266 {
267 public:
268 wxCairoFontData( wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col );
269 ~wxCairoFontData();
270
271 virtual void Apply( wxGraphicsContext* context );
272 #ifdef __WXGTK__
273 const PangoFontDescription* GetFont() const { return m_font; }
274 bool GetUnderlined() const { return m_underlined; }
275 #endif
276 private :
277 double m_size;
278 bool m_underlined;
279 double m_red;
280 double m_green;
281 double m_blue;
282 double m_alpha;
283 #ifdef __WXMAC__
284 cairo_font_face_t *m_font;
285 #elif defined(__WXGTK__)
286 PangoFontDescription* m_font;
287 #else
288 wxCharBuffer m_fontName;
289 cairo_font_slant_t m_slant;
290 cairo_font_weight_t m_weight;
291 #endif
292 #ifdef __WXMSW__
293 wxCairoContext( wxGraphicsRenderer* renderer, HDC context );
294 #endif
295 };
296
297 class wxCairoBitmapData : public wxGraphicsObjectRefData
298 {
299 public:
300 wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp );
301 wxCairoBitmapData( wxGraphicsRenderer* renderer, cairo_surface_t* bitmap );
302 ~wxCairoBitmapData();
303
304 virtual cairo_surface_t* GetCairoSurface() { return m_surface; }
305 virtual cairo_pattern_t* GetCairoPattern() { return m_pattern; }
306 virtual wxSize GetSize() { return wxSize(m_width, m_height); }
307 private :
308 cairo_surface_t* m_surface;
309 cairo_pattern_t* m_pattern;
310 int m_width;
311 int m_height;
312 unsigned char* m_buffer;
313 };
314
315 class WXDLLIMPEXP_CORE wxCairoContext : public wxGraphicsContext
316 {
317 public:
318 wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& dc );
319 wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& dc );
320 wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC& dc );
321 #ifdef __WXGTK__
322 wxCairoContext( wxGraphicsRenderer* renderer, GdkDrawable *drawable );
323 #endif
324 wxCairoContext( wxGraphicsRenderer* renderer, cairo_t *context );
325 wxCairoContext( wxGraphicsRenderer* renderer, wxWindow *window);
326 wxCairoContext();
327 virtual ~wxCairoContext();
328
329 virtual bool ShouldOffset() const
330 {
331 int penwidth = 0 ;
332 if ( !m_pen.IsNull() )
333 {
334 penwidth = (int)((wxCairoPenData*)m_pen.GetRefData())->GetWidth();
335 if ( penwidth == 0 )
336 penwidth = 1;
337 }
338 return ( penwidth % 2 ) == 1;
339 }
340
341 virtual void Clip( const wxRegion &region );
342 #ifdef __WXMSW__
343 cairo_surface_t* m_mswSurface;
344 #endif
345
346 // clips drawings to the rect
347 virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
348
349 // resets the clipping to original extent
350 virtual void ResetClip();
351
352 virtual void * GetNativeContext();
353
354 virtual bool SetAntialiasMode(wxAntialiasMode antialias);
355
356 virtual bool SetCompositionMode(wxCompositionMode op);
357
358 virtual void BeginLayer(wxDouble opacity);
359
360 virtual void EndLayer();
361
362 virtual void StrokePath( const wxGraphicsPath& p );
363 virtual void FillPath( const wxGraphicsPath& p , wxPolygonFillMode fillStyle = wxWINDING_RULE );
364
365 virtual void Translate( wxDouble dx , wxDouble dy );
366 virtual void Scale( wxDouble xScale , wxDouble yScale );
367 virtual void Rotate( wxDouble angle );
368
369 // concatenates this transform with the current transform of this context
370 virtual void ConcatTransform( const wxGraphicsMatrix& matrix );
371
372 // sets the transform of this context
373 virtual void SetTransform( const wxGraphicsMatrix& matrix );
374
375 // gets the matrix of this context
376 virtual wxGraphicsMatrix GetTransform() const;
377
378 virtual void DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
379 virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
380 virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
381 virtual void PushState();
382 virtual void PopState();
383
384 virtual void GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height,
385 wxDouble *descent, wxDouble *externalLeading ) const;
386 virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const;
387
388 protected:
389 virtual void DoDrawText( const wxString &str, wxDouble x, wxDouble y );
390
391 private:
392 void Init(cairo_t *context);
393
394 cairo_t* m_context;
395
396 wxVector<float> m_layerOpacities;
397
398 wxDECLARE_NO_COPY_CLASS(wxCairoContext);
399 };
400
401 //-----------------------------------------------------------------------------
402 // wxCairoPenData implementation
403 //-----------------------------------------------------------------------------
404
405 wxCairoPenData::~wxCairoPenData()
406 {
407 delete[] m_userLengths;
408 }
409
410 void wxCairoPenData::Init()
411 {
412 m_lengths = NULL;
413 m_userLengths = NULL;
414 m_width = 0;
415 m_count = 0;
416 }
417
418 wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen )
419 : wxGraphicsObjectRefData(renderer)
420 {
421 Init();
422 m_pen = pen;
423 m_width = m_pen.GetWidth();
424 if (m_width <= 0.0)
425 m_width = 0.1;
426
427 m_red = m_pen.GetColour().Red()/255.0;
428 m_green = m_pen.GetColour().Green()/255.0;
429 m_blue = m_pen.GetColour().Blue()/255.0;
430 m_alpha = m_pen.GetColour().Alpha()/255.0;
431
432 switch ( m_pen.GetCap() )
433 {
434 case wxCAP_ROUND :
435 m_cap = CAIRO_LINE_CAP_ROUND;
436 break;
437
438 case wxCAP_PROJECTING :
439 m_cap = CAIRO_LINE_CAP_SQUARE;
440 break;
441
442 case wxCAP_BUTT :
443 m_cap = CAIRO_LINE_CAP_BUTT;
444 break;
445
446 default :
447 m_cap = CAIRO_LINE_CAP_BUTT;
448 break;
449 }
450
451 switch ( m_pen.GetJoin() )
452 {
453 case wxJOIN_BEVEL :
454 m_join = CAIRO_LINE_JOIN_BEVEL;
455 break;
456
457 case wxJOIN_MITER :
458 m_join = CAIRO_LINE_JOIN_MITER;
459 break;
460
461 case wxJOIN_ROUND :
462 m_join = CAIRO_LINE_JOIN_ROUND;
463 break;
464
465 default :
466 m_join = CAIRO_LINE_JOIN_MITER;
467 break;
468 }
469
470 const double dashUnit = m_width < 1.0 ? 1.0 : m_width;
471 const double dotted[] =
472 {
473 dashUnit , dashUnit + 2.0
474 };
475 static const double short_dashed[] =
476 {
477 9.0 , 6.0
478 };
479 static const double dashed[] =
480 {
481 19.0 , 9.0
482 };
483 static const double dotted_dashed[] =
484 {
485 9.0 , 6.0 , 3.0 , 3.0
486 };
487
488 switch ( m_pen.GetStyle() )
489 {
490 case wxPENSTYLE_SOLID :
491 break;
492
493 case wxPENSTYLE_DOT :
494 m_count = WXSIZEOF(dotted);
495 m_userLengths = new double[ m_count ] ;
496 memcpy( m_userLengths, dotted, sizeof(dotted) );
497 m_lengths = m_userLengths;
498 break;
499
500 case wxPENSTYLE_LONG_DASH :
501 m_lengths = dashed ;
502 m_count = WXSIZEOF(dashed);
503 break;
504
505 case wxPENSTYLE_SHORT_DASH :
506 m_lengths = short_dashed ;
507 m_count = WXSIZEOF(short_dashed);
508 break;
509
510 case wxPENSTYLE_DOT_DASH :
511 m_lengths = dotted_dashed ;
512 m_count = WXSIZEOF(dotted_dashed);
513 break;
514
515 case wxPENSTYLE_USER_DASH :
516 {
517 wxDash *wxdashes ;
518 m_count = m_pen.GetDashes( &wxdashes ) ;
519 if ((wxdashes != NULL) && (m_count > 0))
520 {
521 m_userLengths = new double[m_count] ;
522 for ( int i = 0 ; i < m_count ; ++i )
523 {
524 m_userLengths[i] = wxdashes[i] * dashUnit ;
525
526 if ( i % 2 == 1 && m_userLengths[i] < dashUnit + 2.0 )
527 m_userLengths[i] = dashUnit + 2.0 ;
528 else if ( i % 2 == 0 && m_userLengths[i] < dashUnit )
529 m_userLengths[i] = dashUnit ;
530 }
531 }
532 m_lengths = m_userLengths ;
533 }
534 break;
535 case wxPENSTYLE_STIPPLE :
536 {
537 /*
538 wxBitmap* bmp = pen.GetStipple();
539 if ( bmp && bmp->Ok() )
540 {
541 wxDELETE( m_penImage );
542 wxDELETE( m_penBrush );
543 m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
544 m_penBrush = new TextureBrush(m_penImage);
545 m_pen->SetBrush( m_penBrush );
546 }
547 */
548 }
549 break;
550 default :
551 if ( m_pen.GetStyle() >= wxPENSTYLE_FIRST_HATCH
552 && m_pen.GetStyle() <= wxPENSTYLE_LAST_HATCH )
553 {
554 /*
555 wxDELETE( m_penBrush );
556 HatchStyle style = HatchStyleHorizontal;
557 switch( pen.GetStyle() )
558 {
559 case wxPENSTYLE_BDIAGONAL_HATCH :
560 style = HatchStyleBackwardDiagonal;
561 break ;
562 case wxPENSTYLE_CROSSDIAG_HATCH :
563 style = HatchStyleDiagonalCross;
564 break ;
565 case wxPENSTYLE_FDIAGONAL_HATCH :
566 style = HatchStyleForwardDiagonal;
567 break ;
568 case wxPENSTYLE_CROSS_HATCH :
569 style = HatchStyleCross;
570 break ;
571 case wxPENSTYLE_HORIZONTAL_HATCH :
572 style = HatchStyleHorizontal;
573 break ;
574 case wxPENSTYLE_VERTICAL_HATCH :
575 style = HatchStyleVertical;
576 break ;
577
578 }
579 m_penBrush = new HatchBrush(style,Color( pen.GetColour().Alpha() , pen.GetColour().Red() ,
580 pen.GetColour().Green() , pen.GetColour().Blue() ), Color.Transparent );
581 m_pen->SetBrush( m_penBrush )
582 */
583 }
584 break;
585 }
586 }
587
588 void wxCairoPenData::Apply( wxGraphicsContext* context )
589 {
590 cairo_t * ctext = (cairo_t*) context->GetNativeContext();
591 cairo_set_line_width(ctext,m_width);
592 cairo_set_source_rgba(ctext,m_red,m_green, m_blue,m_alpha);
593 cairo_set_line_cap(ctext,m_cap);
594 cairo_set_line_join(ctext,m_join);
595 cairo_set_dash(ctext,(double*)m_lengths,m_count,0.0);
596 }
597
598 //-----------------------------------------------------------------------------
599 // wxCairoBrushData implementation
600 //-----------------------------------------------------------------------------
601
602 wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer* renderer )
603 : wxGraphicsObjectRefData( renderer )
604 {
605 Init();
606 }
607
608 wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer* renderer, const wxBrush &brush )
609 : wxGraphicsObjectRefData(renderer)
610 {
611 Init();
612
613 m_red = brush.GetColour().Red()/255.0;
614 m_green = brush.GetColour().Green()/255.0;
615 m_blue = brush.GetColour().Blue()/255.0;
616 m_alpha = brush.GetColour().Alpha()/255.0;
617 /*
618 if ( brush.GetStyle() == wxBRUSHSTYLE_SOLID)
619 {
620 m_brush = new SolidBrush( Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
621 brush.GetColour().Green() , brush.GetColour().Blue() ) );
622 }
623 else if ( brush.IsHatch() )
624 {
625 HatchStyle style = HatchStyleHorizontal;
626 switch( brush.GetStyle() )
627 {
628 case wxBRUSHSTYLE_BDIAGONAL_HATCH :
629 style = HatchStyleBackwardDiagonal;
630 break ;
631 case wxBRUSHSTYLE_CROSSDIAG_HATCH :
632 style = HatchStyleDiagonalCross;
633 break ;
634 case wxBRUSHSTYLE_FDIAGONAL_HATCH :
635 style = HatchStyleForwardDiagonal;
636 break ;
637 case wxBRUSHSTYLE_CROSS_HATCH :
638 style = HatchStyleCross;
639 break ;
640 case wxBRUSHSTYLE_HORIZONTAL_HATCH :
641 style = HatchStyleHorizontal;
642 break ;
643 case wxBRUSHSTYLE_VERTICAL_HATCH :
644 style = HatchStyleVertical;
645 break ;
646
647 }
648 m_brush = new HatchBrush(style,Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
649 brush.GetColour().Green() , brush.GetColour().Blue() ), Color.Transparent );
650 }
651 else
652 {
653 wxBitmap* bmp = brush.GetStipple();
654 if ( bmp && bmp->Ok() )
655 {
656 wxDELETE( m_brushImage );
657 m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
658 m_brush = new TextureBrush(m_brushImage);
659 }
660 }
661 */
662 }
663
664 wxCairoBrushData::~wxCairoBrushData ()
665 {
666 if (m_brushPattern)
667 cairo_pattern_destroy(m_brushPattern);
668 }
669
670 void wxCairoBrushData::Apply( wxGraphicsContext* context )
671 {
672 cairo_t * ctext = (cairo_t*) context->GetNativeContext();
673 if ( m_brushPattern )
674 {
675 cairo_set_source(ctext,m_brushPattern);
676 }
677 else
678 {
679 cairo_set_source_rgba(ctext,m_red,m_green, m_blue,m_alpha);
680 }
681 }
682
683 void wxCairoBrushData::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
684 const wxColour&c1, const wxColour&c2 )
685 {
686 m_brushPattern = cairo_pattern_create_linear(x1,y1,x2,y2);
687 cairo_pattern_add_color_stop_rgba(m_brushPattern,0.0,c1.Red()/255.0,
688 c1.Green()/255.0, c1.Blue()/255.0,c1.Alpha()/255.0);
689 cairo_pattern_add_color_stop_rgba(m_brushPattern,1.0,c2.Red()/255.0,
690 c2.Green()/255.0, c2.Blue()/255.0,c2.Alpha()/255.0);
691 wxASSERT_MSG(cairo_pattern_status(m_brushPattern) == CAIRO_STATUS_SUCCESS, wxT("Couldn't create cairo pattern"));
692 }
693
694 void wxCairoBrushData::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
695 const wxColour &oColor, const wxColour &cColor )
696 {
697 m_brushPattern = cairo_pattern_create_radial(xo,yo,0.0,xc,yc,radius);
698 cairo_pattern_add_color_stop_rgba(m_brushPattern,0.0,oColor.Red()/255.0,
699 oColor.Green()/255.0, oColor.Blue()/255.0,oColor.Alpha()/255.0);
700 cairo_pattern_add_color_stop_rgba(m_brushPattern,1.0,cColor.Red()/255.0,
701 cColor.Green()/255.0, cColor.Blue()/255.0,cColor.Alpha()/255.0);
702 wxASSERT_MSG(cairo_pattern_status(m_brushPattern) == CAIRO_STATUS_SUCCESS, wxT("Couldn't create cairo pattern"));
703 }
704
705 void wxCairoBrushData::Init()
706 {
707 m_brushPattern = NULL;
708 }
709
710 //-----------------------------------------------------------------------------
711 // wxCairoFontData implementation
712 //-----------------------------------------------------------------------------
713
714 wxCairoFontData::wxCairoFontData( wxGraphicsRenderer* renderer, const wxFont &font,
715 const wxColour& col ) : wxGraphicsObjectRefData(renderer)
716 {
717 m_red = col.Red()/255.0;
718 m_green = col.Green()/255.0;
719 m_blue = col.Blue()/255.0;
720 m_alpha = col.Alpha()/255.0;
721 m_size = font.GetPointSize();
722 m_underlined = font.GetUnderlined();
723
724 #ifdef __WXMAC__
725 m_font = cairo_quartz_font_face_create_for_cgfont( font.OSXGetCGFont() );
726 #elif defined(__WXGTK__)
727 m_font = pango_font_description_copy( font.GetNativeFontInfo()->description );
728 #else
729 m_fontName = font.GetFaceName().mb_str(wxConvUTF8);
730 m_slant = font.GetStyle() == wxFONTSTYLE_ITALIC ? CAIRO_FONT_SLANT_ITALIC:CAIRO_FONT_SLANT_NORMAL;
731 m_weight = font.GetWeight() == wxFONTWEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD:CAIRO_FONT_WEIGHT_NORMAL;
732 #endif
733 }
734
735 wxCairoFontData::~wxCairoFontData()
736 {
737 #ifdef __WXMAC__
738 cairo_font_face_destroy( m_font );
739 #elif defined(__WXGTK__)
740 pango_font_description_free( m_font );
741 #else
742 #endif
743 }
744
745 void wxCairoFontData::Apply( wxGraphicsContext* context )
746 {
747 cairo_t * ctext = (cairo_t*) context->GetNativeContext();
748 cairo_set_source_rgba(ctext,m_red,m_green, m_blue,m_alpha);
749 #ifdef __WXGTK__
750 // the rest is done using Pango layouts
751 #elif defined(__WXMAC__)
752 cairo_set_font_face(ctext, m_font);
753 cairo_set_font_size(ctext, m_size );
754 #else
755 cairo_select_font_face(ctext, m_fontName, m_slant, m_weights );
756 cairo_set_font_size(ctext, m_size );
757 #endif
758 }
759
760 //-----------------------------------------------------------------------------
761 // wxCairoPathData implementation
762 //-----------------------------------------------------------------------------
763
764 wxCairoPathData::wxCairoPathData( wxGraphicsRenderer* renderer, cairo_t* pathcontext)
765 : wxGraphicsPathData(renderer)
766 {
767 if (pathcontext)
768 {
769 m_pathContext = pathcontext;
770 }
771 else
772 {
773 cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,1,1);
774 m_pathContext = cairo_create(surface);
775 cairo_surface_destroy (surface);
776 }
777 }
778
779 wxCairoPathData::~wxCairoPathData()
780 {
781 cairo_destroy(m_pathContext);
782 }
783
784 wxGraphicsObjectRefData *wxCairoPathData::Clone() const
785 {
786 cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,1,1);
787 cairo_t* pathcontext = cairo_create(surface);
788 cairo_surface_destroy (surface);
789
790 cairo_path_t* path = cairo_copy_path(m_pathContext);
791 cairo_append_path(pathcontext, path);
792 cairo_path_destroy(path);
793 return new wxCairoPathData( GetRenderer() ,pathcontext);
794 }
795
796
797 void* wxCairoPathData::GetNativePath() const
798 {
799 return cairo_copy_path(m_pathContext) ;
800 }
801
802 void wxCairoPathData::UnGetNativePath(void *p) const
803 {
804 cairo_path_destroy((cairo_path_t*)p);
805 }
806
807 //
808 // The Primitives
809 //
810
811 void wxCairoPathData::MoveToPoint( wxDouble x , wxDouble y )
812 {
813 cairo_move_to(m_pathContext,x,y);
814 }
815
816 void wxCairoPathData::AddLineToPoint( wxDouble x , wxDouble y )
817 {
818 cairo_line_to(m_pathContext,x,y);
819 }
820
821 void wxCairoPathData::AddPath( const wxGraphicsPathData* path )
822 {
823 cairo_path_t* p = (cairo_path_t*)path->GetNativePath();
824 cairo_append_path(m_pathContext, p);
825 UnGetNativePath(p);
826 }
827
828 void wxCairoPathData::CloseSubpath()
829 {
830 cairo_close_path(m_pathContext);
831 }
832
833 void wxCairoPathData::AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y )
834 {
835 cairo_curve_to(m_pathContext,cx1,cy1,cx2,cy2,x,y);
836 }
837
838 // gets the last point of the current path, (0,0) if not yet set
839 void wxCairoPathData::GetCurrentPoint( wxDouble* x, wxDouble* y) const
840 {
841 double dx,dy;
842 cairo_get_current_point(m_pathContext,&dx,&dy);
843 if (x)
844 *x = dx;
845 if (y)
846 *y = dy;
847 }
848
849 void wxCairoPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double startAngle, double endAngle, bool clockwise )
850 {
851 // as clockwise means positive in our system (y pointing downwards)
852 // TODO make this interpretation dependent of the
853 // real device trans
854 if ( clockwise||(endAngle-startAngle)>=2*M_PI)
855 cairo_arc(m_pathContext,x,y,r,startAngle,endAngle);
856 else
857 cairo_arc_negative(m_pathContext,x,y,r,startAngle,endAngle);
858 }
859
860 // transforms each point of this path by the matrix
861 void wxCairoPathData::Transform( const wxGraphicsMatrixData* matrix )
862 {
863 // as we don't have a true path object, we have to apply the inverse
864 // matrix to the context
865 cairo_matrix_t m = *((cairo_matrix_t*) matrix->GetNativeMatrix());
866 cairo_matrix_invert( &m );
867 cairo_transform(m_pathContext,&m);
868 }
869
870 // gets the bounding box enclosing all points (possibly including control points)
871 void wxCairoPathData::GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const
872 {
873 double x1,y1,x2,y2;
874
875 cairo_stroke_extents( m_pathContext, &x1, &y1, &x2, &y2 );
876 if ( x2 < x1 )
877 {
878 *x = x2;
879 *w = x1-x2;
880 }
881 else
882 {
883 *x = x1;
884 *w = x2-x1;
885 }
886
887 if( y2 < y1 )
888 {
889 *y = y2;
890 *h = y1-y2;
891 }
892 else
893 {
894 *y = y1;
895 *h = y2-y1;
896 }
897 }
898
899 bool wxCairoPathData::Contains( wxDouble x, wxDouble y, wxPolygonFillMode WXUNUSED(fillStyle) ) const
900 {
901 return cairo_in_stroke( m_pathContext, x, y) != 0;
902 }
903
904 //-----------------------------------------------------------------------------
905 // wxCairoMatrixData implementation
906 //-----------------------------------------------------------------------------
907
908 wxCairoMatrixData::wxCairoMatrixData(wxGraphicsRenderer* renderer, const cairo_matrix_t* matrix )
909 : wxGraphicsMatrixData(renderer)
910 {
911 if ( matrix )
912 m_matrix = *matrix;
913 }
914
915 wxCairoMatrixData::~wxCairoMatrixData()
916 {
917 // nothing to do
918 }
919
920 wxGraphicsObjectRefData *wxCairoMatrixData::Clone() const
921 {
922 return new wxCairoMatrixData(GetRenderer(),&m_matrix);
923 }
924
925 // concatenates the matrix
926 void wxCairoMatrixData::Concat( const wxGraphicsMatrixData *t )
927 {
928 cairo_matrix_multiply( &m_matrix, &m_matrix, (cairo_matrix_t*) t->GetNativeMatrix());
929 }
930
931 // sets the matrix to the respective values
932 void wxCairoMatrixData::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d,
933 wxDouble tx, wxDouble ty)
934 {
935 cairo_matrix_init( &m_matrix, a, b, c, d, tx, ty);
936 }
937
938 // gets the component valuess of the matrix
939 void wxCairoMatrixData::Get(wxDouble* a, wxDouble* b, wxDouble* c,
940 wxDouble* d, wxDouble* tx, wxDouble* ty) const
941 {
942 if (a) *a = m_matrix.xx;
943 if (b) *b = m_matrix.yx;
944 if (c) *c = m_matrix.xy;
945 if (d) *d = m_matrix.yy;
946 if (tx) *tx= m_matrix.x0;
947 if (ty) *ty= m_matrix.y0;
948 }
949
950 // makes this the inverse matrix
951 void wxCairoMatrixData::Invert()
952 {
953 cairo_matrix_invert( &m_matrix );
954 }
955
956 // returns true if the elements of the transformation matrix are equal ?
957 bool wxCairoMatrixData::IsEqual( const wxGraphicsMatrixData* t) const
958 {
959 const cairo_matrix_t* tm = (cairo_matrix_t*) t->GetNativeMatrix();
960 return (
961 m_matrix.xx == tm->xx &&
962 m_matrix.yx == tm->yx &&
963 m_matrix.xy == tm->xy &&
964 m_matrix.yy == tm->yy &&
965 m_matrix.x0 == tm->x0 &&
966 m_matrix.y0 == tm->y0 ) ;
967 }
968
969 // return true if this is the identity matrix
970 bool wxCairoMatrixData::IsIdentity() const
971 {
972 return ( m_matrix.xx == 1 && m_matrix.yy == 1 &&
973 m_matrix.yx == 0 && m_matrix.xy == 0 && m_matrix.x0 == 0 && m_matrix.y0 == 0);
974 }
975
976 //
977 // transformation
978 //
979
980 // add the translation to this matrix
981 void wxCairoMatrixData::Translate( wxDouble dx , wxDouble dy )
982 {
983 cairo_matrix_translate( &m_matrix, dx, dy) ;
984 }
985
986 // add the scale to this matrix
987 void wxCairoMatrixData::Scale( wxDouble xScale , wxDouble yScale )
988 {
989 cairo_matrix_scale( &m_matrix, xScale, yScale) ;
990 }
991
992 // add the rotation to this matrix (radians)
993 void wxCairoMatrixData::Rotate( wxDouble angle )
994 {
995 cairo_matrix_rotate( &m_matrix, angle) ;
996 }
997
998 //
999 // apply the transforms
1000 //
1001
1002 // applies that matrix to the point
1003 void wxCairoMatrixData::TransformPoint( wxDouble *x, wxDouble *y ) const
1004 {
1005 double lx = *x, ly = *y ;
1006 cairo_matrix_transform_point( &m_matrix, &lx, &ly);
1007 *x = lx;
1008 *y = ly;
1009 }
1010
1011 // applies the matrix except for translations
1012 void wxCairoMatrixData::TransformDistance( wxDouble *dx, wxDouble *dy ) const
1013 {
1014 double lx = *dx, ly = *dy ;
1015 cairo_matrix_transform_distance( &m_matrix, &lx, &ly);
1016 *dx = lx;
1017 *dy = ly;
1018 }
1019
1020 // returns the native representation
1021 void * wxCairoMatrixData::GetNativeMatrix() const
1022 {
1023 return (void*) &m_matrix;
1024 }
1025
1026 // wxCairoBitmap implementation
1027 //-----------------------------------------------------------------------------
1028
1029 wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, cairo_surface_t* bitmap ) :
1030 wxGraphicsObjectRefData( renderer )
1031 {
1032 m_surface = bitmap;
1033 m_pattern = cairo_pattern_create_for_surface(m_surface);
1034 }
1035
1036 wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp ) : wxGraphicsObjectRefData( renderer )
1037 {
1038 wxCHECK_RET( bmp.IsOk(), wxT("Invalid bitmap in wxCairoContext::DrawBitmap"));
1039
1040 int bw = bmp.GetWidth();
1041 int bh = bmp.GetHeight();
1042 wxBitmap bmpSource = bmp; // we need a non-const instance
1043 m_buffer = new unsigned char[bw*bh*4];
1044 wxUint32* data = (wxUint32*)m_buffer;
1045
1046 // Create a surface object and copy the bitmap pixel data to it. if the
1047 // image has alpha (or a mask represented as alpha) then we'll use a
1048 // different format and iterator than if it doesn't...
1049 if (bmpSource.HasAlpha() || bmpSource.GetMask())
1050 {
1051 m_surface = cairo_image_surface_create_for_data(
1052 m_buffer, CAIRO_FORMAT_ARGB32, bw, bh, bw*4);
1053 wxAlphaPixelData pixData(bmpSource, wxPoint(0,0), wxSize(bw, bh));
1054 wxCHECK_RET( pixData, wxT("Failed to gain raw access to bitmap data."));
1055
1056 wxAlphaPixelData::Iterator p(pixData);
1057 for (int y=0; y<bh; y++)
1058 {
1059 wxAlphaPixelData::Iterator rowStart = p;
1060 for (int x=0; x<bw; x++)
1061 {
1062 // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
1063 // with alpha in the upper 8 bits, then red, then green, then
1064 // blue. The 32-bit quantities are stored native-endian.
1065 // Pre-multiplied alpha is used.
1066 unsigned char alpha = p.Alpha();
1067 if (alpha == 0)
1068 *data = 0;
1069 else
1070 *data = ( alpha << 24
1071 | (p.Red() * alpha/255) << 16
1072 | (p.Green() * alpha/255) << 8
1073 | (p.Blue() * alpha/255) );
1074 ++data;
1075 ++p;
1076 }
1077 p = rowStart;
1078 p.OffsetY(pixData, 1);
1079 }
1080 }
1081 else // no alpha
1082 {
1083 m_surface = cairo_image_surface_create_for_data(
1084 m_buffer, CAIRO_FORMAT_RGB24, bw, bh, bw*4);
1085 wxNativePixelData pixData(bmpSource, wxPoint(0,0), wxSize(bw, bh));
1086 wxCHECK_RET( pixData, wxT("Failed to gain raw access to bitmap data."));
1087
1088 wxNativePixelData::Iterator p(pixData);
1089 for (int y=0; y<bh; y++)
1090 {
1091 wxNativePixelData::Iterator rowStart = p;
1092 for (int x=0; x<bw; x++)
1093 {
1094 // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
1095 // the upper 8 bits unused. Red, Green, and Blue are stored in
1096 // the remaining 24 bits in that order. The 32-bit quantities
1097 // are stored native-endian.
1098 *data = ( p.Red() << 16 | p.Green() << 8 | p.Blue() );
1099 ++data;
1100 ++p;
1101 }
1102 p = rowStart;
1103 p.OffsetY(pixData, 1);
1104 }
1105 }
1106 m_pattern = cairo_pattern_create_for_surface(m_surface);
1107 }
1108
1109 wxCairoBitmapData::~wxCairoBitmapData()
1110 {
1111 if (m_pattern)
1112 cairo_pattern_destroy(m_pattern);
1113
1114 if (m_surface)
1115 cairo_surface_destroy(m_surface);
1116
1117 delete [] m_buffer;
1118 }
1119
1120
1121
1122 //-----------------------------------------------------------------------------
1123 // wxCairoContext implementation
1124 //-----------------------------------------------------------------------------
1125
1126 class wxCairoOffsetHelper
1127 {
1128 public :
1129 wxCairoOffsetHelper( cairo_t* ctx , bool offset )
1130 {
1131 m_ctx = ctx;
1132 m_offset = offset;
1133 if ( m_offset )
1134 cairo_translate( m_ctx, 0.5, 0.5 );
1135 }
1136 ~wxCairoOffsetHelper( )
1137 {
1138 if ( m_offset )
1139 cairo_translate( m_ctx, -0.5, -0.5 );
1140 }
1141 public :
1142 cairo_t* m_ctx;
1143 bool m_offset;
1144 } ;
1145
1146 wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC& dc )
1147 : wxGraphicsContext(renderer)
1148 {
1149 #ifdef __WXGTK20__
1150 const wxDCImpl *impl = dc.GetImpl();
1151 Init( (cairo_t*) impl->GetCairoContext() );
1152
1153 wxPoint org = dc.GetDeviceOrigin();
1154 cairo_translate( m_context, org.x, org.y );
1155
1156 double sx,sy;
1157 dc.GetUserScale( &sx, &sy );
1158 cairo_scale( m_context, sx, sy );
1159
1160 org = dc.GetLogicalOrigin();
1161 cairo_translate( m_context, -org.x, -org.y );
1162 #endif
1163 }
1164
1165 wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& dc )
1166 : wxGraphicsContext(renderer)
1167 {
1168 #ifdef __WXGTK20__
1169 wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl();
1170 Init( gdk_cairo_create( impldc->GetGDKWindow() ) );
1171
1172 #if 0
1173 wxGraphicsMatrix matrix = CreateMatrix();
1174
1175 wxPoint org = dc.GetDeviceOrigin();
1176 matrix.Translate( org.x, org.y );
1177
1178 org = dc.GetLogicalOrigin();
1179 matrix.Translate( -org.x, -org.y );
1180
1181 double sx,sy;
1182 dc.GetUserScale( &sx, &sy );
1183 matrix.Scale( sx, sy );
1184
1185 ConcatTransform( matrix );
1186 #endif
1187 #endif
1188
1189 #ifdef __WXMAC__
1190 int width, height;
1191 dc.GetSize( &width, &height );
1192 CGContextRef cgcontext = (CGContextRef)dc.GetWindow()->MacGetCGContextRef();
1193 cairo_surface_t* surface = cairo_quartz_surface_create_for_cg_context(cgcontext, width, height);
1194 Init( cairo_create( surface ) );
1195 cairo_surface_destroy( surface );
1196 #endif
1197 }
1198
1199 wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& dc )
1200 : wxGraphicsContext(renderer)
1201 {
1202 #ifdef __WXGTK20__
1203 wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl();
1204 Init( gdk_cairo_create( impldc->GetGDKWindow() ) );
1205
1206 #if 0
1207 wxGraphicsMatrix matrix = CreateMatrix();
1208
1209 wxPoint org = dc.GetDeviceOrigin();
1210 matrix.Translate( org.x, org.y );
1211
1212 org = dc.GetLogicalOrigin();
1213 matrix.Translate( -org.x, -org.y );
1214
1215 double sx,sy;
1216 dc.GetUserScale( &sx, &sy );
1217 matrix.Scale( sx, sy );
1218
1219 ConcatTransform( matrix );
1220 #endif
1221 #endif
1222
1223 #ifdef __WXMAC__
1224 int width, height;
1225 dc.GetSize( &width, &height );
1226 CGContextRef cgcontext = (CGContextRef)dc.GetWindow()->MacGetCGContextRef();
1227 cairo_surface_t* surface = cairo_quartz_surface_create_for_cg_context(cgcontext, width, height);
1228 Init( cairo_create( surface ) );
1229 cairo_surface_destroy( surface );
1230 #endif
1231 }
1232
1233 #ifdef __WXGTK20__
1234 wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, GdkDrawable *drawable )
1235 : wxGraphicsContext(renderer)
1236 {
1237 Init( gdk_cairo_create( drawable ) );
1238 }
1239 #endif
1240
1241 #ifdef __WXMSW__
1242 wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, HDC handle )
1243 : wxGraphicsContext(renderer)
1244 {
1245 m_mswSurface = cairo_win32_surface_create(handle);
1246 m_context = cairo_create(m_mswSurface);
1247 PushState();
1248 PushState();
1249 }
1250 #endif
1251
1252
1253 wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, cairo_t *context )
1254 : wxGraphicsContext(renderer)
1255 {
1256 Init( context );
1257 }
1258
1259 wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, wxWindow *window)
1260 : wxGraphicsContext(renderer)
1261 {
1262 #ifdef __WXGTK__
1263 // something along these lines (copied from dcclient)
1264
1265 // Some controls don't have m_wxwindow - like wxStaticBox, but the user
1266 // code should still be able to create wxClientDCs for them, so we will
1267 // use the parent window here then.
1268 if (window->m_wxwindow == NULL)
1269 {
1270 window = window->GetParent();
1271 }
1272
1273 wxASSERT_MSG( window->m_wxwindow, wxT("wxCairoContext needs a widget") );
1274
1275 Init(gdk_cairo_create(window->GTKGetDrawingWindow()));
1276 #endif
1277 }
1278
1279 wxCairoContext::~wxCairoContext()
1280 {
1281 if ( m_context )
1282 {
1283 PopState();
1284 #ifdef __WXMSW__
1285 m_mswSurface = cairo_win32_surface_create((HDC)window->GetHandle());
1286 m_context = cairo_create(m_mswSurface);
1287 #endif
1288 PopState();
1289 cairo_destroy(m_context);
1290 }
1291 #ifdef __WXMSW__
1292 if ( m_mswSurface )
1293 cairo_surface_destroy(m_mswSurface);
1294 #endif
1295 }
1296
1297 void wxCairoContext::Init(cairo_t *context)
1298 {
1299 m_context = context ;
1300 PushState();
1301 PushState();
1302 }
1303
1304
1305 void wxCairoContext::Clip( const wxRegion& region )
1306 {
1307 // Create a path with all the rectangles in the region
1308 wxGraphicsPath path = GetRenderer()->CreatePath();
1309 wxRegionIterator ri(region);
1310 while (ri)
1311 {
1312 path.AddRectangle(ri.GetX(), ri.GetY(), ri.GetW(), ri.GetH());
1313 ++ri;
1314 }
1315
1316 // Put it in the context
1317 cairo_path_t* cp = (cairo_path_t*) path.GetNativePath() ;
1318 cairo_append_path(m_context, cp);
1319
1320 // clip to that path
1321 cairo_clip(m_context);
1322 path.UnGetNativePath(cp);
1323 }
1324
1325 void wxCairoContext::Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
1326 {
1327 // Create a path with this rectangle
1328 wxGraphicsPath path = GetRenderer()->CreatePath();
1329 path.AddRectangle(x,y,w,h);
1330
1331 // Put it in the context
1332 cairo_path_t* cp = (cairo_path_t*) path.GetNativePath() ;
1333 cairo_append_path(m_context, cp);
1334
1335 // clip to that path
1336 cairo_clip(m_context);
1337 path.UnGetNativePath(cp);
1338 }
1339
1340 void wxCairoContext::ResetClip()
1341 {
1342 cairo_reset_clip(m_context);
1343 }
1344
1345
1346 void wxCairoContext::StrokePath( const wxGraphicsPath& path )
1347 {
1348 if ( !m_pen.IsNull() )
1349 {
1350 wxCairoOffsetHelper helper( m_context, ShouldOffset() ) ;
1351 cairo_path_t* cp = (cairo_path_t*) path.GetNativePath() ;
1352 cairo_append_path(m_context,cp);
1353 ((wxCairoPenData*)m_pen.GetRefData())->Apply(this);
1354 cairo_stroke(m_context);
1355 path.UnGetNativePath(cp);
1356 }
1357 }
1358
1359 void wxCairoContext::FillPath( const wxGraphicsPath& path , wxPolygonFillMode fillStyle )
1360 {
1361 if ( !m_brush.IsNull() )
1362 {
1363 wxCairoOffsetHelper helper( m_context, ShouldOffset() ) ;
1364 cairo_path_t* cp = (cairo_path_t*) path.GetNativePath() ;
1365 cairo_append_path(m_context,cp);
1366 ((wxCairoBrushData*)m_brush.GetRefData())->Apply(this);
1367 cairo_set_fill_rule(m_context,fillStyle==wxODDEVEN_RULE ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
1368 cairo_fill(m_context);
1369 path.UnGetNativePath(cp);
1370 }
1371 }
1372
1373 void wxCairoContext::Rotate( wxDouble angle )
1374 {
1375 cairo_rotate(m_context,angle);
1376 }
1377
1378 void wxCairoContext::Translate( wxDouble dx , wxDouble dy )
1379 {
1380 cairo_translate(m_context,dx,dy);
1381 }
1382
1383 void wxCairoContext::Scale( wxDouble xScale , wxDouble yScale )
1384 {
1385 cairo_scale(m_context,xScale,yScale);
1386 }
1387
1388 // concatenates this transform with the current transform of this context
1389 void wxCairoContext::ConcatTransform( const wxGraphicsMatrix& matrix )
1390 {
1391 cairo_transform(m_context,(const cairo_matrix_t *) matrix.GetNativeMatrix());
1392 }
1393
1394 // sets the transform of this context
1395 void wxCairoContext::SetTransform( const wxGraphicsMatrix& matrix )
1396 {
1397 cairo_set_matrix(m_context,(const cairo_matrix_t*) matrix.GetNativeMatrix());
1398 }
1399
1400 // gets the matrix of this context
1401 wxGraphicsMatrix wxCairoContext::GetTransform() const
1402 {
1403 wxGraphicsMatrix matrix = CreateMatrix();
1404 cairo_get_matrix(m_context,(cairo_matrix_t*) matrix.GetNativeMatrix());
1405 return matrix;
1406 }
1407
1408
1409
1410 void wxCairoContext::PushState()
1411 {
1412 cairo_save(m_context);
1413 }
1414
1415 void wxCairoContext::PopState()
1416 {
1417 cairo_restore(m_context);
1418 }
1419
1420 void wxCairoContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
1421 {
1422 wxGraphicsBitmap bitmap = GetRenderer()->CreateBitmap(bmp);
1423 DrawBitmap(bitmap, x, y, w, h);
1424
1425 }
1426
1427 void wxCairoContext::DrawBitmap(const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
1428 {
1429 PushState();
1430
1431 // In case we're scaling the image by using a width and height different
1432 // than the bitmap's size create a pattern transformation on the surface and
1433 // draw the transformed pattern.
1434 wxCairoBitmapData* data = static_cast<wxCairoBitmapData*>(bmp.GetRefData());
1435 cairo_pattern_t* pattern = data->GetCairoPattern();
1436 wxSize size = data->GetSize();
1437
1438 wxDouble scaleX = w / size.GetWidth();
1439 wxDouble scaleY = h / size.GetHeight();
1440 cairo_scale(m_context, scaleX, scaleY);
1441
1442 // prepare to draw the image
1443 cairo_translate(m_context, x, y);
1444 cairo_set_source(m_context, pattern);
1445 // use the original size here since the context is scaled already...
1446 cairo_rectangle(m_context, 0, 0, size.GetWidth(), size.GetHeight());
1447 // fill the rectangle using the pattern
1448 cairo_fill(m_context);
1449
1450 PopState();
1451 }
1452
1453 void wxCairoContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
1454 {
1455 // An icon is a bitmap on wxGTK, so do this the easy way. When we want to
1456 // start using the Cairo backend on other platforms then we may need to
1457 // fiddle with this...
1458 DrawBitmap(icon, x, y, w, h);
1459 }
1460
1461
1462 void wxCairoContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y)
1463 {
1464 wxCHECK_RET( !m_font.IsNull(),
1465 wxT("wxCairoContext::DrawText - no valid font set") );
1466
1467 if ( str.empty())
1468 return;
1469
1470 const wxCharBuffer data = str.utf8_str();
1471 if ( !data )
1472 return;
1473
1474 ((wxCairoFontData*)m_font.GetRefData())->Apply(this);
1475
1476 #ifdef __WXGTK__
1477 size_t datalen = strlen(data);
1478
1479 PangoLayout *layout = pango_cairo_create_layout (m_context);
1480 wxCairoFontData* font_data = (wxCairoFontData*) m_font.GetRefData();
1481 pango_layout_set_font_description( layout, font_data->GetFont());
1482 pango_layout_set_text(layout, data, datalen);
1483
1484 if (font_data->GetUnderlined())
1485 {
1486 PangoAttrList *attrs = pango_attr_list_new();
1487 PangoAttribute *attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
1488 pango_attr_list_insert(attrs, attr);
1489 pango_layout_set_attributes(layout, attrs);
1490 pango_attr_list_unref(attrs);
1491 }
1492
1493 cairo_move_to(m_context, x, y);
1494 pango_cairo_show_layout (m_context, layout);
1495
1496 g_object_unref (layout);
1497 #else
1498 // Cairo's x,y for drawing text is at the baseline, so we need to adjust
1499 // the position we move to by the ascent.
1500 cairo_font_extents_t fe;
1501 cairo_font_extents(m_context, &fe);
1502 cairo_move_to(m_context, x, y+fe.ascent);
1503
1504 cairo_show_text(m_context, data);
1505 #endif
1506 }
1507
1508 void wxCairoContext::GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height,
1509 wxDouble *descent, wxDouble *externalLeading ) const
1510 {
1511 wxCHECK_RET( !m_font.IsNull(), wxT("wxCairoContext::GetTextExtent - no valid font set") );
1512
1513 if ( width )
1514 *width = 0;
1515 if ( height )
1516 *height = 0;
1517 if ( descent )
1518 *descent = 0;
1519 if ( externalLeading )
1520 *externalLeading = 0;
1521
1522 if ( str.empty())
1523 return;
1524
1525 #ifdef __WXGTK__
1526 int w, h;
1527
1528 PangoLayout *layout = pango_cairo_create_layout (m_context);
1529 pango_layout_set_font_description( layout, ((wxCairoFontData*)m_font.GetRefData())->GetFont());
1530 const wxCharBuffer data = str.utf8_str();
1531 if ( !data )
1532 {
1533 return;
1534 }
1535 pango_layout_set_text( layout, data, strlen(data) );
1536 pango_layout_get_pixel_size (layout, &w, &h);
1537 if ( width )
1538 *width = w;
1539 if ( height )
1540 *height = h;
1541 if (descent)
1542 {
1543 PangoLayoutIter *iter = pango_layout_get_iter(layout);
1544 int baseline = pango_layout_iter_get_baseline(iter);
1545 pango_layout_iter_free(iter);
1546 *descent = h - PANGO_PIXELS(baseline);
1547 }
1548 g_object_unref (layout);
1549 #else
1550 ((wxCairoFontData*)m_font.GetRefData())->Apply((wxCairoContext*)this);
1551
1552 if (width)
1553 {
1554 const wxWX2MBbuf buf(str.mb_str(wxConvUTF8));
1555 cairo_text_extents_t te;
1556 cairo_text_extents(m_context, buf, &te);
1557 *width = te.width;
1558 }
1559
1560 if (height || descent || externalLeading)
1561 {
1562 cairo_font_extents_t fe;
1563 cairo_font_extents(m_context, &fe);
1564
1565 // some backends have negative descents
1566
1567 if ( fe.descent < 0 )
1568 fe.descent = -fe.descent;
1569
1570 if ( fe.height < (fe.ascent + fe.descent ) )
1571 {
1572 // some backends are broken re height ... (eg currently ATSUI)
1573 fe.height = fe.ascent + fe.descent;
1574 }
1575
1576 if (height)
1577 *height = fe.height;
1578 if ( descent )
1579 *descent = fe.descent;
1580 if ( externalLeading )
1581 *externalLeading = wxMax(0, fe.height - (fe.ascent + fe.descent));
1582 }
1583 #endif
1584 }
1585
1586 void wxCairoContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const
1587 {
1588 widths.Empty();
1589 widths.Add(0, text.length());
1590
1591 wxCHECK_RET( !m_font.IsNull(), wxT("wxCairoContext::GetPartialTextExtents - no valid font set") );
1592
1593 if (text.empty())
1594 return;
1595
1596 // TODO
1597 }
1598
1599 void * wxCairoContext::GetNativeContext()
1600 {
1601 return m_context;
1602 }
1603
1604 bool wxCairoContext::SetAntialiasMode(wxAntialiasMode antialias)
1605 {
1606 if (m_antialias == antialias)
1607 return true;
1608
1609 m_antialias = antialias;
1610
1611 cairo_antialias_t antialiasMode;
1612 switch (antialias)
1613 {
1614 case wxANTIALIAS_DEFAULT:
1615 antialiasMode = CAIRO_ANTIALIAS_DEFAULT;
1616 break;
1617 case wxANTIALIAS_NONE:
1618 antialiasMode = CAIRO_ANTIALIAS_NONE;
1619 break;
1620 default:
1621 return false;
1622 }
1623 cairo_set_antialias(m_context, antialiasMode);
1624 return true;
1625 }
1626
1627 bool wxCairoContext::SetCompositionMode(wxCompositionMode op)
1628 {
1629 if ( m_composition == op )
1630 return true;
1631
1632 m_composition = op;
1633 cairo_operator_t cop;
1634 switch (op)
1635 {
1636 case wxCOMPOSITION_CLEAR:
1637 cop = CAIRO_OPERATOR_CLEAR;
1638 break;
1639 case wxCOMPOSITION_SOURCE:
1640 cop = CAIRO_OPERATOR_SOURCE;
1641 break;
1642 case wxCOMPOSITION_OVER:
1643 cop = CAIRO_OPERATOR_OVER;
1644 break;
1645 case wxCOMPOSITION_IN:
1646 cop = CAIRO_OPERATOR_IN;
1647 break;
1648 case wxCOMPOSITION_OUT:
1649 cop = CAIRO_OPERATOR_OUT;
1650 break;
1651 case wxCOMPOSITION_ATOP:
1652 cop = CAIRO_OPERATOR_ATOP;
1653 break;
1654 case wxCOMPOSITION_DEST:
1655 cop = CAIRO_OPERATOR_DEST;
1656 break;
1657 case wxCOMPOSITION_DEST_OVER:
1658 cop = CAIRO_OPERATOR_DEST_OVER;
1659 break;
1660 case wxCOMPOSITION_DEST_IN:
1661 cop = CAIRO_OPERATOR_DEST_IN;
1662 break;
1663 case wxCOMPOSITION_DEST_OUT:
1664 cop = CAIRO_OPERATOR_DEST_OUT;
1665 break;
1666 case wxCOMPOSITION_DEST_ATOP:
1667 cop = CAIRO_OPERATOR_DEST_ATOP;
1668 break;
1669 case wxCOMPOSITION_XOR:
1670 cop = CAIRO_OPERATOR_XOR;
1671 break;
1672 case wxCOMPOSITION_ADD:
1673 cop = CAIRO_OPERATOR_ADD;
1674 break;
1675 default:
1676 return false;
1677 }
1678 cairo_set_operator(m_context, cop);
1679 return true;
1680 }
1681
1682 void wxCairoContext::BeginLayer(wxDouble opacity)
1683 {
1684 m_layerOpacities.push_back(opacity);
1685 cairo_push_group(m_context);
1686 }
1687
1688 void wxCairoContext::EndLayer()
1689 {
1690 float opacity = m_layerOpacities.back();
1691 m_layerOpacities.pop_back();
1692 cairo_pop_group_to_source(m_context);
1693 cairo_paint_with_alpha(m_context,opacity);
1694 }
1695
1696 //-----------------------------------------------------------------------------
1697 // wxCairoRenderer declaration
1698 //-----------------------------------------------------------------------------
1699
1700 class WXDLLIMPEXP_CORE wxCairoRenderer : public wxGraphicsRenderer
1701 {
1702 public :
1703 wxCairoRenderer() {}
1704
1705 virtual ~wxCairoRenderer() {}
1706
1707 // Context
1708
1709 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc);
1710 virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc);
1711 virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc);
1712
1713 virtual wxGraphicsContext * CreateContextFromNativeContext( void * context );
1714
1715 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window );
1716
1717 virtual wxGraphicsContext * CreateContext( wxWindow* window );
1718
1719 virtual wxGraphicsContext * CreateMeasuringContext();
1720
1721 // Path
1722
1723 virtual wxGraphicsPath CreatePath();
1724
1725 // Matrix
1726
1727 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
1728 wxDouble tx=0.0, wxDouble ty=0.0);
1729
1730
1731 virtual wxGraphicsPen CreatePen(const wxPen& pen) ;
1732
1733 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) ;
1734
1735 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1736 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
1737 const wxColour&c1, const wxColour&c2) ;
1738
1739 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1740 // with radius r and color cColor
1741 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
1742 const wxColour &oColor, const wxColour &cColor) ;
1743
1744 // sets the font
1745 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) ;
1746
1747 // create a native bitmap representation
1748 virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap );
1749
1750 // create a graphics bitmap from a native bitmap
1751 virtual wxGraphicsBitmap CreateBitmapFromNativeBitmap( void* bitmap );
1752
1753 // create a subimage from a native image representation
1754 virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
1755
1756 private :
1757 DECLARE_DYNAMIC_CLASS_NO_COPY(wxCairoRenderer)
1758 } ;
1759
1760 //-----------------------------------------------------------------------------
1761 // wxCairoRenderer implementation
1762 //-----------------------------------------------------------------------------
1763
1764 IMPLEMENT_DYNAMIC_CLASS(wxCairoRenderer,wxGraphicsRenderer)
1765
1766 static wxCairoRenderer gs_cairoGraphicsRenderer;
1767 // temporary hack to allow creating a cairo context on any platform
1768 extern wxGraphicsRenderer* gCairoRenderer;
1769 wxGraphicsRenderer* gCairoRenderer = &gs_cairoGraphicsRenderer;
1770
1771 #ifdef __WXGTK__
1772 wxGraphicsRenderer* wxGraphicsRenderer::GetDefaultRenderer()
1773 {
1774 return &gs_cairoGraphicsRenderer;
1775 }
1776 #endif
1777
1778 wxGraphicsContext * wxCairoRenderer::CreateContext( const wxWindowDC& dc)
1779 {
1780 return new wxCairoContext(this,dc);
1781 }
1782
1783 wxGraphicsContext * wxCairoRenderer::CreateContext( const wxMemoryDC& dc)
1784 {
1785 return new wxCairoContext(this,dc);
1786 }
1787
1788 wxGraphicsContext * wxCairoRenderer::CreateContext( const wxPrinterDC& dc)
1789 {
1790 #ifdef __WXGTK20__
1791 const wxDCImpl *impl = dc.GetImpl();
1792 cairo_t* context = (cairo_t*) impl->GetCairoContext();
1793 if (context)
1794 return new wxCairoContext(this,dc);
1795 else
1796 #endif
1797 return NULL;
1798 }
1799
1800 wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeContext( void * context )
1801 {
1802 #ifdef __WXMSW__
1803 return new wxCairoContext(this,(HDC)context);
1804 #endif
1805 #ifdef __WXGTK__
1806 return new wxCairoContext(this,(cairo_t*)context);
1807 #endif
1808 }
1809
1810
1811 wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeWindow( void * window )
1812 {
1813 #ifdef __WXGTK__
1814 return new wxCairoContext(this,(GdkDrawable*)window);
1815 #else
1816 return NULL;
1817 #endif
1818 }
1819
1820 wxGraphicsContext * wxCairoRenderer::CreateMeasuringContext()
1821 {
1822 #ifdef __WXGTK__
1823 return CreateContextFromNativeWindow(gdk_get_default_root_window());
1824 #endif
1825 return NULL;
1826 // TODO
1827 }
1828
1829 wxGraphicsContext * wxCairoRenderer::CreateContext( wxWindow* window )
1830 {
1831 return new wxCairoContext(this, window );
1832 }
1833
1834 // Path
1835
1836 wxGraphicsPath wxCairoRenderer::CreatePath()
1837 {
1838 wxGraphicsPath path;
1839 path.SetRefData( new wxCairoPathData(this) );
1840 return path;
1841 }
1842
1843
1844 // Matrix
1845
1846 wxGraphicsMatrix wxCairoRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDouble c, wxDouble d,
1847 wxDouble tx, wxDouble ty)
1848
1849 {
1850 wxGraphicsMatrix m;
1851 wxCairoMatrixData* data = new wxCairoMatrixData( this );
1852 data->Set( a,b,c,d,tx,ty ) ;
1853 m.SetRefData(data);
1854 return m;
1855 }
1856
1857 wxGraphicsPen wxCairoRenderer::CreatePen(const wxPen& pen)
1858 {
1859 if ( !pen.Ok() || pen.GetStyle() == wxPENSTYLE_TRANSPARENT )
1860 return wxNullGraphicsPen;
1861 else
1862 {
1863 wxGraphicsPen p;
1864 p.SetRefData(new wxCairoPenData( this, pen ));
1865 return p;
1866 }
1867 }
1868
1869 wxGraphicsBrush wxCairoRenderer::CreateBrush(const wxBrush& brush )
1870 {
1871 if ( !brush.Ok() || brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT )
1872 return wxNullGraphicsBrush;
1873 else
1874 {
1875 wxGraphicsBrush p;
1876 p.SetRefData(new wxCairoBrushData( this, brush ));
1877 return p;
1878 }
1879 }
1880
1881 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1882 wxGraphicsBrush wxCairoRenderer::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
1883 const wxColour&c1, const wxColour&c2)
1884 {
1885 wxGraphicsBrush p;
1886 wxCairoBrushData* d = new wxCairoBrushData( this );
1887 d->CreateLinearGradientBrush(x1, y1, x2, y2, c1, c2);
1888 p.SetRefData(d);
1889 return p;
1890 }
1891
1892 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1893 // with radius r and color cColor
1894 wxGraphicsBrush wxCairoRenderer::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
1895 const wxColour &oColor, const wxColour &cColor)
1896 {
1897 wxGraphicsBrush p;
1898 wxCairoBrushData* d = new wxCairoBrushData( this );
1899 d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,oColor,cColor);
1900 p.SetRefData(d);
1901 return p;
1902 }
1903
1904 // sets the font
1905 wxGraphicsFont wxCairoRenderer::CreateFont( const wxFont &font , const wxColour &col )
1906 {
1907 if ( font.Ok() )
1908 {
1909 wxGraphicsFont p;
1910 p.SetRefData(new wxCairoFontData( this , font, col ));
1911 return p;
1912 }
1913 else
1914 return wxNullGraphicsFont;
1915 }
1916
1917 wxGraphicsBitmap wxCairoRenderer::CreateBitmap( const wxBitmap& bmp )
1918 {
1919 if ( bmp.Ok() )
1920 {
1921 wxGraphicsBitmap p;
1922 p.SetRefData(new wxCairoBitmapData( this , bmp ));
1923 return p;
1924 }
1925 else
1926 return wxNullGraphicsBitmap;
1927 }
1928
1929 wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromNativeBitmap( void* bitmap )
1930 {
1931 if ( bitmap != NULL )
1932 {
1933 wxGraphicsBitmap p;
1934 p.SetRefData(new wxCairoBitmapData( this , (cairo_surface_t*) bitmap ));
1935 return p;
1936 }
1937 else
1938 return wxNullGraphicsBitmap;
1939 }
1940
1941 wxGraphicsBitmap
1942 wxCairoRenderer::CreateSubBitmap(const wxGraphicsBitmap& WXUNUSED(bitmap),
1943 wxDouble WXUNUSED(x),
1944 wxDouble WXUNUSED(y),
1945 wxDouble WXUNUSED(w),
1946 wxDouble WXUNUSED(h))
1947 {
1948 wxFAIL_MSG("wxCairoRenderer::CreateSubBitmap is not implemented.");
1949 return wxNullGraphicsBitmap;
1950 }
1951
1952 #endif // wxUSE_GRAPHICS_CONTEXT && wxUSE_CAIRO
1953
1954 #if wxUSE_GRAPHICS_CONTEXT
1955 wxGraphicsRenderer* wxGraphicsRenderer::GetCairoRenderer()
1956 {
1957 #if wxUSE_CAIRO
1958 return &gs_cairoGraphicsRenderer;
1959 #else
1960 return NULL;
1961 #endif
1962 }
1963 #endif