// Author: Stefan Csomor
// Modified by:
// Created: 01/02/97
-// RCS-ID: $Id$
// copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
CGColorRef wxMacCreateCGColor( const wxColour& col )
{
- CGColorRef retval = 0;
-
- retval = col.CreateCGColor();
+ CGColorRef retval = col.CreateCGColor();
wxASSERT(retval != NULL);
return retval;
// fast convenience methods
- virtual void DrawRectangleX( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
+ virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
void SetNativeContext( CGContextRef cg );
mode = kCGBlendModeDestinationAtop;
break;
case wxCOMPOSITION_XOR:
- mode = kCGBlendModeXOR;
+ mode = kCGBlendModeExclusion; // Not kCGBlendModeXOR!
break;
case wxCOMPOSITION_ADD:
if ( externalLeading )
*externalLeading = 0;
+ // In wxWidgets (MSW-inspired) API it is possible to call GetTextExtent()
+ // with an empty string to get just the descent and the leading of the
+ // font, so support this (mis)use.
+ wxString strToMeasure(str);
if (str.empty())
- return;
+ strToMeasure = wxS(" ");
#if wxOSX_USE_CORE_TEXT
{
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
CTFontRef font = fref->OSXGetCTFont();
- wxCFStringRef text(str, wxLocale::GetSystemEncoding() );
+ wxCFStringRef text(strToMeasure, wxLocale::GetSystemEncoding() );
CFStringRef keys[] = { kCTFontAttributeName };
CFTypeRef values[] = { font };
wxCFRef<CFDictionaryRef> attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values,
CGFloat a, d, l, w;
w = CTLineGetTypographicBounds(line, &a, &d, &l);
- if ( height )
- *height = a+d+l;
+ if ( !str.empty() )
+ {
+ if ( width )
+ *width = w;
+ if ( height )
+ *height = a+d+l;
+ }
+
if ( descent )
*descent = d;
if ( externalLeading )
*externalLeading = l;
- if ( width )
- *width = w;
return;
}
#endif
OSStatus status = noErr;
ATSUTextLayout atsuLayout;
- wxMacUniCharBuffer unibuf( str );
+ wxMacUniCharBuffer unibuf( strToMeasure );
UniCharCount chars = unibuf.GetChars();
ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle());
status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
&textBefore , &textAfter, &textAscent , &textDescent );
- if ( height )
- *height = FixedToFloat(textAscent + textDescent);
+ if ( !str.empty() )
+ {
+ if ( width )
+ *width = FixedToFloat(textAfter - textBefore);
+ if ( height )
+ *height = FixedToFloat(textAscent + textDescent);
+ }
+
if ( descent )
*descent = FixedToFloat(textDescent);
if ( externalLeading )
*externalLeading = 0;
- if ( width )
- *width = FixedToFloat(textAfter - textBefore);
::ATSUDisposeTextLayout(atsuLayout);
#if wxOSX_USE_IPHONE
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
- wxCFStringRef text(str, wxLocale::GetSystemEncoding() );
+ wxCFStringRef text(strToMeasure, wxLocale::GetSystemEncoding() );
CGSize sz = MeasureTextInContext( fref->GetUIFont() , text.AsNSString() );
- if ( height )
- *height = sz.height;
+ if ( !str.empty() )
+ {
+ if ( width )
+ *width = sz.width;
+ if ( height )
+ *height = sz.height;
+ }
+
/*
if ( descent )
*descent = FixedToFloat(textDescent);
if ( externalLeading )
*externalLeading = 0;
*/
- if ( width )
- *width = sz.width;
#endif
CheckInvariants();
}
-void wxMacCoreGraphicsContext::DrawRectangleX( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+void wxMacCoreGraphicsContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
{
+ if (!EnsureIsValid())
+ return;
+
if (m_composition == wxCOMPOSITION_DEST)
return;
+ // when using shading, we have to go back to drawing paths
+ if ( !m_brush.IsNull() && ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->IsShading() )
+ {
+ wxGraphicsContext::DrawRectangle( x,y,w,h );
+ return;
+ }
+
CGRect rect = CGRectMake( (CGFloat) x , (CGFloat) y , (CGFloat) w , (CGFloat) h );
if ( !m_brush.IsNull() )
{