]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/graphics.cpp
fixing memory leaks on three levels (bug report 1905138)
[wxWidgets.git] / src / mac / carbon / graphics.cpp
index 80e114ea8bb3ab66784caba165e2a7aa291e5219..e5567b5f8da35fe4d74a7d5a82fece06bce0487b 100644 (file)
@@ -23,6 +23,7 @@
     #include "wx/icon.h"
 #endif
 
+
 #ifdef __MSL__
     #if __MSL__ >= 0x6000
         #include "math.h"
@@ -34,6 +35,7 @@
 
 #ifdef __WXMAC__
     #include "wx/mac/uma.h"
+    #include "wx/mac/dcprint.h"
 #else
     #include "CoreServices/CoreServices.h"
     #include "ApplicationServices/ApplicationServices.h"
@@ -2151,6 +2153,8 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr
         status = ::ATSUSetTransientFontMatching( atsuLayout , true );
         wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
 
+// new implementation from JS, keep old one just in case
+#if 0
         for ( int pos = 0; pos < (int)chars; pos ++ )
         {
             unsigned long actualNumberOfBounds = 0;
@@ -2166,7 +2170,31 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr
             widths[pos] = FixedToInt( glyphBounds.upperRight.x - glyphBounds.upperLeft.x );
             //unsigned char uch = s[i];
         }
-
+#else
+        ATSLayoutRecord *layoutRecords = NULL;
+        ItemCount glyphCount = 0;
+        
+        // Get the glyph extents
+        OSStatus err = ::ATSUDirectGetLayoutDataArrayPtrFromTextLayout(atsuLayout,
+                                                                       0,
+                                                                       kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
+                                                                       (void **)
+                                                                       &layoutRecords,
+                                                                       &glyphCount);
+        wxASSERT(glyphCount == (text.length()+1));
+        
+        if ( err == noErr && glyphCount == (text.length()+1))
+        {
+            for ( int pos = 1; pos < (int)glyphCount ; pos ++ )
+            {
+                widths[pos-1] = FixedToInt( layoutRecords[pos].realPos );
+            }
+        }
+        
+        ::ATSUDirectReleaseLayoutDataArrayPtr(NULL,
+                                              kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
+                                              (void **) &layoutRecords);
+#endif
         ::ATSUDisposeTextLayout(atsuLayout);
     }
 #endif
@@ -2233,6 +2261,7 @@ public :
 
     virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc);
     virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc);
+    virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc);
 
     virtual wxGraphicsContext * CreateContextFromNativeContext( void * context );
 
@@ -2329,6 +2358,22 @@ wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( const wxMemoryDC&
     return NULL;
 }
 
+wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( const wxPrinterDC& dc )
+{
+#ifdef __WXMAC__
+    const wxDCImpl* impl = dc.GetImpl();
+    wxPrinterDCImpl *print_impl = wxDynamicCast( impl, wxPrinterDCImpl );
+    if (print_impl)
+    {
+        int w, h;
+        print_impl->GetSize( &w, &h );
+        return new wxMacCoreGraphicsContext( this,
+            (CGContextRef)(print_impl->GetGraphicsContext()->GetNativeContext()), (wxDouble) w, (wxDouble) h );
+    }
+#endif
+    return NULL;
+}
+
 wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContextFromNativeContext( void * context )
 {
     return new wxMacCoreGraphicsContext(this,(CGContextRef)context);