From 92de4ed1c0947354f3f7ddc0de5621c007d01c96 Mon Sep 17 00:00:00 2001 From: Massimiliano Ribuoli Date: Sat, 1 Mar 2014 11:22:43 +0100 Subject: [PATCH 1/2] Added support for NSCalibratedRGBColorSpace, NSDeviceWhiteColorSpace and NSCalibratedRGBColorSpace. --- colordump/CDColorListDumper.m | 49 ++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/colordump/CDColorListDumper.m b/colordump/CDColorListDumper.m index d77d4cb..8d17171 100644 --- a/colordump/CDColorListDumper.m +++ b/colordump/CDColorListDumper.m @@ -33,20 +33,45 @@ - (void)startWithCompletionHandler:(dispatch_block_t)completionBlock; for (NSString *key in colorList.allKeys) { NSColor *color = [colorList colorWithKey:key]; - if (![color.colorSpaceName isEqualToString:NSDeviceRGBColorSpace]) { - printf("Color %s isn't device RGB. Skipping.", [key UTF8String]); + + if([color.colorSpaceName isEqualToString:NSCalibratedRGBColorSpace]) + { + color = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace]; + } + else if([color.colorSpaceName isEqualToString:NSCalibratedWhiteColorSpace]) + { + color = [color colorUsingColorSpaceName:NSDeviceWhiteColorSpace]; + } + + if ([color.colorSpaceName isEqualToString:NSDeviceRGBColorSpace]) + { + CGFloat r, g, b, a; + [color getRed:&r green:&g blue:&b alpha:&a]; + + NSString *declaration = [NSString stringWithFormat:@"+ (UIColor *)%@Color;\n", [self methodNameForKey:key]]; + [self.interfaceContents addObject:declaration]; + + NSMutableString *method = [declaration mutableCopy]; + [method appendFormat:@"{\n\treturn [UIColor colorWithRed:%.3ff green:%.3ff blue:%.3ff alpha:%.3ff];\n}\n", r, g, b, a]; + [self.implementationContents addObject:method]; + } + else if([color.colorSpaceName isEqualToString:NSDeviceWhiteColorSpace]) + { + CGFloat w, a; + [color getWhite:&w alpha:&a]; + + NSString *declaration = [NSString stringWithFormat:@"+ (UIColor *)%@Color;\n", [self methodNameForKey:key]]; + [self.interfaceContents addObject:declaration]; + + NSMutableString *method = [declaration mutableCopy]; + [method appendFormat:@"{\n\treturn [UIColor colorWithWhite:%.3f alpha:%.3f];\n}\n", w, a]; + [self.implementationContents addObject:method]; + } + else + { + printf("Color %s isn't supported. Skipping.\n", [key UTF8String]); continue; } - - CGFloat r, g, b, a; - [color getRed:&r green:&g blue:&b alpha:&a]; - - NSString *declaration = [NSString stringWithFormat:@"+ (UIColor *)%@Color;\n", [self methodNameForKey:key]]; - [self.interfaceContents addObject:declaration]; - - NSMutableString *method = [declaration mutableCopy]; - [method appendFormat:@"{\n return [UIColor colorWithRed:%.3ff green:%.3ff blue:%.3ff alpha:%.3ff];\n}\n", r, g, b, a]; - [self.implementationContents addObject:method]; } [self writeOutputFiles]; From 5ab9b7641272d8ae3e6e8fed218849f2da0bc576 Mon Sep 17 00:00:00 2001 From: Massimiliano Ribuoli Date: Wed, 5 Mar 2014 09:29:15 +0100 Subject: [PATCH 2/2] Made indentation/spacing style consistent with the resto of the codebase. Removed color space conversion from calibrated to device. --- colordump/CDColorListDumper.m | 62 ++++++++++++++--------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/colordump/CDColorListDumper.m b/colordump/CDColorListDumper.m index 8d17171..633416f 100644 --- a/colordump/CDColorListDumper.m +++ b/colordump/CDColorListDumper.m @@ -20,9 +20,9 @@ + (NSString *)inputFileExtension; - (void)startWithCompletionHandler:(dispatch_block_t)completionBlock; { NSString *colorListName = [[self.inputURL lastPathComponent] stringByDeletingPathExtension]; - + self.className = [[NSString stringWithFormat:@"%@%@ColorList", self.classPrefix, colorListName]stringByReplacingOccurrencesOfString:@" " withString:@""]; - + NSColorList *colorList = [[NSColorList alloc] initWithName:colorListName fromFile:self.inputURL.path]; // Install this color list @@ -33,42 +33,28 @@ - (void)startWithCompletionHandler:(dispatch_block_t)completionBlock; for (NSString *key in colorList.allKeys) { NSColor *color = [colorList colorWithKey:key]; - - if([color.colorSpaceName isEqualToString:NSCalibratedRGBColorSpace]) - { - color = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace]; - } - else if([color.colorSpaceName isEqualToString:NSCalibratedWhiteColorSpace]) - { - color = [color colorUsingColorSpaceName:NSDeviceWhiteColorSpace]; - } - - if ([color.colorSpaceName isEqualToString:NSDeviceRGBColorSpace]) - { - CGFloat r, g, b, a; - [color getRed:&r green:&g blue:&b alpha:&a]; - - NSString *declaration = [NSString stringWithFormat:@"+ (UIColor *)%@Color;\n", [self methodNameForKey:key]]; - [self.interfaceContents addObject:declaration]; - - NSMutableString *method = [declaration mutableCopy]; - [method appendFormat:@"{\n\treturn [UIColor colorWithRed:%.3ff green:%.3ff blue:%.3ff alpha:%.3ff];\n}\n", r, g, b, a]; - [self.implementationContents addObject:method]; - } - else if([color.colorSpaceName isEqualToString:NSDeviceWhiteColorSpace]) - { - CGFloat w, a; - [color getWhite:&w alpha:&a]; - - NSString *declaration = [NSString stringWithFormat:@"+ (UIColor *)%@Color;\n", [self methodNameForKey:key]]; - [self.interfaceContents addObject:declaration]; - - NSMutableString *method = [declaration mutableCopy]; - [method appendFormat:@"{\n\treturn [UIColor colorWithWhite:%.3f alpha:%.3f];\n}\n", w, a]; - [self.implementationContents addObject:method]; - } - else - { + + if ([color.colorSpaceName isEqualToString:NSDeviceRGBColorSpace] || [color.colorSpaceName isEqualToString:NSCalibratedRGBColorSpace]) { + CGFloat r, g, b, a; + [color getRed:&r green:&g blue:&b alpha:&a]; + + NSString *declaration = [NSString stringWithFormat:@"+ (UIColor *)%@Color;\n", [self methodNameForKey:key]]; + [self.interfaceContents addObject:declaration]; + + NSMutableString *method = [declaration mutableCopy]; + [method appendFormat:@"{\n\treturn [UIColor colorWithRed:%.3ff green:%.3ff blue:%.3ff alpha:%.3ff];\n}\n", r, g, b, a]; + [self.implementationContents addObject:method]; + } else if([color.colorSpaceName isEqualToString:NSDeviceWhiteColorSpace] || [color.colorSpaceName isEqualToString:NSCalibratedWhiteColorSpace]) { + CGFloat w, a; + [color getWhite:&w alpha:&a]; + + NSString *declaration = [NSString stringWithFormat:@"+ (UIColor *)%@Color;\n", [self methodNameForKey:key]]; + [self.interfaceContents addObject:declaration]; + + NSMutableString *method = [declaration mutableCopy]; + [method appendFormat:@"{\n\treturn [UIColor colorWithWhite:%.3f alpha:%.3f];\n}\n", w, a]; + [self.implementationContents addObject:method]; + } else { printf("Color %s isn't supported. Skipping.\n", [key UTF8String]); continue; }