]> git.saurik.com Git - wxWidgets.git/commitdiff
adapted Julian's new speed improved version
authorStefan Csomor <csomor@advancedconcepts.ch>
Mon, 28 Apr 2008 12:57:00 +0000 (12:57 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Mon, 28 Apr 2008 12:57:00 +0000 (12:57 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53399 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/graphics.cpp

index 80e114ea8bb3ab66784caba165e2a7aa291e5219..b7a64d5726a5a85e2c2648e33b828f740939de9a 100644 (file)
@@ -2151,6 +2151,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 +2168,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