Author: fredkiefer
Date: Fri Mar 31 23:49:09 2017
New Revision: 40430

URL: http://svn.gna.org/viewcvs/gnustep?rev=40430&view=rev
Log:
2017-03-31 Fred Kiefer <fredkie...@gmx.de>

        * Source/NSAttributedString.m: Check for surrogate UTF16
        characters to prevent nil strings when trying to attempt fonst
        substitution.

Modified:
    libs/gui/trunk/ChangeLog
    libs/gui/trunk/Source/NSAttributedString.m

Modified: libs/gui/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=40430&r1=40429&r2=40430&view=diff
==============================================================================
--- libs/gui/trunk/ChangeLog    (original)
+++ libs/gui/trunk/ChangeLog    Fri Mar 31 23:49:09 2017
@@ -1,3 +1,9 @@
+2017-03-31 Fred Kiefer <fredkie...@gmx.de>
+
+       * Source/NSAttributedString.m: Check for surrogate UTF16
+       characters to prevent nil strings when trying to attempt fonst
+       substitution.
+
 2017-03-31 Riccardo Mottola <r...@gnu.org>
 
        * Source/NSBitmapImageRep+JPEG.m (-_initBitmapFromJPEG:errorMessage:)

Modified: libs/gui/trunk/Source/NSAttributedString.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSAttributedString.m?rev=40430&r1=40429&r2=40430&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSAttributedString.m  (original)
+++ libs/gui/trunk/Source/NSAttributedString.m  Fri Mar 31 23:49:09 2017
@@ -1524,11 +1524,20 @@
 - (NSFontDescriptor*)_substituteFontDescriptorFor: (unichar)uchar
 {
   NSString *chars = [NSString stringWithCharacters: &uchar length: 1];
-  NSCharacterSet *requiredCharacterSet = [NSCharacterSet 
characterSetWithCharactersInString: chars];
-  NSDictionary *fontAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
requiredCharacterSet, NSFontCharacterSetAttribute, nil];
-  NSSet *mandatoryKeys = [NSSet setWithObjects: NSFontCharacterSetAttribute, 
nil];
-  NSFontDescriptor *fd = [NSFontDescriptor fontDescriptorWithFontAttributes: 
fontAttributes];
-  return [fd matchingFontDescriptorWithMandatoryKeys: mandatoryKeys];
+
+  // If we cannot get a string from a single unichar, it most likely is part 
of a surrogate pair
+  if (nil != chars)
+    {
+      NSCharacterSet *requiredCharacterSet = [NSCharacterSet 
characterSetWithCharactersInString: chars];
+      NSDictionary *fontAttributes = [NSDictionary 
dictionaryWithObjectsAndKeys: requiredCharacterSet, 
NSFontCharacterSetAttribute, nil];
+      NSSet *mandatoryKeys = [NSSet setWithObjects: 
NSFontCharacterSetAttribute, nil];
+      NSFontDescriptor *fd = [NSFontDescriptor 
fontDescriptorWithFontAttributes: fontAttributes];
+      return [fd matchingFontDescriptorWithMandatoryKeys: mandatoryKeys];
+    }
+  else
+    {
+      return nil;
+    }
 }
 
 - (NSFont*)_substituteFontFor: (unichar)uchar font: (NSFont*)baseFont
@@ -1620,6 +1629,11 @@
           [string getCharacters: chars range: NSMakeRange(start, dist)];
         }
       uchar = chars[i - start];
+      if (uchar >= 0xd800 && uchar <= 0xdfff)
+        {
+          // Currently we don't handle surrogate pairs
+          continue;
+        }
       
       if (!NSLocationInRange(i, fontRange))
         {


_______________________________________________
Gnustep-cvs mailing list
Gnustep-cvs@gna.org
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to