diff --git a/colordump/CDColorListDumper.m b/colordump/CDColorListDumper.m index d77d4cb..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,20 +33,31 @@ - (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: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; } - - 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];