Changeset 2133

Show
Ignore:
Timestamp:
11/21/04 12:10:34 (4 years ago)
Author:
timothy
Message:

When getting the THML or CSS value of a color, don't convert to calibrated RGB space unless we need to. This fixed a Safari 1.3 issue where colors could mismatch now that WebKit? returns colors in device color space.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/NSColorAdditions.m

    r1823 r2133  
    134134- (NSString *) HTMLAttributeValue { 
    135135        float red = 0., green = 0., blue = 0.; 
    136         [[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:NULL]; 
     136        NSColor *color = self; 
     137        if( ! [[self colorSpaceName] isEqualToString:NSCalibratedRGBColorSpace] && ! [[self colorSpaceName] isEqualToString:NSDeviceRGBColorSpace] ) 
     138                color = [self colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; // we need to convert to RGB space 
     139        [color getRed:&red green:&green blue:&blue alpha:NULL]; 
    137140        return [NSString stringWithFormat:@"#%02x%02x%02x", (int)(red * 255), (int)(green * 255), (int)(blue * 255)]; 
    138141} 
     
    140143- (NSString *) CSSAttributeValue { 
    141144        float red = 0., green = 0., blue = 0., alpha = 0.; 
    142         [[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha]; 
     145        NSColor *color = self; 
     146        if( ! [[self colorSpaceName] isEqualToString:NSCalibratedRGBColorSpace] && ! [[self colorSpaceName] isEqualToString:NSDeviceRGBColorSpace] ) 
     147                color = [self colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; // we need to convert to RGB space 
     148        [color getRed:&red green:&green blue:&blue alpha:&alpha]; 
    143149        if( alpha < 1. ) return [NSString stringWithFormat:@"rgba( %d, %d, %d, %.3f )", (int)(red * 255), (int)(green * 255), (int)(blue * 255), alpha]; 
    144150        return [NSString stringWithFormat:@"#%02x%02x%02x", (int)(red * 255), (int)(green * 255), (int)(blue * 255)];