mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
2017-03-31 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSAttributedString.m: Check for surrogate UTF16 characters to prevent nil strings when trying to attempt fonst substitution. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@40430 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
90d793695b
commit
34bbb5e95d
2 changed files with 25 additions and 5 deletions
|
@ -1,3 +1,9 @@
|
|||
2017-03-31 Fred Kiefer <FredKiefer@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 <rm@gnu.org>
|
||||
|
||||
* Source/NSBitmapImageRep+JPEG.m (-_initBitmapFromJPEG:errorMessage:)
|
||||
|
|
|
@ -1524,11 +1524,20 @@ static NSMutableDictionary *cachedCSets = nil;
|
|||
- (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 @@ static NSMutableDictionary *cachedCSets = nil;
|
|||
[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))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue