Fixed bug reading colors

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3571 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-01-18 05:35:14 +00:00
parent a1947434d8
commit 92eef2512b
2 changed files with 82 additions and 81 deletions

View file

@ -1,3 +1,8 @@
Mon Jan 18 5:00:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSColor.m: Fixed error in decoding color from defaults
string - was only reading the first (red) color component.
Fri Jan 15 10:00:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Fri Jan 15 10:00:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSPasteboard.m: Removed unused (and erroneous) header. * Source/NSPasteboard.m: Removed unused (and erroneous) header.

View file

@ -1133,95 +1133,91 @@ static NSMutableDictionary *colorStrings = nil;
+ (NSColor*) colorFromString: (NSString*)str + (NSColor*) colorFromString: (NSString*)str
{ {
id plist = [str propertyList]; if ([str hasPrefix: @"{"])
NSDictionary *dict;
NSString *space;
float alpha;
if (plist == nil)
return nil;
if ([plist isKindOfClass: [NSString class]] == YES)
{ {
const char *str = [(NSString*)plist cString]; NSDictionary *dict;
NSString *space;
float alpha;
dict = [str propertyList];
if (dict == nil)
return nil;
if ((space = [dict objectForKey: @"ColorSpace"]) == nil)
return nil;
alpha = [[dict objectForKey: @"Alpha"] floatValue];
if ([space isEqual: NSCalibratedWhiteColorSpace])
{
float white = [[dict objectForKey: @"W"] floatValue];
return [self colorWithCalibratedWhite: white alpha: alpha];
}
if ([space isEqual: NSCalibratedBlackColorSpace])
{
float white = [[dict objectForKey: @"W"] floatValue];
return [self colorWithCalibratedWhite: white
alpha: alpha];
}
if ([space isEqual: NSCalibratedRGBColorSpace])
{
if ([dict objectForKey: @"H"] != nil)
{
float hue = [[dict objectForKey: @"H"] floatValue];
float saturation = [[dict objectForKey: @"S"] floatValue];
float brightness = [[dict objectForKey: @"B"] floatValue];
return [self colorWithCalibratedHue: hue
saturation: saturation
brightness: brightness
alpha: alpha];
}
else
{
float red = [[dict objectForKey: @"R"] floatValue];
float green = [[dict objectForKey: @"G"] floatValue];
float blue = [[dict objectForKey: @"B"] floatValue];
return [self colorWithCalibratedRed: red
green: green
blue: blue
alpha: alpha];
}
}
if ([space isEqual: NSDeviceCMYKColorSpace])
{
float cyan = [[dict objectForKey: @"C"] floatValue];
float magenta = [[dict objectForKey: @"M"] floatValue];
float yellow = [[dict objectForKey: @"Y"] floatValue];
float black = [[dict objectForKey: @"B"] floatValue];
return [self colorWithDeviceCyan: cyan
magenta: magenta
yellow: yellow
black: black
alpha: alpha];
}
if ([space isEqual: NSNamedColorSpace])
{
NSString *cat = [dict objectForKey: @"Catalog"];
NSString *col = [dict objectForKey: @"Color"];
return [self colorWithCatalogName: cat
colorName: col];
}
}
else if (str)
{
const char *ptr = [str cString];
float r, g, b; float r, g, b;
sscanf(str, "%f %f %f", &r, &g, &b); sscanf(ptr, "%f %f %f", &r, &g, &b);
return [self colorWithCalibratedRed: r return [self colorWithCalibratedRed: r
green: g green: g
blue: b blue: b
alpha: 0]; alpha: 0];
} }
if ([plist isKindOfClass: [NSDictionary class]] == NO)
return nil;
dict = (NSDictionary*)plist;
if ((space = [dict objectForKey: @"ColorSpace"]) == nil)
return nil;
alpha = [[dict objectForKey: @"Alpha"] floatValue];
if ([space isEqual: NSCalibratedWhiteColorSpace])
{
float white = [[dict objectForKey: @"W"] floatValue];
return [self colorWithCalibratedWhite: white alpha: alpha];
}
if ([space isEqual: NSCalibratedBlackColorSpace])
{
float white = [[dict objectForKey: @"W"] floatValue];
return [self colorWithCalibratedWhite: white
alpha: alpha];
}
if ([space isEqual: NSCalibratedRGBColorSpace])
{
if ([dict objectForKey: @"H"] != nil)
{
float hue = [[dict objectForKey: @"H"] floatValue];
float saturation = [[dict objectForKey: @"S"] floatValue];
float brightness = [[dict objectForKey: @"B"] floatValue];
return [self colorWithCalibratedHue: hue
saturation: saturation
brightness: brightness
alpha: alpha];
}
else
{
float red = [[dict objectForKey: @"R"] floatValue];
float green = [[dict objectForKey: @"G"] floatValue];
float blue = [[dict objectForKey: @"B"] floatValue];
return [self colorWithCalibratedRed: red
green: green
blue: blue
alpha: alpha];
}
}
if ([space isEqual: NSDeviceCMYKColorSpace])
{
float cyan = [[dict objectForKey: @"C"] floatValue];
float magenta = [[dict objectForKey: @"M"] floatValue];
float yellow = [[dict objectForKey: @"Y"] floatValue];
float black = [[dict objectForKey: @"B"] floatValue];
return [self colorWithDeviceCyan: cyan
magenta: magenta
yellow: yellow
black: black
alpha: alpha];
}
if ([space isEqual: NSNamedColorSpace])
{
NSString *cat = [dict objectForKey: @"Catalog"];
NSString *col = [dict objectForKey: @"Color"];
return [self colorWithCatalogName: cat
colorName: col];
}
return nil; return nil;
} }