From b04bfd507afcd7ccfd31bc1402bc2c2fe10c2d51 Mon Sep 17 00:00:00 2001 From: Fred Kiefer Date: Tue, 11 Oct 2011 20:57:24 +0000 Subject: [PATCH] * Source/NSColor.m: Add alpha handling to keyed-coding/decoding. Should fix bug #34501. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33965 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/NSColor.m | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index bdc6cbcbf..e61300e99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-10-11 Fred Kiefer + + * Source/NSColor.m: Add alpha handling to keyed-coding/decoding. + Should fix bug #34501. + 2011-10-11 Fred Kiefer * Source/NSTextView.m(currentVersion, -encodeWithCoder:, diff --git a/Source/NSColor.m b/Source/NSColor.m index b78d54864..d1472156c 100644 --- a/Source/NSColor.m +++ b/Source/NSColor.m @@ -1426,6 +1426,7 @@ systemColorWithName(NSString *name) [scanner scanFloat: &red]; [scanner scanFloat: &green]; [scanner scanFloat: &blue]; + [scanner scanFloat: &alpha]; RELEASE(scanner); RELEASE(str); } @@ -1462,6 +1463,7 @@ systemColorWithName(NSString *name) length: length]; scanner = [[NSScanner alloc] initWithString: str]; [scanner scanFloat: &white]; + [scanner scanFloat: &alpha]; RELEASE(scanner); RELEASE(str); } @@ -1500,6 +1502,7 @@ systemColorWithName(NSString *name) [scanner scanFloat: &yellow]; [scanner scanFloat: &magenta]; [scanner scanFloat: &black]; + [scanner scanFloat: &alpha]; RELEASE(scanner); RELEASE(str); } @@ -2219,8 +2222,15 @@ static NSRecursiveLock *namedColorLock = nil; { [aCoder encodeInt: 4 forKey: @"NSColorSpace"]; } - // FIXME: Missing handling of alpha value - str = [[NSString alloc] initWithFormat: @"%f", _white_component]; + + if (_alpha_component == 1.0) + { + str = [[NSString alloc] initWithFormat: @"%f", _white_component]; + } + else + { + str = [[NSString alloc] initWithFormat: @"%f %f", _white_component, _alpha_component]; + } [aCoder encodeBytes: (const uint8_t*)[str cString] length: [str cStringLength] forKey: @"NSWhite"]; @@ -2526,10 +2536,19 @@ static NSRecursiveLock *namedColorLock = nil; { NSString *str; - // FIXME: Missing handling of alpha value [aCoder encodeInt: 5 forKey: @"NSColorSpace"]; - str = [[NSString alloc] initWithFormat: @"%f %f %f %f", _cyan_component, - _magenta_component, _yellow_component, _black_component]; + if (_alpha_component == 1.0) + { + str = [[NSString alloc] initWithFormat: @"%f %f %f %f", _cyan_component, + _magenta_component, _yellow_component, + _black_component]; + } + else + { + str = [[NSString alloc] initWithFormat: @"%f %f %f %f %f", _cyan_component, + _magenta_component, _yellow_component, + _black_component, _alpha_component]; + } [aCoder encodeBytes: (const uint8_t*)[str cString] length: [str cStringLength] forKey: @"NSCYMK"]; @@ -2819,9 +2838,17 @@ static NSRecursiveLock *namedColorLock = nil; { [aCoder encodeInt: 2 forKey: @"NSColorSpace"]; } - // FIXME: Missing handling of alpha value - str = [[NSString alloc] initWithFormat: @"%f %f %f", _red_component, - _green_component, _blue_component]; + + if (_alpha_component == 1.0) + { + str = [[NSString alloc] initWithFormat: @"%f %f %f", _red_component, + _green_component, _blue_component]; + } + else + { + str = [[NSString alloc] initWithFormat: @"%f %f %f %f", _red_component, + _green_component, _blue_component, _alpha_component]; + } [aCoder encodeBytes: (const uint8_t*)[str cString] length: [str cStringLength] forKey: @"NSRGB"];