Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions colordump/CDColorListDumper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down