diff --git a/Frameworks/OakAppKit/src/NSColor Additions.h b/Frameworks/OakAppKit/src/NSColor Additions.h index 4a54ec1f..90c1b9f1 100644 --- a/Frameworks/OakAppKit/src/NSColor Additions.h +++ b/Frameworks/OakAppKit/src/NSColor Additions.h @@ -1,8 +1,6 @@ -@interface NSColor (Creation) +@interface NSColor (TMColorAdditions) + (NSColor*)colorWithString:(NSString*)aString; + (NSColor*)tmColorWithCGColor:(CGColorRef)aColor; -@end - -@interface NSColor (OakColor) +- (CGColorRef)tmCGColor; - (BOOL)isDark; @end diff --git a/Frameworks/OakAppKit/src/NSColor Additions.mm b/Frameworks/OakAppKit/src/NSColor Additions.mm index 1a487a4a..1e1ffb37 100644 --- a/Frameworks/OakAppKit/src/NSColor Additions.mm +++ b/Frameworks/OakAppKit/src/NSColor Additions.mm @@ -1,7 +1,7 @@ #import "NSColor Additions.h" #import -@implementation NSColor (Creation) +@implementation NSColor (TMColorAdditions) + (NSColor*)colorWithString:(NSString*)aString { if(NSIsEmptyString(aString)) @@ -23,9 +23,21 @@ return [self colorWithCGColor:aColor]; return [NSColor colorWithColorSpace:[[[NSColorSpace alloc] initWithCGColorSpace:CGColorGetColorSpace(aColor)] autorelease] components:CGColorGetComponents(aColor) count:CGColorGetNumberOfComponents(aColor)]; } -@end -@implementation NSColor (OakColor) +- (CGColorRef)tmCGColor +{ + if([self respondsToSelector:@selector(CGColor)]) + return [self CGColor]; + + NSColor* rgbColor = [self colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; + CGFloat rgba[4]; + [rgbColor getRed:&rgba[0] green:&rgba[1] blue:&rgba[2] alpha:&rgba[3]]; + CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + CGColorRef res = CGColorCreate(colorSpace, rgba); + CGColorSpaceRelease(colorSpace); + return (CGColorRef)[(id)res autorelease]; +} + - (BOOL)isDark { uint32_t r(lroundf(255 * [self redComponent])); diff --git a/Frameworks/OakTextView/src/GutterView.mm b/Frameworks/OakTextView/src/GutterView.mm index a6a2b07b..32020c8c 100644 --- a/Frameworks/OakTextView/src/GutterView.mm +++ b/Frameworks/OakTextView/src/GutterView.mm @@ -1,6 +1,7 @@ #import "GutterView.h" #import #import +#import #import #import #import @@ -276,9 +277,9 @@ static CTLineRef CTCreateLineFromText (std::string const& text, NSFont* font, NS CTLineRef res = NULL; if(CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)) { - if(CGColorRef cgColor = [color CGColor]) + if(CGColorRef cgColor = [color tmCGColor]) CFDictionaryAddValue(dict, kCTForegroundColorAttributeName, cgColor); - + if(CTFontRef ctFont = CTFontCreateWithName((CFStringRef)[font fontName], [font pointSize], NULL)) { CFDictionaryAddValue(dict, kCTFontAttributeName, ctFont);