diff --git a/Core/Source/DTColor+Compatibility.m b/Core/Source/DTColor+Compatibility.m index cb96c7dd3..eb47e1ccd 100644 --- a/Core/Source/DTColor+Compatibility.m +++ b/Core/Source/DTColor+Compatibility.m @@ -22,9 +22,50 @@ - (CGFloat)alphaComponent #else +#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_7 +#import + +@interface NSColor (DTCoreText) ++ (NSColor *)DTCoreText_colorWithCGColor:(CGColorRef)cgColor; +- (CGColorRef)DTCoreText_CGColor; +@end + +static void DTCoreTextAddMissingSelector(Class aClass, SEL aSelector, SEL implementationSelector) +{ + Method method = class_getInstanceMethod(aClass, aSelector); + if (method == NULL) { + method = class_getInstanceMethod(aClass, implementationSelector); + NSCAssert(method != NULL, @"missing implementation method"); + + IMP methodImplementation = method_getImplementation(method); + const char *methodTypeEncoding = method_getTypeEncoding(method); + +#if !defined(NS_BLOCK_ASSERTIONS) + BOOL rc = class_addMethod(aClass, aSelector, methodImplementation, methodTypeEncoding); + NSCAssert(rc, @"failed to add missing method"); +#else + (void) class_addMethod(aClass, aSelector, methodImplementation, methodTypeEncoding); +#endif + } +} + +__attribute__((constructor)) +static void DTCoreTextNSColorInitialization(void) +{ + Class NSColorClass = objc_getClass("NSColor"); + Class NSColorMetaClass = object_getClass(NSColorClass); + DTCoreTextAddMissingSelector(NSColorMetaClass, @selector(colorWithCGColor:), @selector(DTCoreText_colorWithCGColor:)); + DTCoreTextAddMissingSelector(NSColorClass, @selector(CGColor), @selector(DTCoreText_CGColor)); +} + +#define colorWithCGColor DTCoreText_colorWithCGColor +#define CGColor DTCoreText_CGColor +#define HTML DTCoreText +#endif + @implementation NSColor (HTML) -#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_7 +#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_7 || MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_7 + (NSColor *)colorWithCGColor:(CGColorRef)cgColor { size_t count = CGColorGetNumberOfComponents(cgColor);