]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/core/strconv_cf.cpp
Applied Blit system options optimization to StretchBlit
[wxWidgets.git] / src / osx / core / strconv_cf.cpp
index aba24024113a9daba1f4ee588dcd3fac58031de6..f4bd30f334d036910551af628fd152c920d66b3a 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        src/osx/corefoundation/strconv.cpp
+// Name:        src/osx/core/strconv_cf.cpp
 // Purpose:     Unicode conversion classes
 // Author:      David Elliott
 // Modified by:
@@ -90,6 +90,14 @@ WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_cf(wxFontEncoding encoding)
         if ( theString == NULL )
             return wxCONV_FAILED;
 
+        // Ensure that the string is in canonical composed form (NFC): this is
+        // important because Darwin uses decomposed form (NFD) for e.g. file
+        // names but we want to use NFC internally.
+        wxCFRef<CFMutableStringRef>
+            cfMutableString(CFStringCreateMutableCopy(NULL, 0, theString));
+        CFStringNormalize(cfMutableString, kCFStringNormalizationFormC);
+        theString = cfMutableString;
+
         /* NOTE: The string content includes the NULL element if the source string did
          * That means we have to do nothing special because the destination will have
          * the NULL element iff the source did and the NULL element will be included
@@ -212,13 +220,15 @@ WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_cf(wxFontEncoding encoding)
                 m_encoding,
                 0, // FAIL on unconvertible characters
                 false, // not an external representation
-                // if dstSize is 0 then pass NULL to get required length in usedBufLen
-                (dstSize != 0)?(UInt8*)dst:NULL,
+                (UInt8*)dst,
                 dstSize,
                 &usedBufLen
             );
 
-        if(charsConverted < CFStringGetLength(theString) )
+        // when dst is non-NULL, we check usedBufLen against dstSize as
+        // CFStringGetBytes sometimes treats dst as being NULL when dstSize==0
+        if( (charsConverted < CFStringGetLength(theString)) ||
+                (dst && (size_t) usedBufLen > dstSize) )
             return wxCONV_FAILED;
 
         return usedBufLen;