1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/dccg.cpp
4 // Author: Stefan Csomor
8 // copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/graphics.h"
15 #include "wx/private/graphics.h"
18 #include "wx/dcclient.h"
19 #include "wx/dcmemory.h"
20 #include "wx/dcprint.h"
22 #include "wx/region.h"
31 // in case our functions were defined outside std, we make it known all the same
38 #include "wx/osx/private.h"
39 #include "wx/osx/dcprint.h"
40 #include "wx/osx/dcclient.h"
41 #include "wx/osx/dcmemory.h"
42 #include "wx/osx/private.h"
44 #include "CoreServices/CoreServices.h"
45 #include "ApplicationServices/ApplicationServices.h"
46 #include "wx/osx/core/cfstring.h"
47 #include "wx/cocoa/dcclient.h"
52 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
54 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
56 if (genericRGBColorSpace
== NULL
)
58 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
61 return genericRGBColorSpace
;
64 int UMAGetSystemVersion()
70 #define wxOSX_USE_CORE_TEXT 1
74 #if wxOSX_USE_COCOA_OR_IPHONE
75 extern CGContextRef
wxOSXGetContextFromCurrentContext() ;
77 extern bool wxOSXLockFocus( WXWidget view
) ;
78 extern void wxOSXUnlockFocus( WXWidget view
) ;
82 #if 1 // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
84 // TODO test whether this private API also works under 10.3
86 // copying values from NSCompositingModes (see also webkit and cairo sources)
88 typedef enum CGCompositeOperation
{
89 kCGCompositeOperationClear
= 0,
90 kCGCompositeOperationCopy
= 1,
91 kCGCompositeOperationSourceOver
= 2,
92 kCGCompositeOperationSourceIn
= 3,
93 kCGCompositeOperationSourceOut
= 4,
94 kCGCompositeOperationSourceAtop
= 5,
95 kCGCompositeOperationDestinationOver
= 6,
96 kCGCompositeOperationDestinationIn
= 7,
97 kCGCompositeOperationDestinationOut
= 8,
98 kCGCompositeOperationDestinationAtop
= 9,
99 kCGCompositeOperationXOR
= 10,
100 kCGCompositeOperationPlusDarker
= 11,
101 // NS only, unsupported by CG : Highlight
102 kCGCompositeOperationPlusLighter
= 12
103 } CGCompositeOperation
;
107 CG_EXTERN
void CGContextSetCompositeOperation (CGContextRef context
, int operation
);
112 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
116 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
118 const double M_PI
= 3.14159265358979;
122 static const double RAD2DEG
= 180.0 / M_PI
;
125 // Pen, Brushes and Fonts
129 #pragma mark wxMacCoreGraphicsPattern, ImagePattern, HatchPattern classes
131 OSStatus
wxMacDrawCGImage(
132 CGContextRef inContext
,
133 const CGRect
* inBounds
,
137 return HIViewDrawCGImage( inContext
, inBounds
, inImage
);
139 CGContextSaveGState(inContext
);
140 CGContextTranslateCTM(inContext
, inBounds
->origin
.x
, inBounds
->origin
.y
+ inBounds
->size
.height
);
141 CGRect r
= *inBounds
;
142 r
.origin
.x
= r
.origin
.y
= 0;
143 CGContextScaleCTM(inContext
, 1, -1);
144 CGContextDrawImage(inContext
, r
, inImage
);
145 CGContextRestoreGState(inContext
);
150 CGColorRef
wxMacCreateCGColor( const wxColour
& col
)
152 CGColorRef retval
= 0;
154 retval
= col
.CreateCGColor();
156 // TODO add conversion NSColor - CGColorRef (obj-c)
157 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
158 if ( CGColorCreateGenericRGB
)
159 retval
= CGColorCreateGenericRGB( col
.Red() / 255.0 , col
.Green() / 255.0, col
.Blue() / 255.0, col
.Alpha() / 255.0 );
163 CGFloat components
[4] = { col
.Red() / 255.0, col
.Green() / 255.0, col
.Blue() / 255.0, col
.Alpha() / 255.0 } ;
164 retval
= CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ;
171 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 && wxOSX_USE_CORE_TEXT
173 CTFontRef
wxMacCreateCTFont( const wxFont
& font
)
176 return wxCFRetain((CTFontRef
) font
.OSXGetCTFont());
178 return CTFontCreateWithName( wxCFStringRef( font
.GetFaceName(), wxLocale::GetSystemEncoding() ) , font
.GetPointSize() , NULL
);
184 // CGPattern wrapper class: always allocate on heap, never call destructor
186 class wxMacCoreGraphicsPattern
189 wxMacCoreGraphicsPattern() {}
191 // is guaranteed to be called only with a non-Null CGContextRef
192 virtual void Render( CGContextRef ctxRef
) = 0;
194 operator CGPatternRef() const { return m_patternRef
; }
197 virtual ~wxMacCoreGraphicsPattern()
199 // as this is called only when the m_patternRef is been released;
200 // don't release it again
203 static void _Render( void *info
, CGContextRef ctxRef
)
205 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
206 if ( self
&& ctxRef
)
207 self
->Render( ctxRef
);
210 static void _Dispose( void *info
)
212 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
216 CGPatternRef m_patternRef
;
218 static const CGPatternCallbacks ms_Callbacks
;
221 const CGPatternCallbacks
wxMacCoreGraphicsPattern::ms_Callbacks
= { 0, &wxMacCoreGraphicsPattern::_Render
, &wxMacCoreGraphicsPattern::_Dispose
};
223 class ImagePattern
: public wxMacCoreGraphicsPattern
226 ImagePattern( const wxBitmap
* bmp
, const CGAffineTransform
& transform
)
228 wxASSERT( bmp
&& bmp
->Ok() );
230 Init( (CGImageRef
) bmp
->CreateCGImage() , transform
);
234 // ImagePattern takes ownership of CGImageRef passed in
235 ImagePattern( CGImageRef image
, const CGAffineTransform
& transform
)
240 Init( image
, transform
);
243 virtual void Render( CGContextRef ctxRef
)
246 wxMacDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
250 void Init( CGImageRef image
, const CGAffineTransform
& transform
)
255 m_imageBounds
= CGRectMake( (CGFloat
) 0.0, (CGFloat
) 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) );
256 m_patternRef
= CGPatternCreate(
257 this , m_imageBounds
, transform
,
258 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
259 kCGPatternTilingNoDistortion
, true , &wxMacCoreGraphicsPattern::ms_Callbacks
);
263 virtual ~ImagePattern()
266 CGImageRelease( m_image
);
270 CGRect m_imageBounds
;
273 class HatchPattern
: public wxMacCoreGraphicsPattern
276 HatchPattern( int hatchstyle
, const CGAffineTransform
& transform
)
278 m_hatch
= hatchstyle
;
279 m_imageBounds
= CGRectMake( (CGFloat
) 0.0, (CGFloat
) 0.0, (CGFloat
) 8.0 , (CGFloat
) 8.0 );
280 m_patternRef
= CGPatternCreate(
281 this , m_imageBounds
, transform
,
282 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
283 kCGPatternTilingNoDistortion
, false , &wxMacCoreGraphicsPattern::ms_Callbacks
);
286 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
288 CGContextStrokeLineSegments( ctxRef
, pts
, count
);
291 virtual void Render( CGContextRef ctxRef
)
295 case wxBDIAGONAL_HATCH
:
299 { (CGFloat
) 8.0 , (CGFloat
) 0.0 } , { (CGFloat
) 0.0 , (CGFloat
) 8.0 }
301 StrokeLineSegments( ctxRef
, pts
, 2 );
305 case wxCROSSDIAG_HATCH
:
309 { (CGFloat
) 0.0 , (CGFloat
) 0.0 } , { (CGFloat
) 8.0 , (CGFloat
) 8.0 } ,
310 { (CGFloat
) 8.0 , (CGFloat
) 0.0 } , { (CGFloat
) 0.0 , (CGFloat
) 8.0 }
312 StrokeLineSegments( ctxRef
, pts
, 4 );
316 case wxFDIAGONAL_HATCH
:
320 { (CGFloat
) 0.0 , (CGFloat
) 0.0 } , { (CGFloat
) 8.0 , (CGFloat
) 8.0 }
322 StrokeLineSegments( ctxRef
, pts
, 2 );
330 { (CGFloat
) 0.0 , (CGFloat
) 4.0 } , { (CGFloat
) 8.0 , (CGFloat
) 4.0 } ,
331 { (CGFloat
) 4.0 , (CGFloat
) 0.0 } , { (CGFloat
) 4.0 , (CGFloat
) 8.0 } ,
333 StrokeLineSegments( ctxRef
, pts
, 4 );
337 case wxHORIZONTAL_HATCH
:
341 { (CGFloat
) 0.0 , (CGFloat
) 4.0 } , { (CGFloat
) 8.0 , (CGFloat
) 4.0 } ,
343 StrokeLineSegments( ctxRef
, pts
, 2 );
347 case wxVERTICAL_HATCH
:
351 { (CGFloat
) 4.0 , (CGFloat
) 0.0 } , { (CGFloat
) 4.0 , (CGFloat
) 8.0 } ,
353 StrokeLineSegments( ctxRef
, pts
, 2 );
363 virtual ~HatchPattern() {}
365 CGRect m_imageBounds
;
369 class wxMacCoreGraphicsPenData
: public wxGraphicsObjectRefData
372 wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
373 ~wxMacCoreGraphicsPenData();
376 virtual void Apply( wxGraphicsContext
* context
);
377 virtual wxDouble
GetWidth() { return m_width
; }
381 wxCFRef
<CGColorRef
> m_color
;
382 wxCFRef
<CGColorSpaceRef
> m_colorSpace
;
388 const CGFloat
*m_lengths
;
389 CGFloat
*m_userLengths
;
393 wxCFRef
<CGPatternRef
> m_pattern
;
394 CGFloat
* m_patternColorComponents
;
397 wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
) :
398 wxGraphicsObjectRefData( renderer
)
402 m_color
.reset( wxMacCreateCGColor( pen
.GetColour() ) ) ;
404 // TODO: * m_dc->m_scaleX
405 m_width
= pen
.GetWidth();
407 m_width
= (CGFloat
) 0.1;
409 switch ( pen
.GetCap() )
412 m_cap
= kCGLineCapRound
;
415 case wxCAP_PROJECTING
:
416 m_cap
= kCGLineCapSquare
;
420 m_cap
= kCGLineCapButt
;
424 m_cap
= kCGLineCapButt
;
428 switch ( pen
.GetJoin() )
431 m_join
= kCGLineJoinBevel
;
435 m_join
= kCGLineJoinMiter
;
439 m_join
= kCGLineJoinRound
;
443 m_join
= kCGLineJoinMiter
;
447 const CGFloat dashUnit
= m_width
< 1.0 ? (CGFloat
) 1.0 : m_width
;
449 const CGFloat dotted
[] = { (CGFloat
) dashUnit
, (CGFloat
) (dashUnit
+ 2.0) };
450 static const CGFloat short_dashed
[] = { (CGFloat
) 9.0 , (CGFloat
) 6.0 };
451 static const CGFloat dashed
[] = { (CGFloat
) 19.0 , (CGFloat
) 9.0 };
452 static const CGFloat dotted_dashed
[] = { (CGFloat
) 9.0 , (CGFloat
) 6.0 , (CGFloat
) 3.0 , (CGFloat
) 3.0 };
454 switch ( pen
.GetStyle() )
456 case wxPENSTYLE_SOLID
:
460 m_count
= WXSIZEOF(dotted
);
461 m_userLengths
= new CGFloat
[ m_count
] ;
462 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
463 m_lengths
= m_userLengths
;
466 case wxPENSTYLE_LONG_DASH
:
467 m_count
= WXSIZEOF(dashed
);
471 case wxPENSTYLE_SHORT_DASH
:
472 m_count
= WXSIZEOF(short_dashed
);
473 m_lengths
= short_dashed
;
476 case wxPENSTYLE_DOT_DASH
:
477 m_count
= WXSIZEOF(dotted_dashed
);
478 m_lengths
= dotted_dashed
;
481 case wxPENSTYLE_USER_DASH
:
483 m_count
= pen
.GetDashes( &dashes
);
484 if ((dashes
!= NULL
) && (m_count
> 0))
486 m_userLengths
= new CGFloat
[m_count
];
487 for ( int i
= 0; i
< m_count
; ++i
)
489 m_userLengths
[i
] = dashes
[i
] * dashUnit
;
491 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
492 m_userLengths
[i
] = (CGFloat
) (dashUnit
+ 2.0);
493 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
494 m_userLengths
[i
] = dashUnit
;
497 m_lengths
= m_userLengths
;
500 case wxPENSTYLE_STIPPLE
:
502 wxBitmap
* bmp
= pen
.GetStipple();
503 if ( bmp
&& bmp
->Ok() )
505 m_colorSpace
.reset( CGColorSpaceCreatePattern( NULL
) );
506 m_pattern
.reset( (CGPatternRef
) *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
507 m_patternColorComponents
= new CGFloat
[1] ;
508 m_patternColorComponents
[0] = (CGFloat
) 1.0;
517 m_colorSpace
.reset( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
518 m_pattern
.reset( (CGPatternRef
) *( new HatchPattern( pen
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
519 m_patternColorComponents
= new CGFloat
[4] ;
520 m_patternColorComponents
[0] = (CGFloat
) (pen
.GetColour().Red() / 255.0);
521 m_patternColorComponents
[1] = (CGFloat
) (pen
.GetColour().Green() / 255.0);
522 m_patternColorComponents
[2] = (CGFloat
) (pen
.GetColour().Blue() / 255.0);
523 m_patternColorComponents
[3] = (CGFloat
) (pen
.GetColour().Alpha() / 255.0);
527 if ((m_lengths
!= NULL
) && (m_count
> 0))
529 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
530 m_cap
= kCGLineCapButt
;
534 wxMacCoreGraphicsPenData::~wxMacCoreGraphicsPenData()
536 delete[] m_userLengths
;
537 delete[] m_patternColorComponents
;
540 void wxMacCoreGraphicsPenData::Init()
543 m_userLengths
= NULL
;
546 m_patternColorComponents
= NULL
;
550 void wxMacCoreGraphicsPenData::Apply( wxGraphicsContext
* context
)
552 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
553 CGContextSetLineWidth( cg
, m_width
);
554 CGContextSetLineJoin( cg
, m_join
);
556 CGContextSetLineDash( cg
, 0 , m_lengths
, m_count
);
557 CGContextSetLineCap( cg
, m_cap
);
561 CGAffineTransform matrix
= CGContextGetCTM( cg
);
562 CGContextSetPatternPhase( cg
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
563 CGContextSetStrokeColorSpace( cg
, m_colorSpace
);
564 CGContextSetStrokePattern( cg
, m_pattern
, m_patternColorComponents
);
568 CGContextSetStrokeColorWithColor( cg
, m_color
);
576 // make sure we all use one class for all conversions from wx to native colour
578 class wxMacCoreGraphicsColour
581 wxMacCoreGraphicsColour();
582 wxMacCoreGraphicsColour(const wxBrush
&brush
);
583 ~wxMacCoreGraphicsColour();
585 void Apply( CGContextRef cgContext
);
588 wxCFRef
<CGColorRef
> m_color
;
589 wxCFRef
<CGColorSpaceRef
> m_colorSpace
;
592 wxCFRef
<CGPatternRef
> m_pattern
;
593 CGFloat
* m_patternColorComponents
;
596 wxMacCoreGraphicsColour::~wxMacCoreGraphicsColour()
598 delete[] m_patternColorComponents
;
601 void wxMacCoreGraphicsColour::Init()
604 m_patternColorComponents
= NULL
;
607 void wxMacCoreGraphicsColour::Apply( CGContextRef cgContext
)
611 CGAffineTransform matrix
= CGContextGetCTM( cgContext
);
612 CGContextSetPatternPhase( cgContext
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
613 CGContextSetFillColorSpace( cgContext
, m_colorSpace
);
614 CGContextSetFillPattern( cgContext
, m_pattern
, m_patternColorComponents
);
618 CGContextSetFillColorWithColor( cgContext
, m_color
);
622 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour()
627 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush
&brush
)
630 if ( brush
.GetStyle() == wxSOLID
)
632 m_color
.reset( wxMacCreateCGColor( brush
.GetColour() ));
634 else if ( brush
.IsHatch() )
637 m_colorSpace
.reset( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
638 m_pattern
.reset( (CGPatternRef
) *( new HatchPattern( brush
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
640 m_patternColorComponents
= new CGFloat
[4] ;
641 m_patternColorComponents
[0] = (CGFloat
) (brush
.GetColour().Red() / 255.0);
642 m_patternColorComponents
[1] = (CGFloat
) (brush
.GetColour().Green() / 255.0);
643 m_patternColorComponents
[2] = (CGFloat
) (brush
.GetColour().Blue() / 255.0);
644 m_patternColorComponents
[3] = (CGFloat
) (brush
.GetColour().Alpha() / 255.0);
648 // now brush is a bitmap
649 wxBitmap
* bmp
= brush
.GetStipple();
650 if ( bmp
&& bmp
->Ok() )
653 m_patternColorComponents
= new CGFloat
[1] ;
654 m_patternColorComponents
[0] = (CGFloat
) 1.0;
655 m_colorSpace
.reset( CGColorSpaceCreatePattern( NULL
) );
656 m_pattern
.reset( (CGPatternRef
) *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
661 class wxMacCoreGraphicsBrushData
: public wxGraphicsObjectRefData
664 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
);
665 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
666 ~wxMacCoreGraphicsBrushData ();
668 virtual void Apply( wxGraphicsContext
* context
);
669 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
670 const wxColour
&c1
, const wxColour
&c2
);
671 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
672 const wxColour
&oColor
, const wxColour
&cColor
);
674 virtual bool IsShading() { return m_isShading
; }
675 CGShadingRef
GetShading() { return m_shading
; }
677 CGFunctionRef
CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
);
678 static void CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
);
681 wxMacCoreGraphicsColour m_cgColor
;
684 CGFunctionRef m_gradientFunction
;
685 CGShadingRef m_shading
;
686 CGFloat
*m_gradientComponents
;
689 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
) : wxGraphicsObjectRefData( renderer
)
694 void wxMacCoreGraphicsBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
695 const wxColour
&c1
, const wxColour
&c2
)
697 m_gradientFunction
= CreateGradientFunction( c1
, c2
);
698 m_shading
= CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake((CGFloat
) x1
, (CGFloat
) y1
),
699 CGPointMake((CGFloat
) x2
,(CGFloat
) y2
), m_gradientFunction
, true, true ) ;
703 void wxMacCoreGraphicsBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
704 const wxColour
&oColor
, const wxColour
&cColor
)
706 m_gradientFunction
= CreateGradientFunction( oColor
, cColor
);
707 m_shading
= CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake((CGFloat
) xo
,(CGFloat
) yo
), 0,
708 CGPointMake((CGFloat
) xc
,(CGFloat
) yc
), (CGFloat
) radius
, m_gradientFunction
, true, true ) ;
712 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer
* renderer
, const wxBrush
&brush
) : wxGraphicsObjectRefData( renderer
),
719 wxMacCoreGraphicsBrushData::~wxMacCoreGraphicsBrushData()
722 CGShadingRelease(m_shading
);
724 if( m_gradientFunction
)
725 CGFunctionRelease(m_gradientFunction
);
727 delete[] m_gradientComponents
;
730 void wxMacCoreGraphicsBrushData::Init()
732 m_gradientFunction
= NULL
;
734 m_gradientComponents
= NULL
;
738 void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext
* context
)
740 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
744 // nothing to set as shades are processed by clipping using the path and filling
748 m_cgColor
.Apply( cg
);
752 void wxMacCoreGraphicsBrushData::CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
)
754 CGFloat
* colors
= (CGFloat
*) info
;
756 for( int i
= 0 ; i
< 4 ; ++i
)
758 out
[i
] = colors
[i
] + ( colors
[4+i
] - colors
[i
] ) * f
;
762 CGFunctionRef
wxMacCoreGraphicsBrushData::CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
)
764 static const CGFunctionCallbacks callbacks
= { 0, &CalculateShadingValues
, NULL
};
765 static const CGFloat input_value_range
[2] = { 0, 1 };
766 static const CGFloat output_value_ranges
[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
767 m_gradientComponents
= new CGFloat
[8] ;
768 m_gradientComponents
[0] = (CGFloat
) (c1
.Red() / 255.0);
769 m_gradientComponents
[1] = (CGFloat
) (c1
.Green() / 255.0);
770 m_gradientComponents
[2] = (CGFloat
) (c1
.Blue() / 255.0);
771 m_gradientComponents
[3] = (CGFloat
) (c1
.Alpha() / 255.0);
772 m_gradientComponents
[4] = (CGFloat
) (c2
.Red() / 255.0);
773 m_gradientComponents
[5] = (CGFloat
) (c2
.Green() / 255.0);
774 m_gradientComponents
[6] = (CGFloat
) (c2
.Blue() / 255.0);
775 m_gradientComponents
[7] = (CGFloat
) (c2
.Alpha() / 255.0);
777 return CGFunctionCreate ( m_gradientComponents
, 1,
790 extern UIFont
* CreateUIFont( const wxFont
& font
);
791 extern void DrawTextInContext( CGContextRef context
, CGPoint where
, UIFont
*font
, NSString
* text
);
792 extern CGSize
MeasureTextInContext( UIFont
*font
, NSString
* text
);
796 class wxMacCoreGraphicsFontData
: public wxGraphicsObjectRefData
799 wxMacCoreGraphicsFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
800 ~wxMacCoreGraphicsFontData();
802 #if wxOSX_USE_ATSU_TEXT
803 virtual ATSUStyle
GetATSUStyle() { return m_macATSUIStyle
; }
805 #if wxOSX_USE_CORE_TEXT
806 CTFontRef
OSXGetCTFont() const { return m_ctFont
; }
808 wxColour
GetColour() const { return m_colour
; }
810 bool GetUnderlined() const { return m_underlined
; }
812 UIFont
* GetUIFont() const { return m_uiFont
; }
817 #if wxOSX_USE_ATSU_TEXT
818 ATSUStyle m_macATSUIStyle
;
820 #if wxOSX_USE_CORE_TEXT
821 wxCFRef
< CTFontRef
> m_ctFont
;
828 wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
) : wxGraphicsObjectRefData( renderer
)
831 m_underlined
= font
.GetUnderlined();
833 #if wxOSX_USE_CORE_TEXT
834 m_ctFont
.reset( wxMacCreateCTFont( font
) );
837 m_uiFont
= CreateUIFont(font
);
838 wxMacCocoaRetain( m_uiFont
);
840 #if wxOSX_USE_ATSU_TEXT
841 OSStatus status
= noErr
;
842 m_macATSUIStyle
= NULL
;
844 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , &m_macATSUIStyle
);
846 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") );
848 // we need the scale here ...
850 Fixed atsuSize
= IntToFixed( int( 1 * font
.GetPointSize()) );
852 col
.GetRGBColor( &atsuColor
);
853 ATSUAttributeTag atsuTags
[] =
858 ByteCount atsuSizes
[WXSIZEOF(atsuTags
)] =
863 ATSUAttributeValuePtr atsuValues
[WXSIZEOF(atsuTags
)] =
869 status
= ::ATSUSetAttributes(
870 m_macATSUIStyle
, WXSIZEOF(atsuTags
),
871 atsuTags
, atsuSizes
, atsuValues
);
873 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") );
877 wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData()
879 #if wxOSX_USE_CORE_TEXT
881 #if wxOSX_USE_ATSU_TEXT
882 if ( m_macATSUIStyle
)
884 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
885 m_macATSUIStyle
= NULL
;
889 wxMacCocoaRelease( m_uiFont
);
893 class wxMacCoreGraphicsBitmapData
: public wxGraphicsObjectRefData
896 wxMacCoreGraphicsBitmapData( wxGraphicsRenderer
* renderer
, CGImageRef bitmap
, bool monochrome
);
897 ~wxMacCoreGraphicsBitmapData();
899 virtual CGImageRef
GetBitmap() { return m_bitmap
; }
900 bool IsMonochrome() { return m_monochrome
; }
906 wxMacCoreGraphicsBitmapData::wxMacCoreGraphicsBitmapData( wxGraphicsRenderer
* renderer
, CGImageRef bitmap
, bool monochrome
) : wxGraphicsObjectRefData( renderer
),
907 m_bitmap(bitmap
), m_monochrome(monochrome
)
911 wxMacCoreGraphicsBitmapData::~wxMacCoreGraphicsBitmapData()
913 CGImageRelease( m_bitmap
);
920 //-----------------------------------------------------------------------------
921 // wxMacCoreGraphicsMatrix declaration
922 //-----------------------------------------------------------------------------
924 class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData
: public wxGraphicsMatrixData
927 wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) ;
929 virtual ~wxMacCoreGraphicsMatrixData() ;
931 virtual wxGraphicsObjectRefData
*Clone() const ;
933 // concatenates the matrix
934 virtual void Concat( const wxGraphicsMatrixData
*t
);
936 // sets the matrix to the respective values
937 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
938 wxDouble tx
=0.0, wxDouble ty
=0.0);
940 // gets the component valuess of the matrix
941 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
942 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
944 // makes this the inverse matrix
945 virtual void Invert();
947 // returns true if the elements of the transformation matrix are equal ?
948 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
950 // return true if this is the identity matrix
951 virtual bool IsIdentity() const;
957 // add the translation to this matrix
958 virtual void Translate( wxDouble dx
, wxDouble dy
);
960 // add the scale to this matrix
961 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
963 // add the rotation to this matrix (radians)
964 virtual void Rotate( wxDouble angle
);
967 // apply the transforms
970 // applies that matrix to the point
971 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
973 // applies the matrix except for translations
974 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
976 // returns the native representation
977 virtual void * GetNativeMatrix() const;
980 CGAffineTransform m_matrix
;
983 //-----------------------------------------------------------------------------
984 // wxMacCoreGraphicsMatrix implementation
985 //-----------------------------------------------------------------------------
987 wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) : wxGraphicsMatrixData(renderer
)
991 wxMacCoreGraphicsMatrixData::~wxMacCoreGraphicsMatrixData()
995 wxGraphicsObjectRefData
*wxMacCoreGraphicsMatrixData::Clone() const
997 wxMacCoreGraphicsMatrixData
* m
= new wxMacCoreGraphicsMatrixData(GetRenderer()) ;
998 m
->m_matrix
= m_matrix
;
1002 // concatenates the matrix
1003 void wxMacCoreGraphicsMatrixData::Concat( const wxGraphicsMatrixData
*t
)
1005 m_matrix
= CGAffineTransformConcat(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()) );
1008 // sets the matrix to the respective values
1009 void wxMacCoreGraphicsMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
1010 wxDouble tx
, wxDouble ty
)
1012 m_matrix
= CGAffineTransformMake((CGFloat
) a
,(CGFloat
) b
,(CGFloat
) c
,(CGFloat
) d
,(CGFloat
) tx
,(CGFloat
) ty
);
1015 // gets the component valuess of the matrix
1016 void wxMacCoreGraphicsMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
1017 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
1019 if (a
) *a
= m_matrix
.a
;
1020 if (b
) *b
= m_matrix
.b
;
1021 if (c
) *c
= m_matrix
.c
;
1022 if (d
) *d
= m_matrix
.d
;
1023 if (tx
) *tx
= m_matrix
.tx
;
1024 if (ty
) *ty
= m_matrix
.ty
;
1027 // makes this the inverse matrix
1028 void wxMacCoreGraphicsMatrixData::Invert()
1030 m_matrix
= CGAffineTransformInvert( m_matrix
);
1033 // returns true if the elements of the transformation matrix are equal ?
1034 bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
1036 return CGAffineTransformEqualToTransform(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()));
1039 // return true if this is the identity matrix
1040 bool wxMacCoreGraphicsMatrixData::IsIdentity() const
1042 return ( m_matrix
.a
== 1 && m_matrix
.d
== 1 &&
1043 m_matrix
.b
== 0 && m_matrix
.d
== 0 && m_matrix
.tx
== 0 && m_matrix
.ty
== 0);
1050 // add the translation to this matrix
1051 void wxMacCoreGraphicsMatrixData::Translate( wxDouble dx
, wxDouble dy
)
1053 m_matrix
= CGAffineTransformTranslate( m_matrix
, (CGFloat
) dx
, (CGFloat
) dy
);
1056 // add the scale to this matrix
1057 void wxMacCoreGraphicsMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
1059 m_matrix
= CGAffineTransformScale( m_matrix
, (CGFloat
) xScale
, (CGFloat
) yScale
);
1062 // add the rotation to this matrix (radians)
1063 void wxMacCoreGraphicsMatrixData::Rotate( wxDouble angle
)
1065 m_matrix
= CGAffineTransformRotate( m_matrix
, (CGFloat
) angle
);
1069 // apply the transforms
1072 // applies that matrix to the point
1073 void wxMacCoreGraphicsMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
1075 CGPoint pt
= CGPointApplyAffineTransform( CGPointMake((CGFloat
) *x
,(CGFloat
) *y
), m_matrix
);
1081 // applies the matrix except for translations
1082 void wxMacCoreGraphicsMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
1084 CGSize sz
= CGSizeApplyAffineTransform( CGSizeMake((CGFloat
) *dx
,(CGFloat
) *dy
) , m_matrix
);
1089 // returns the native representation
1090 void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const
1092 return (void*) &m_matrix
;
1099 //-----------------------------------------------------------------------------
1100 // wxMacCoreGraphicsPath declaration
1101 //-----------------------------------------------------------------------------
1103 class WXDLLEXPORT wxMacCoreGraphicsPathData
: public wxGraphicsPathData
1106 wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
= NULL
);
1108 ~wxMacCoreGraphicsPathData();
1110 virtual wxGraphicsObjectRefData
*Clone() const;
1112 // begins a new subpath at (x,y)
1113 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
1115 // adds a straight line from the current point to (x,y)
1116 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
1118 // adds a cubic Bezier curve from the current point, using two control points and an end point
1119 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
1121 // closes the current sub-path
1122 virtual void CloseSubpath();
1124 // gets the last point of the current path, (0,0) if not yet set
1125 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
1127 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
1128 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
1131 // These are convenience functions which - if not available natively will be assembled
1132 // using the primitives from above
1135 // adds a quadratic Bezier curve from the current point, using a control point and an end point
1136 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
1138 // appends a rectangle as a new closed subpath
1139 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1141 // appends a circle as a new closed subpath
1142 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
1144 // appends an ellipsis as a new closed subpath fitting the passed rectangle
1145 virtual void AddEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1147 // 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)
1148 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
1150 // adds another path
1151 virtual void AddPath( const wxGraphicsPathData
* path
);
1153 // returns the native path
1154 virtual void * GetNativePath() const { return m_path
; }
1156 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
1157 virtual void UnGetNativePath(void *WXUNUSED(p
)) const {}
1159 // transforms each point of this path by the matrix
1160 virtual void Transform( const wxGraphicsMatrixData
* matrix
);
1162 // gets the bounding box enclosing all points (possibly including control points)
1163 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*y
) const;
1165 virtual bool Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) const;
1167 CGMutablePathRef m_path
;
1170 //-----------------------------------------------------------------------------
1171 // wxMacCoreGraphicsPath implementation
1172 //-----------------------------------------------------------------------------
1174 wxMacCoreGraphicsPathData::wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
) : wxGraphicsPathData(renderer
)
1179 m_path
= CGPathCreateMutable();
1182 wxMacCoreGraphicsPathData::~wxMacCoreGraphicsPathData()
1184 CGPathRelease( m_path
);
1187 wxGraphicsObjectRefData
* wxMacCoreGraphicsPathData::Clone() const
1189 wxMacCoreGraphicsPathData
* clone
= new wxMacCoreGraphicsPathData(GetRenderer(),CGPathCreateMutableCopy(m_path
));
1194 // opens (starts) a new subpath
1195 void wxMacCoreGraphicsPathData::MoveToPoint( wxDouble x1
, wxDouble y1
)
1197 CGPathMoveToPoint( m_path
, NULL
, (CGFloat
) x1
, (CGFloat
) y1
);
1200 void wxMacCoreGraphicsPathData::AddLineToPoint( wxDouble x1
, wxDouble y1
)
1202 CGPathAddLineToPoint( m_path
, NULL
, (CGFloat
) x1
, (CGFloat
) y1
);
1205 void wxMacCoreGraphicsPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1207 CGPathAddCurveToPoint( m_path
, NULL
, (CGFloat
) cx1
, (CGFloat
) cy1
, (CGFloat
) cx2
, (CGFloat
) cy2
, (CGFloat
) x
, (CGFloat
) y
);
1210 void wxMacCoreGraphicsPathData::AddQuadCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble x
, wxDouble y
)
1212 CGPathAddQuadCurveToPoint( m_path
, NULL
, (CGFloat
) cx1
, (CGFloat
) cy1
, (CGFloat
) x
, (CGFloat
) y
);
1215 void wxMacCoreGraphicsPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1217 CGRect cgRect
= { { (CGFloat
) x
, (CGFloat
) y
} , { (CGFloat
) w
, (CGFloat
) h
} };
1218 CGPathAddRect( m_path
, NULL
, cgRect
);
1221 void wxMacCoreGraphicsPathData::AddCircle( wxDouble x
, wxDouble y
, wxDouble r
)
1223 CGPathAddEllipseInRect( m_path
, NULL
, CGRectMake(x
-r
,y
-r
,2*r
,2*r
));
1226 void wxMacCoreGraphicsPathData::AddEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1228 CGPathAddEllipseInRect( m_path
, NULL
, CGRectMake(x
,y
,w
,h
));
1231 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
1232 void wxMacCoreGraphicsPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
)
1234 // inverse direction as we the 'normal' state is a y axis pointing down, ie mirrored to the standard core graphics setup
1235 CGPathAddArc( m_path
, NULL
, (CGFloat
) x
, (CGFloat
) y
, (CGFloat
) r
, (CGFloat
) startAngle
, (CGFloat
) endAngle
, !clockwise
);
1238 void wxMacCoreGraphicsPathData::AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
)
1240 CGPathAddArcToPoint( m_path
, NULL
, (CGFloat
) x1
, (CGFloat
) y1
, (CGFloat
) x2
, (CGFloat
) y2
, (CGFloat
) r
);
1243 void wxMacCoreGraphicsPathData::AddPath( const wxGraphicsPathData
* path
)
1245 CGPathAddPath( m_path
, NULL
, (CGPathRef
) path
->GetNativePath() );
1248 // closes the current subpath
1249 void wxMacCoreGraphicsPathData::CloseSubpath()
1251 CGPathCloseSubpath( m_path
);
1254 // gets the last point of the current path, (0,0) if not yet set
1255 void wxMacCoreGraphicsPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1257 CGPoint p
= CGPathGetCurrentPoint( m_path
);
1262 // transforms each point of this path by the matrix
1263 void wxMacCoreGraphicsPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1265 CGMutablePathRef p
= CGPathCreateMutable() ;
1266 CGPathAddPath( p
, (CGAffineTransform
*) matrix
->GetNativeMatrix() , m_path
);
1267 CGPathRelease( m_path
);
1271 // gets the bounding box enclosing all points (possibly including control points)
1272 void wxMacCoreGraphicsPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1274 CGRect bounds
= CGPathGetBoundingBox( m_path
) ;
1275 *x
= bounds
.origin
.x
;
1276 *y
= bounds
.origin
.y
;
1277 *w
= bounds
.size
.width
;
1278 *h
= bounds
.size
.height
;
1281 bool wxMacCoreGraphicsPathData::Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
) const
1283 return CGPathContainsPoint( m_path
, NULL
, CGPointMake((CGFloat
) x
,(CGFloat
) y
), fillStyle
== wxODDEVEN_RULE
);
1290 //-----------------------------------------------------------------------------
1291 // wxMacCoreGraphicsContext declaration
1292 //-----------------------------------------------------------------------------
1294 class WXDLLEXPORT wxMacCoreGraphicsContext
: public wxGraphicsContext
1297 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
= 0, wxDouble height
= 0 );
1299 #if wxOSX_USE_CARBON
1300 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
);
1303 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
);
1305 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
);
1307 wxMacCoreGraphicsContext();
1309 ~wxMacCoreGraphicsContext();
1313 // returns the size of the graphics context in device coordinates
1314 virtual void GetSize( wxDouble
* width
, wxDouble
* height
);
1316 virtual void StartPage( wxDouble width
, wxDouble height
);
1318 virtual void EndPage();
1320 virtual void Flush();
1322 // push the current state of the context, ie the transformation matrix on a stack
1323 virtual void PushState();
1325 // pops a stored state from the stack
1326 virtual void PopState();
1328 // clips drawings to the region
1329 virtual void Clip( const wxRegion
®ion
);
1331 // clips drawings to the rect
1332 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1334 // resets the clipping to original extent
1335 virtual void ResetClip();
1337 virtual void * GetNativeContext();
1339 virtual bool SetAntialiasMode(wxAntialiasMode antialias
);
1341 virtual bool SetCompositionMode(wxCompositionMode op
);
1343 virtual void BeginLayer(wxDouble opacity
);
1345 virtual void EndLayer();
1352 virtual void Translate( wxDouble dx
, wxDouble dy
);
1355 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
1358 virtual void Rotate( wxDouble angle
);
1360 // concatenates this transform with the current transform of this context
1361 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
1363 // sets the transform of this context
1364 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
1366 // gets the matrix of this context
1367 virtual wxGraphicsMatrix
GetTransform() const;
1369 // setting the paint
1372 // strokes along a path with the current pen
1373 virtual void StrokePath( const wxGraphicsPath
&path
);
1375 // fills a path with the current brush
1376 virtual void FillPath( const wxGraphicsPath
&path
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
1378 // draws a path by first filling and then stroking
1379 virtual void DrawPath( const wxGraphicsPath
&path
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
1381 virtual bool ShouldOffset() const
1384 if ( !m_pen
.IsNull() )
1386 penwidth
= (int)((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->GetWidth();
1387 if ( penwidth
== 0 )
1390 return ( penwidth
% 2 ) == 1;
1396 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
1397 wxDouble
*descent
, wxDouble
*externalLeading
) const;
1399 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
1405 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1407 virtual void DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1409 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1411 void SetNativeContext( CGContextRef cg
);
1413 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsContext
)
1416 bool EnsureIsValid();
1418 virtual void DoDrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
1419 virtual void DoDrawRotatedText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
);
1421 CGContextRef m_cgContext
;
1422 #if wxOSX_USE_CARBON
1423 WindowRef m_windowRef
;
1427 bool m_contextSynthesized
;
1428 CGAffineTransform m_windowTransform
;
1433 #if wxOSX_USE_COCOA_OR_CARBON
1434 wxCFRef
<HIShapeRef
> m_clipRgn
;
1438 //-----------------------------------------------------------------------------
1439 // device context implementation
1441 // more and more of the dc functionality should be implemented by calling
1442 // the appropricate wxMacCoreGraphicsContext, but we will have to do that step by step
1443 // also coordinate conversions should be moved to native matrix ops
1444 //-----------------------------------------------------------------------------
1446 // we always stock two context states, one at entry, to be able to preserve the
1447 // state we were called with, the other one after changing to HI Graphics orientation
1448 // (this one is used for getting back clippings etc)
1450 //-----------------------------------------------------------------------------
1451 // wxMacCoreGraphicsContext implementation
1452 //-----------------------------------------------------------------------------
1454 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsContext
, wxGraphicsContext
)
1456 class wxQuartzOffsetHelper
1459 wxQuartzOffsetHelper( CGContextRef cg
, bool offset
)
1465 m_userOffset
= CGContextConvertSizeToUserSpace( m_cg
, CGSizeMake( 0.5 , 0.5 ) );
1466 CGContextTranslateCTM( m_cg
, m_userOffset
.width
, m_userOffset
.height
);
1469 ~wxQuartzOffsetHelper( )
1472 CGContextTranslateCTM( m_cg
, -m_userOffset
.width
, -m_userOffset
.height
);
1475 CGSize m_userOffset
;
1480 void wxMacCoreGraphicsContext::Init()
1483 m_contextSynthesized
= false;
1486 #if wxOSX_USE_CARBON
1489 #if wxOSX_USE_COCOA_OR_IPHONE
1492 m_invisible
= false;
1495 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
, wxDouble height
) : wxGraphicsContext(renderer
)
1498 SetNativeContext(cgcontext
);
1503 #if wxOSX_USE_CARBON
1504 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
): wxGraphicsContext(renderer
)
1507 m_windowRef
= window
;
1511 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
): wxGraphicsContext(renderer
)
1515 wxSize sz
= window
->GetSize();
1519 #if wxOSX_USE_COCOA_OR_IPHONE
1520 m_view
= window
->GetHandle();
1523 if ( ! window
->GetPeer()->IsFlipped() )
1525 m_windowTransform
= CGAffineTransformMakeTranslation( 0 , m_height
);
1526 m_windowTransform
= CGAffineTransformScale( m_windowTransform
, 1 , -1 );
1531 m_windowTransform
= CGAffineTransformIdentity
;
1534 int originX
, originY
;
1535 originX
= originY
= 0;
1536 Rect bounds
= { 0,0,0,0 };
1537 m_windowRef
= (WindowRef
) window
->MacGetTopLevelWindowRef();
1538 window
->MacWindowToRootWindow( &originX
, &originY
);
1539 GetWindowBounds( m_windowRef
, kWindowContentRgn
, &bounds
);
1540 m_windowTransform
= CGAffineTransformMakeTranslation( 0 , bounds
.bottom
- bounds
.top
);
1541 m_windowTransform
= CGAffineTransformScale( m_windowTransform
, 1 , -1 );
1542 m_windowTransform
= CGAffineTransformTranslate( m_windowTransform
, originX
, originY
) ;
1546 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext(wxGraphicsRenderer
* renderer
) : wxGraphicsContext(renderer
)
1551 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext() : wxGraphicsContext(NULL
)
1554 wxLogDebug(wxT("Illegal Constructor called"));
1557 wxMacCoreGraphicsContext::~wxMacCoreGraphicsContext()
1559 SetNativeContext(NULL
);
1562 void wxMacCoreGraphicsContext::GetSize( wxDouble
* width
, wxDouble
* height
)
1569 void wxMacCoreGraphicsContext::StartPage( wxDouble width
, wxDouble height
)
1572 if ( width
!= 0 && height
!= 0)
1573 r
= CGRectMake( (CGFloat
) 0.0 , (CGFloat
) 0.0 , (CGFloat
) width
, (CGFloat
) height
);
1575 r
= CGRectMake( (CGFloat
) 0.0 , (CGFloat
) 0.0 , (CGFloat
) m_width
, (CGFloat
) m_height
);
1577 CGContextBeginPage(m_cgContext
, &r
);
1578 // CGContextTranslateCTM( m_cgContext , 0 , height == 0 ? m_height : height );
1579 // CGContextScaleCTM( m_cgContext , 1 , -1 );
1582 void wxMacCoreGraphicsContext::EndPage()
1584 CGContextEndPage(m_cgContext
);
1587 void wxMacCoreGraphicsContext::Flush()
1589 CGContextFlush(m_cgContext
);
1592 bool wxMacCoreGraphicsContext::EnsureIsValid()
1600 if ( wxOSXLockFocus(m_view
) )
1602 m_cgContext
= wxOSXGetContextFromCurrentContext();
1603 wxASSERT_MSG( m_cgContext
!= NULL
, wxT("Unable to retrieve drawing context from View"));
1610 #if wxOSX_USE_IPHONE
1611 m_cgContext
= wxOSXGetContextFromCurrentContext();
1612 if ( m_cgContext
== NULL
)
1617 #if wxOSX_USE_CARBON
1618 OSStatus status
= QDBeginCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1619 if ( status
!= noErr
)
1621 wxFAIL_MSG("Cannot nest wxDCs on the same window");
1626 CGContextSaveGState( m_cgContext
);
1627 CGContextConcatCTM( m_cgContext
, m_windowTransform
);
1628 CGContextSetTextMatrix( m_cgContext
, CGAffineTransformIdentity
);
1629 m_contextSynthesized
= true;
1630 #if wxOSX_USE_COCOA_OR_CARBON
1631 if ( m_clipRgn
.get() )
1633 // the clip region is in device coordinates, so we convert this again to user coordinates
1634 wxCFRef
<HIMutableShapeRef
> hishape( HIShapeCreateMutableCopy( m_clipRgn
) );
1635 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
,m_windowTransform
);
1636 HIShapeOffset( hishape
, -transformedOrigin
.x
, -transformedOrigin
.y
);
1637 // if the shape is empty, HIShapeReplacePathInCGContext doesn't work
1638 if ( HIShapeIsEmpty(hishape
))
1640 CGRect empty
= CGRectMake( 0,0,0,0 );
1641 CGContextClipToRect( m_cgContext
, empty
);
1645 HIShapeReplacePathInCGContext( hishape
, m_cgContext
);
1646 CGContextClip( m_cgContext
);
1650 CGContextSaveGState( m_cgContext
);
1652 #if 0 // turn on for debugging of clientdc
1653 static float color
= 0.5 ;
1654 static int channel
= 0 ;
1655 CGRect bounds
= CGRectMake(-1000,-1000,2000,2000);
1656 CGContextSetRGBFillColor( m_cgContext
, channel
== 0 ? color
: 0.5 ,
1657 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
1658 CGContextFillRect( m_cgContext
, bounds
);
1670 return m_cgContext
!= NULL
;
1673 bool wxMacCoreGraphicsContext::SetAntialiasMode(wxAntialiasMode antialias
)
1675 if (!EnsureIsValid())
1678 if (m_antialias
== antialias
)
1681 m_antialias
= antialias
;
1686 case wxANTIALIAS_DEFAULT
:
1687 antialiasMode
= true;
1689 case wxANTIALIAS_NONE
:
1690 antialiasMode
= false;
1695 CGContextSetShouldAntialias(m_cgContext
, antialiasMode
);
1699 bool wxMacCoreGraphicsContext::SetCompositionMode(wxCompositionMode op
)
1701 if (!EnsureIsValid())
1704 if ( m_composition
== op
)
1709 if (m_composition
== wxCOMPOSITION_DEST
)
1712 #if wxOSX_USE_COCOA_OR_CARBON
1713 if ( UMAGetSystemVersion() < 0x1060 )
1715 CGCompositeOperation cop
= kCGCompositeOperationSourceOver
;
1716 CGBlendMode mode
= kCGBlendModeNormal
;
1719 case wxCOMPOSITION_CLEAR
:
1720 cop
= kCGCompositeOperationClear
;
1722 case wxCOMPOSITION_SOURCE
:
1723 cop
= kCGCompositeOperationCopy
;
1725 case wxCOMPOSITION_OVER
:
1726 mode
= kCGBlendModeNormal
;
1728 case wxCOMPOSITION_IN
:
1729 cop
= kCGCompositeOperationSourceIn
;
1731 case wxCOMPOSITION_OUT
:
1732 cop
= kCGCompositeOperationSourceOut
;
1734 case wxCOMPOSITION_ATOP
:
1735 cop
= kCGCompositeOperationSourceAtop
;
1737 case wxCOMPOSITION_DEST_OVER
:
1738 cop
= kCGCompositeOperationDestinationOver
;
1740 case wxCOMPOSITION_DEST_IN
:
1741 cop
= kCGCompositeOperationDestinationIn
;
1743 case wxCOMPOSITION_DEST_OUT
:
1744 cop
= kCGCompositeOperationDestinationOut
;
1746 case wxCOMPOSITION_DEST_ATOP
:
1747 cop
= kCGCompositeOperationDestinationAtop
;
1749 case wxCOMPOSITION_XOR
:
1750 cop
= kCGCompositeOperationXOR
;
1752 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1753 case wxCOMPOSITION_ADD
:
1754 mode
= kCGBlendModePlusLighter
;
1760 if ( cop
!= kCGCompositeOperationSourceOver
)
1761 CGContextSetCompositeOperation(m_cgContext
, cop
);
1763 CGContextSetBlendMode(m_cgContext
, mode
);
1766 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1769 CGBlendMode mode
= kCGBlendModeNormal
;
1772 case wxCOMPOSITION_CLEAR
:
1773 mode
= kCGBlendModeClear
;
1775 case wxCOMPOSITION_SOURCE
:
1776 mode
= kCGBlendModeCopy
;
1778 case wxCOMPOSITION_OVER
:
1779 mode
= kCGBlendModeNormal
;
1781 case wxCOMPOSITION_IN
:
1782 mode
= kCGBlendModeSourceIn
;
1784 case wxCOMPOSITION_OUT
:
1785 mode
= kCGBlendModeSourceOut
;
1787 case wxCOMPOSITION_ATOP
:
1788 mode
= kCGBlendModeSourceAtop
;
1790 case wxCOMPOSITION_DEST_OVER
:
1791 mode
= kCGBlendModeDestinationOver
;
1793 case wxCOMPOSITION_DEST_IN
:
1794 mode
= kCGBlendModeDestinationIn
;
1796 case wxCOMPOSITION_DEST_OUT
:
1797 mode
= kCGBlendModeDestinationOut
;
1799 case wxCOMPOSITION_DEST_ATOP
:
1800 mode
= kCGBlendModeDestinationAtop
;
1802 case wxCOMPOSITION_XOR
:
1803 mode
= kCGBlendModeXOR
;
1806 case wxCOMPOSITION_ADD
:
1807 mode
= kCGBlendModePlusLighter
;
1812 CGContextSetBlendMode(m_cgContext
, mode
);
1818 void wxMacCoreGraphicsContext::BeginLayer(wxDouble opacity
)
1820 CGContextSaveGState(m_cgContext
);
1821 CGContextSetAlpha(m_cgContext
, (CGFloat
) opacity
);
1822 CGContextBeginTransparencyLayer(m_cgContext
, 0);
1825 void wxMacCoreGraphicsContext::EndLayer()
1827 CGContextEndTransparencyLayer(m_cgContext
);
1828 CGContextRestoreGState(m_cgContext
);
1831 void wxMacCoreGraphicsContext::Clip( const wxRegion
®ion
)
1833 #if wxOSX_USE_COCOA_OR_CARBON
1836 wxCFRef
<HIShapeRef
> shape
= wxCFRefFromGet(region
.GetWXHRGN());
1837 // if the shape is empty, HIShapeReplacePathInCGContext doesn't work
1838 if ( HIShapeIsEmpty(shape
))
1840 CGRect empty
= CGRectMake( 0,0,0,0 );
1841 CGContextClipToRect( m_cgContext
, empty
);
1845 HIShapeReplacePathInCGContext( shape
, m_cgContext
);
1846 CGContextClip( m_cgContext
);
1851 // this offsetting to device coords is not really correct, but since we cannot apply affine transforms
1852 // to regions we try at least to have correct translations
1853 HIMutableShapeRef mutableShape
= HIShapeCreateMutableCopy( region
.GetWXHRGN() );
1855 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
, m_windowTransform
);
1856 HIShapeOffset( mutableShape
, transformedOrigin
.x
, transformedOrigin
.y
);
1857 m_clipRgn
.reset(mutableShape
);
1860 // allow usage as measuring context
1861 // wxASSERT_MSG( m_cgContext != NULL, "Needs a valid context for clipping" );
1865 // clips drawings to the rect
1866 void wxMacCoreGraphicsContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1868 CGRect r
= CGRectMake( (CGFloat
) x
, (CGFloat
) y
, (CGFloat
) w
, (CGFloat
) h
);
1871 CGContextClipToRect( m_cgContext
, r
);
1875 #if wxOSX_USE_COCOA_OR_CARBON
1876 // the clipping itself must be stored as device coordinates, otherwise
1877 // we cannot apply it back correctly
1878 r
.origin
= CGPointApplyAffineTransform( r
.origin
, m_windowTransform
);
1879 m_clipRgn
.reset(HIShapeCreateWithRect(&r
));
1881 // allow usage as measuring context
1882 // wxFAIL_MSG( "Needs a valid context for clipping" );
1887 // resets the clipping to original extent
1888 void wxMacCoreGraphicsContext::ResetClip()
1892 // there is no way for clearing the clip, we can only revert to the stored
1893 // state, but then we have to make sure everything else is NOT restored
1894 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1895 CGContextRestoreGState( m_cgContext
);
1896 CGContextSaveGState( m_cgContext
);
1897 CGAffineTransform transformNew
= CGContextGetCTM( m_cgContext
);
1898 transformNew
= CGAffineTransformInvert( transformNew
) ;
1899 CGContextConcatCTM( m_cgContext
, transformNew
);
1900 CGContextConcatCTM( m_cgContext
, transform
);
1904 #if wxOSX_USE_COCOA_OR_CARBON
1907 // allow usage as measuring context
1908 // wxFAIL_MSG( "Needs a valid context for clipping" );
1913 void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath
&path
)
1915 if ( m_pen
.IsNull() )
1918 if (!EnsureIsValid())
1921 if (m_composition
== wxCOMPOSITION_DEST
)
1924 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1926 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1927 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1928 CGContextStrokePath( m_cgContext
);
1931 void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath
&path
, wxPolygonFillMode fillStyle
)
1933 if (!EnsureIsValid())
1936 if (m_composition
== wxCOMPOSITION_DEST
)
1939 if ( !m_brush
.IsNull() && ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1941 // when using shading, we cannot draw pen and brush at the same time
1942 // revert to the base implementation of first filling and then stroking
1943 wxGraphicsContext::DrawPath( path
, fillStyle
);
1947 CGPathDrawingMode mode
= kCGPathFill
;
1948 if ( m_brush
.IsNull() )
1950 if ( m_pen
.IsNull() )
1953 mode
= kCGPathStroke
;
1957 if ( m_pen
.IsNull() )
1959 if ( fillStyle
== wxODDEVEN_RULE
)
1960 mode
= kCGPathEOFill
;
1966 if ( fillStyle
== wxODDEVEN_RULE
)
1967 mode
= kCGPathEOFillStroke
;
1969 mode
= kCGPathFillStroke
;
1973 if ( !m_brush
.IsNull() )
1974 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1975 if ( !m_pen
.IsNull() )
1976 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1978 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1980 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1981 CGContextDrawPath( m_cgContext
, mode
);
1984 void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath
&path
, wxPolygonFillMode fillStyle
)
1986 if ( m_brush
.IsNull() )
1989 if (!EnsureIsValid())
1992 if (m_composition
== wxCOMPOSITION_DEST
)
1995 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1997 CGContextSaveGState( m_cgContext
);
1998 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1999 CGContextClip( m_cgContext
);
2000 CGContextDrawShading( m_cgContext
, ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->GetShading() );
2001 CGContextRestoreGState( m_cgContext
);
2005 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
2006 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
2007 if ( fillStyle
== wxODDEVEN_RULE
)
2008 CGContextEOFillPath( m_cgContext
);
2010 CGContextFillPath( m_cgContext
);
2014 void wxMacCoreGraphicsContext::SetNativeContext( CGContextRef cg
)
2016 // we allow either setting or clearing but not replacing
2017 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
);
2021 CGContextRestoreGState( m_cgContext
);
2022 CGContextRestoreGState( m_cgContext
);
2023 if ( m_contextSynthesized
)
2025 #if wxOSX_USE_CARBON
2026 QDEndCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
2029 wxOSXUnlockFocus(m_view
);
2033 CGContextRelease(m_cgContext
);
2038 // FIXME: This check is needed because currently we need to use a DC/GraphicsContext
2039 // in order to get font properties, like wxFont::GetPixelSize, but since we don't have
2040 // a native window attached to use, I create a wxGraphicsContext with a NULL CGContextRef
2041 // for this one operation.
2043 // When wxFont::GetPixelSize on Mac no longer needs a graphics context, this check
2047 CGContextRetain(m_cgContext
);
2048 CGContextSaveGState( m_cgContext
);
2049 CGContextSetTextMatrix( m_cgContext
, CGAffineTransformIdentity
);
2050 CGContextSaveGState( m_cgContext
);
2051 m_contextSynthesized
= false;
2055 void wxMacCoreGraphicsContext::Translate( wxDouble dx
, wxDouble dy
)
2058 CGContextTranslateCTM( m_cgContext
, (CGFloat
) dx
, (CGFloat
) dy
);
2060 m_windowTransform
= CGAffineTransformTranslate(m_windowTransform
, (CGFloat
) dx
, (CGFloat
) dy
);
2063 void wxMacCoreGraphicsContext::Scale( wxDouble xScale
, wxDouble yScale
)
2066 CGContextScaleCTM( m_cgContext
, (CGFloat
) xScale
, (CGFloat
) yScale
);
2068 m_windowTransform
= CGAffineTransformScale(m_windowTransform
, (CGFloat
) xScale
, (CGFloat
) yScale
);
2071 void wxMacCoreGraphicsContext::Rotate( wxDouble angle
)
2074 CGContextRotateCTM( m_cgContext
, (CGFloat
) angle
);
2076 m_windowTransform
= CGAffineTransformRotate(m_windowTransform
, (CGFloat
) angle
);
2079 void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
2081 wxGraphicsBitmap bitmap
= GetRenderer()->CreateBitmap(bmp
);
2082 DrawBitmap(bitmap
, x
, y
, w
, h
);
2085 void wxMacCoreGraphicsContext::DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
2087 if (!EnsureIsValid())
2090 if (m_composition
== wxCOMPOSITION_DEST
)
2094 wxMacCoreGraphicsBitmapData
* refdata
=static_cast<wxMacCoreGraphicsBitmapData
*>(bmp
.GetRefData());
2095 CGImageRef image
= refdata
->GetBitmap();
2096 CGRect r
= CGRectMake( (CGFloat
) x
, (CGFloat
) y
, (CGFloat
) w
, (CGFloat
) h
);
2097 if ( refdata
->IsMonochrome() == 1 )
2099 // is is a mask, the '1' in the mask tell where to draw the current brush
2100 if ( !m_brush
.IsNull() )
2102 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
2104 // TODO clip to mask
2106 CGContextSaveGState( m_cgContext );
2107 CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() );
2108 CGContextClip( m_cgContext );
2109 CGContextDrawShading( m_cgContext, ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->GetShading() );
2110 CGContextRestoreGState( m_cgContext);
2115 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
2116 wxMacDrawCGImage( m_cgContext
, &r
, image
);
2122 wxMacDrawCGImage( m_cgContext
, &r
, image
);
2127 void wxMacCoreGraphicsContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
2129 if (!EnsureIsValid())
2132 if (m_composition
== wxCOMPOSITION_DEST
)
2135 CGRect r
= CGRectMake( (CGFloat
) 0.0 , (CGFloat
) 0.0 , (CGFloat
) w
, (CGFloat
) h
);
2136 CGContextSaveGState( m_cgContext
);
2137 CGContextTranslateCTM( m_cgContext
,(CGFloat
) x
,(CGFloat
) (y
+ h
) );
2138 CGContextScaleCTM( m_cgContext
, 1, -1 );
2139 #if wxOSX_USE_COCOA_OR_CARBON
2140 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
2141 NULL
, kPlotIconRefNormalFlags
, icon
.GetHICON() );
2143 CGContextRestoreGState( m_cgContext
);
2146 void wxMacCoreGraphicsContext::PushState()
2148 if (!EnsureIsValid())
2151 CGContextSaveGState( m_cgContext
);
2154 void wxMacCoreGraphicsContext::PopState()
2156 if (!EnsureIsValid())
2159 CGContextRestoreGState( m_cgContext
);
2162 void wxMacCoreGraphicsContext::DoDrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
2164 wxCHECK_RET( !m_font
.IsNull(), wxT("wxMacCoreGraphicsContext::DrawText - no valid font set") );
2166 if (!EnsureIsValid())
2169 if (m_composition
== wxCOMPOSITION_DEST
)
2172 #if wxOSX_USE_CORE_TEXT
2173 if ( UMAGetSystemVersion() >= 0x1050 )
2175 wxMacCoreGraphicsFontData
* fref
= (wxMacCoreGraphicsFontData
*)m_font
.GetRefData();
2176 wxCFStringRef
text(str
, wxLocale::GetSystemEncoding() );
2177 CTFontRef font
= fref
->OSXGetCTFont();
2178 CGColorRef col
= wxMacCreateCGColor( fref
->GetColour() );
2179 CTUnderlineStyle ustyle
= fref
->GetUnderlined() ? kCTUnderlineStyleSingle
: kCTUnderlineStyleNone
;
2180 wxCFRef
<CFNumberRef
> underlined( CFNumberCreate(NULL
, kCFNumberSInt32Type
, &ustyle
) );
2181 CFStringRef keys
[] = { kCTFontAttributeName
, kCTForegroundColorAttributeName
, kCTUnderlineStyleAttributeName
};
2182 CFTypeRef values
[] = { font
, col
, underlined
};
2183 wxCFRef
<CFDictionaryRef
> attributes( CFDictionaryCreate(kCFAllocatorDefault
, (const void**) &keys
, (const void**) &values
,
2184 WXSIZEOF( keys
), &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
) );
2185 wxCFRef
<CFAttributedStringRef
> attrtext( CFAttributedStringCreate(kCFAllocatorDefault
, text
, attributes
) );
2186 wxCFRef
<CTLineRef
> line( CTLineCreateWithAttributedString(attrtext
) );
2188 y
+= CTFontGetAscent(font
);
2190 CGContextSaveGState(m_cgContext
);
2191 CGContextTranslateCTM(m_cgContext
, (CGFloat
) x
, (CGFloat
) y
);
2192 CGContextScaleCTM(m_cgContext
, 1, -1);
2193 CGContextSetTextPosition(m_cgContext
, 0, 0);
2194 CTLineDraw( line
, m_cgContext
);
2195 CGContextRestoreGState(m_cgContext
);
2200 #if wxOSX_USE_ATSU_TEXT
2202 DrawText(str
, x
, y
, 0.0);
2206 #if wxOSX_USE_IPHONE
2207 wxMacCoreGraphicsFontData
* fref
= (wxMacCoreGraphicsFontData
*)m_font
.GetRefData();
2209 CGContextSaveGState(m_cgContext
);
2211 CGColorRef col
= wxMacCreateCGColor( fref
->GetColour() );
2212 CGContextSetTextDrawingMode (m_cgContext
, kCGTextFill
);
2213 CGContextSetFillColorWithColor( m_cgContext
, col
);
2215 wxCFStringRef
text(str
, wxLocale::GetSystemEncoding() );
2216 DrawTextInContext( m_cgContext
, CGPointMake( x
, y
), fref
->GetUIFont() , text
.AsNSString() );
2218 CGContextRestoreGState(m_cgContext
);
2223 void wxMacCoreGraphicsContext::DoDrawRotatedText(const wxString
&str
,
2224 wxDouble x
, wxDouble y
,
2227 wxCHECK_RET( !m_font
.IsNull(), wxT("wxMacCoreGraphicsContext::DrawText - no valid font set") );
2229 if (!EnsureIsValid())
2232 if (m_composition
== wxCOMPOSITION_DEST
)
2235 #if wxOSX_USE_CORE_TEXT
2236 if ( UMAGetSystemVersion() >= 0x1050 )
2238 // default implementation takes care of rotation and calls non rotated DrawText afterwards
2239 wxGraphicsContext::DoDrawRotatedText( str
, x
, y
, angle
);
2243 #if wxOSX_USE_ATSU_TEXT
2245 OSStatus status
= noErr
;
2246 ATSUTextLayout atsuLayout
;
2247 wxMacUniCharBuffer
unibuf( str
);
2248 UniCharCount chars
= unibuf
.GetChars();
2250 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
2251 status
= ::ATSUCreateTextLayoutWithTextPtr( unibuf
.GetBuffer() , 0 , chars
, chars
, 1 ,
2252 &chars
, &style
, &atsuLayout
);
2254 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
2256 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true );
2257 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
2259 int iAngle
= int( angle
* RAD2DEG
);
2260 if ( abs(iAngle
) > 0 )
2262 Fixed atsuAngle
= IntToFixed( iAngle
);
2263 ATSUAttributeTag atsuTags
[] =
2265 kATSULineRotationTag
,
2267 ByteCount atsuSizes
[WXSIZEOF(atsuTags
)] =
2271 ATSUAttributeValuePtr atsuValues
[WXSIZEOF(atsuTags
)] =
2275 status
= ::ATSUSetLayoutControls(atsuLayout
, WXSIZEOF(atsuTags
),
2276 atsuTags
, atsuSizes
, atsuValues
);
2280 ATSUAttributeTag atsuTags
[] =
2284 ByteCount atsuSizes
[WXSIZEOF(atsuTags
)] =
2286 sizeof( CGContextRef
) ,
2288 ATSUAttributeValuePtr atsuValues
[WXSIZEOF(atsuTags
)] =
2292 status
= ::ATSUSetLayoutControls(atsuLayout
, WXSIZEOF(atsuTags
),
2293 atsuTags
, atsuSizes
, atsuValues
);
2296 ATSUTextMeasurement textBefore
, textAfter
;
2297 ATSUTextMeasurement ascent
, descent
;
2299 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
2300 &textBefore
, &textAfter
, &ascent
, &descent
);
2302 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
2305 x
+= (int)(sin(angle
) * FixedToInt(ascent
));
2306 y
+= (int)(cos(angle
) * FixedToInt(ascent
));
2308 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
2309 IntToFixed(x
) , IntToFixed(y
) , &rect
);
2310 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
2312 CGContextSaveGState(m_cgContext
);
2313 CGContextTranslateCTM(m_cgContext
, (CGFloat
) x
, (CGFloat
) y
);
2314 CGContextScaleCTM(m_cgContext
, 1, -1);
2315 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
2316 IntToFixed(0) , IntToFixed(0) );
2318 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
2320 CGContextRestoreGState(m_cgContext
);
2322 ::ATSUDisposeTextLayout(atsuLayout
);
2327 #if wxOSX_USE_IPHONE
2328 // default implementation takes care of rotation and calls non rotated DrawText afterwards
2329 wxGraphicsContext::DoDrawRotatedText( str
, x
, y
, angle
);
2333 void wxMacCoreGraphicsContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
2334 wxDouble
*descent
, wxDouble
*externalLeading
) const
2336 wxCHECK_RET( !m_font
.IsNull(), wxT("wxMacCoreGraphicsContext::GetTextExtent - no valid font set") );
2344 if ( externalLeading
)
2345 *externalLeading
= 0;
2350 #if wxOSX_USE_CORE_TEXT
2351 if ( UMAGetSystemVersion() >= 0x1050 )
2353 wxMacCoreGraphicsFontData
* fref
= (wxMacCoreGraphicsFontData
*)m_font
.GetRefData();
2354 CTFontRef font
= fref
->OSXGetCTFont();
2356 wxCFStringRef
text(str
, wxLocale::GetSystemEncoding() );
2357 CFStringRef keys
[] = { kCTFontAttributeName
};
2358 CFTypeRef values
[] = { font
};
2359 wxCFRef
<CFDictionaryRef
> attributes( CFDictionaryCreate(kCFAllocatorDefault
, (const void**) &keys
, (const void**) &values
,
2360 WXSIZEOF( keys
), &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
) );
2361 wxCFRef
<CFAttributedStringRef
> attrtext( CFAttributedStringCreate(kCFAllocatorDefault
, text
, attributes
) );
2362 wxCFRef
<CTLineRef
> line( CTLineCreateWithAttributedString(attrtext
) );
2364 // round the returned extent: this is probably more correct anyhow but
2365 // we also need to do it to be consistent with GetPartialTextExtents()
2366 // below and avoid strange situation when the last partial extent
2367 // returned by it could have been greater than the full extent returned
2370 int w
= CTLineGetTypographicBounds(line
, &a
, &d
, &l
) + 0.5;
2376 if ( externalLeading
)
2377 *externalLeading
= l
;
2383 #if wxOSX_USE_ATSU_TEXT
2385 OSStatus status
= noErr
;
2387 ATSUTextLayout atsuLayout
;
2388 wxMacUniCharBuffer
unibuf( str
);
2389 UniCharCount chars
= unibuf
.GetChars();
2391 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
2392 status
= ::ATSUCreateTextLayoutWithTextPtr( unibuf
.GetBuffer() , 0 , chars
, chars
, 1 ,
2393 &chars
, &style
, &atsuLayout
);
2395 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
2397 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true );
2398 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
2400 ATSUTextMeasurement textBefore
, textAfter
;
2401 ATSUTextMeasurement textAscent
, textDescent
;
2403 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
2404 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
2407 *height
= FixedToInt(textAscent
+ textDescent
);
2409 *descent
= FixedToInt(textDescent
);
2410 if ( externalLeading
)
2411 *externalLeading
= 0;
2413 *width
= FixedToInt(textAfter
- textBefore
);
2415 ::ATSUDisposeTextLayout(atsuLayout
);
2420 #if wxOSX_USE_IPHONE
2421 wxMacCoreGraphicsFontData
* fref
= (wxMacCoreGraphicsFontData
*)m_font
.GetRefData();
2423 wxCFStringRef
text(str
, wxLocale::GetSystemEncoding() );
2424 CGSize sz
= MeasureTextInContext( fref
->GetUIFont() , text
.AsNSString() );
2427 *height
= sz
.height
;
2430 *descent = FixedToInt(textDescent);
2431 if ( externalLeading )
2432 *externalLeading = 0;
2439 void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
2442 widths
.Add(0, text
.length());
2444 wxCHECK_RET( !m_font
.IsNull(), wxT("wxMacCoreGraphicsContext::DrawText - no valid font set") );
2449 #if wxOSX_USE_CORE_TEXT
2451 wxMacCoreGraphicsFontData
* fref
= (wxMacCoreGraphicsFontData
*)m_font
.GetRefData();
2452 CTFontRef font
= fref
->OSXGetCTFont();
2454 wxCFStringRef
t(text
, wxLocale::GetSystemEncoding() );
2455 CFStringRef keys
[] = { kCTFontAttributeName
};
2456 CFTypeRef values
[] = { font
};
2457 wxCFRef
<CFDictionaryRef
> attributes( CFDictionaryCreate(kCFAllocatorDefault
, (const void**) &keys
, (const void**) &values
,
2458 WXSIZEOF( keys
), &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
) );
2459 wxCFRef
<CFAttributedStringRef
> attrtext( CFAttributedStringCreate(kCFAllocatorDefault
, t
, attributes
) );
2460 wxCFRef
<CTLineRef
> line( CTLineCreateWithAttributedString(attrtext
) );
2462 int chars
= text
.length();
2463 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
2465 widths
[pos
] = CTLineGetOffsetForStringIndex( line
, pos
+1 , NULL
);
2471 #if wxOSX_USE_ATSU_TEXT
2473 OSStatus status
= noErr
;
2474 ATSUTextLayout atsuLayout
;
2475 wxMacUniCharBuffer
unibuf( text
);
2476 UniCharCount chars
= unibuf
.GetChars();
2478 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
2479 status
= ::ATSUCreateTextLayoutWithTextPtr( unibuf
.GetBuffer() , 0 , chars
, chars
, 1 ,
2480 &chars
, &style
, &atsuLayout
);
2482 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
2484 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true );
2485 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
2487 // new implementation from JS, keep old one just in case
2489 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
2491 unsigned long actualNumberOfBounds
= 0;
2492 ATSTrapezoid glyphBounds
;
2494 // We get a single bound, since the text should only require one. If it requires more, there is an issue
2496 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
2497 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
2498 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
2501 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
2502 //unsigned char uch = s[i];
2505 ATSLayoutRecord
*layoutRecords
= NULL
;
2506 ItemCount glyphCount
= 0;
2508 // Get the glyph extents
2509 OSStatus err
= ::ATSUDirectGetLayoutDataArrayPtrFromTextLayout(atsuLayout
,
2511 kATSUDirectDataLayoutRecordATSLayoutRecordCurrent
,
2515 wxASSERT(glyphCount
== (text
.length()+1));
2517 if ( err
== noErr
&& glyphCount
== (text
.length()+1))
2519 for ( int pos
= 1; pos
< (int)glyphCount
; pos
++ )
2521 widths
[pos
-1] = FixedToInt( layoutRecords
[pos
].realPos
);
2525 ::ATSUDirectReleaseLayoutDataArrayPtr(NULL
,
2526 kATSUDirectDataLayoutRecordATSLayoutRecordCurrent
,
2527 (void **) &layoutRecords
);
2529 ::ATSUDisposeTextLayout(atsuLayout
);
2532 #if wxOSX_USE_IPHONE
2533 // TODO core graphics text implementation here
2537 void * wxMacCoreGraphicsContext::GetNativeContext()
2542 // concatenates this transform with the current transform of this context
2543 void wxMacCoreGraphicsContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
2546 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2548 m_windowTransform
= CGAffineTransformConcat(m_windowTransform
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2551 // sets the transform of this context
2552 void wxMacCoreGraphicsContext::SetTransform( const wxGraphicsMatrix
& matrix
)
2556 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
2557 transform
= CGAffineTransformInvert( transform
) ;
2558 CGContextConcatCTM( m_cgContext
, transform
);
2559 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2563 m_windowTransform
= *(CGAffineTransform
*) matrix
.GetNativeMatrix();
2567 // gets the matrix of this context
2568 wxGraphicsMatrix
wxMacCoreGraphicsContext::GetTransform() const
2570 wxGraphicsMatrix m
= CreateMatrix();
2571 *((CGAffineTransform
*) m
.GetNativeMatrix()) = ( m_cgContext
== NULL
? m_windowTransform
:
2572 CGContextGetCTM( m_cgContext
));
2580 //-----------------------------------------------------------------------------
2581 // wxMacCoreGraphicsRenderer declaration
2582 //-----------------------------------------------------------------------------
2584 class WXDLLIMPEXP_CORE wxMacCoreGraphicsRenderer
: public wxGraphicsRenderer
2587 wxMacCoreGraphicsRenderer() {}
2589 virtual ~wxMacCoreGraphicsRenderer() {}
2593 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
2594 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
);
2595 #if wxUSE_PRINTING_ARCHITECTURE
2596 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
);
2599 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
2601 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
2603 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
2605 virtual wxGraphicsContext
* CreateMeasuringContext();
2609 virtual wxGraphicsPath
CreatePath();
2613 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
2614 wxDouble tx
=0.0, wxDouble ty
=0.0);
2617 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
2619 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
2621 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2622 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2623 const wxColour
&c1
, const wxColour
&c2
) ;
2625 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2626 // with radius r and color cColor
2627 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2628 const wxColour
&oColor
, const wxColour
&cColor
) ;
2631 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
2633 // create a native bitmap representation
2634 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) ;
2636 // create a graphics bitmap from a native bitmap
2637 virtual wxGraphicsBitmap
CreateBitmapFromNativeBitmap( void* bitmap
);
2639 // create a native bitmap representation
2640 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) ;
2642 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsRenderer
)
2645 //-----------------------------------------------------------------------------
2646 // wxMacCoreGraphicsRenderer implementation
2647 //-----------------------------------------------------------------------------
2649 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsRenderer
,wxGraphicsRenderer
)
2651 static wxMacCoreGraphicsRenderer gs_MacCoreGraphicsRenderer
;
2653 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
2655 return &gs_MacCoreGraphicsRenderer
;
2658 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( const wxWindowDC
& dc
)
2660 const wxDCImpl
* impl
= dc
.GetImpl();
2661 wxWindowDCImpl
*win_impl
= wxDynamicCast( impl
, wxWindowDCImpl
);
2665 win_impl
->GetSize( &w
, &h
);
2666 CGContextRef cgctx
= 0;
2668 wxASSERT_MSG(win_impl
->GetWindow(), "Invalid wxWindow in wxMacCoreGraphicsRenderer::CreateContext");
2669 if (win_impl
->GetWindow())
2670 cgctx
= (CGContextRef
)(win_impl
->GetWindow()->MacGetCGContextRef());
2673 return new wxMacCoreGraphicsContext( this, cgctx
, (wxDouble
) w
, (wxDouble
) h
);
2678 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( const wxMemoryDC
& dc
)
2681 const wxDCImpl
* impl
= dc
.GetImpl();
2682 wxMemoryDCImpl
*mem_impl
= wxDynamicCast( impl
, wxMemoryDCImpl
);
2686 mem_impl
->GetSize( &w
, &h
);
2687 return new wxMacCoreGraphicsContext( this,
2688 (CGContextRef
)(mem_impl
->GetGraphicsContext()->GetNativeContext()), (wxDouble
) w
, (wxDouble
) h
);
2694 #if wxUSE_PRINTING_ARCHITECTURE
2695 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( const wxPrinterDC
& dc
)
2698 const wxDCImpl
* impl
= dc
.GetImpl();
2699 wxPrinterDCImpl
*print_impl
= wxDynamicCast( impl
, wxPrinterDCImpl
);
2703 print_impl
->GetSize( &w
, &h
);
2704 return new wxMacCoreGraphicsContext( this,
2705 (CGContextRef
)(print_impl
->GetGraphicsContext()->GetNativeContext()), (wxDouble
) w
, (wxDouble
) h
);
2712 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeContext( void * context
)
2714 return new wxMacCoreGraphicsContext(this,(CGContextRef
)context
);
2717 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeWindow( void * window
)
2719 #if wxOSX_USE_CARBON
2720 return new wxMacCoreGraphicsContext(this,(WindowRef
)window
);
2722 wxUnusedVar(window
);
2727 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( wxWindow
* window
)
2729 return new wxMacCoreGraphicsContext(this, window
);
2732 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateMeasuringContext()
2734 return new wxMacCoreGraphicsContext(this);
2739 wxGraphicsPath
wxMacCoreGraphicsRenderer::CreatePath()
2742 m
.SetRefData( new wxMacCoreGraphicsPathData(this));
2749 wxGraphicsMatrix
wxMacCoreGraphicsRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2750 wxDouble tx
, wxDouble ty
)
2753 wxMacCoreGraphicsMatrixData
* data
= new wxMacCoreGraphicsMatrixData( this );
2754 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2759 wxGraphicsPen
wxMacCoreGraphicsRenderer::CreatePen(const wxPen
& pen
)
2761 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
2762 return wxNullGraphicsPen
;
2766 p
.SetRefData(new wxMacCoreGraphicsPenData( this, pen
));
2771 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateBrush(const wxBrush
& brush
)
2773 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
2774 return wxNullGraphicsBrush
;
2778 p
.SetRefData(new wxMacCoreGraphicsBrushData( this, brush
));
2783 wxGraphicsBitmap
wxMacCoreGraphicsRenderer::CreateBitmap( const wxBitmap
& bmp
)
2788 p
.SetRefData(new wxMacCoreGraphicsBitmapData( this , bmp
.CreateCGImage(), bmp
.GetDepth() == 1 ) );
2792 return wxNullGraphicsBitmap
;
2795 wxGraphicsBitmap
wxMacCoreGraphicsRenderer::CreateBitmapFromNativeBitmap( void* bitmap
)
2797 if ( bitmap
!= NULL
)
2800 p
.SetRefData(new wxMacCoreGraphicsBitmapData( this , (CGImageRef
) bitmap
, false ));
2804 return wxNullGraphicsBitmap
;
2807 wxGraphicsBitmap
wxMacCoreGraphicsRenderer::CreateSubBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
2809 wxMacCoreGraphicsBitmapData
* refdata
=static_cast<wxMacCoreGraphicsBitmapData
*>(bmp
.GetRefData());
2810 CGImageRef img
= refdata
->GetBitmap();
2814 CGImageRef subimg
= CGImageCreateWithImageInRect(img
,CGRectMake( (CGFloat
) x
, (CGFloat
) y
, (CGFloat
) w
, (CGFloat
) h
));
2815 p
.SetRefData(new wxMacCoreGraphicsBitmapData( this , subimg
, refdata
->IsMonochrome() ) );
2819 return wxNullGraphicsBitmap
;
2822 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2823 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2824 const wxColour
&c1
, const wxColour
&c2
)
2827 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2828 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
2833 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2834 // with radius r and color cColor
2835 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2836 const wxColour
&oColor
, const wxColour
&cColor
)
2839 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2840 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
2846 wxGraphicsFont
wxMacCoreGraphicsRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
2851 p
.SetRefData(new wxMacCoreGraphicsFontData( this , font
, col
));
2855 return wxNullGraphicsFont
;
2859 // CoreGraphics Helper Methods
2862 // Data Providers and Consumers
2864 size_t UMAPutBytesCFRefCallback( void *info
, const void *bytes
, size_t count
)
2866 CFMutableDataRef data
= (CFMutableDataRef
) info
;
2869 CFDataAppendBytes( data
, (const UInt8
*) bytes
, count
);
2874 void wxMacReleaseCFDataProviderCallback(void *info
,
2875 const void *WXUNUSED(data
),
2876 size_t WXUNUSED(count
))
2879 CFRelease( (CFDataRef
) info
);
2882 void wxMacReleaseCFDataConsumerCallback( void *info
)
2885 CFRelease( (CFDataRef
) info
);
2888 CGDataProviderRef
wxMacCGDataProviderCreateWithCFData( CFDataRef data
)
2893 return CGDataProviderCreateWithCFData( data
);
2896 CGDataConsumerRef
wxMacCGDataConsumerCreateWithCFData( CFMutableDataRef data
)
2901 return CGDataConsumerCreateWithCFData( data
);
2905 wxMacReleaseMemoryBufferProviderCallback(void *info
,
2906 const void * WXUNUSED_UNLESS_DEBUG(data
),
2907 size_t WXUNUSED(size
))
2909 wxMemoryBuffer
* membuf
= (wxMemoryBuffer
*) info
;
2911 wxASSERT( data
== membuf
->GetData() ) ;
2916 CGDataProviderRef
wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffer
& buf
)
2918 wxMemoryBuffer
* b
= new wxMemoryBuffer( buf
);
2919 if ( b
->GetDataLen() == 0 )
2922 return CGDataProviderCreateWithData( b
, (const void *) b
->GetData() , b
->GetDataLen() ,
2923 wxMacReleaseMemoryBufferProviderCallback
);