/
DTCompatibility.h
139 lines (107 loc) · 3.61 KB
/
DTCompatibility.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// DTCompatibility.h
// DTCoreText
//
// Created by Oliver Letterer on 09.04.12.
// Copyright (c) 2012 Drobnik.com. All rights reserved.
//
#pragma mark - iOS
#if TARGET_OS_IPHONE
// Compatibility Aliases
@compatibility_alias DTColor UIColor;
@compatibility_alias DTImage UIImage;
@compatibility_alias DTFont UIFont;
// Edge Insets
#define DTEdgeInsets UIEdgeInsets
#define DTEdgeInsetsMake(top, left, bottom, right) UIEdgeInsetsMake(top, left, bottom, right)
// NS-style text attributes are possible with iOS SDK 6.0 or higher
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
#define DTCORETEXT_SUPPORT_NS_ATTRIBUTES 1
#endif
// NSParagraphStyle supports tabs as of iOS SDK 7.0 or higher
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
#define DTCORETEXT_SUPPORT_NSPARAGRAPHSTYLE_TABS 1
#endif
// iOS before 5.0 has leak in CoreText replacing attributes
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
#define DTCORETEXT_NEEDS_ATTRIBUTE_REPLACEMENT_LEAK_FIX 1
#endif
// iOS 7 bug (rdar://14684188) workaround, can be removed once this bug is fixed
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
#define DTCORETEXT_FIX_14684188 1
#endif
// constant for checking for iOS 6
#define DTNSFoundationVersionNumber_iOS_6_0 992.00
// constant for checking for iOS 7
#define DTNSFoundationVersionNumber_iOS_7_0 1047.00
// runtime-check if NS-style attributes are allowed
static inline BOOL DTCoreTextModernAttributesPossible()
{
#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES
if (floor(NSFoundationVersionNumber) >= DTNSFoundationVersionNumber_iOS_6_0)
{
return YES;
}
#endif
return NO;
}
// runtime-check if CoreText draws underlines
static inline BOOL DTCoreTextDrawsUnderlinesWithGlyphs()
{
if (floor(NSFoundationVersionNumber) >= DTNSFoundationVersionNumber_iOS_7_0)
{
return YES;
}
return NO;
}
#if TARGET_CPU_ARM64 || TARGET_CPU_X86_64
#define DTNSNumberFromCGFloat(x) [NSNumber numberWithDouble:x]
#else
#define DTNSNumberFromCGFloat(x) [NSNumber numberWithFloat:x]
#endif
#endif
#pragma mark - Mac
#if !TARGET_OS_IPHONE
// Compatibility Aliases
@compatibility_alias DTColor NSColor;
@compatibility_alias DTImage NSImage;
@compatibility_alias DTFont NSFont;
// Edge Insets
#define DTEdgeInsets NSEdgeInsets
#define DTEdgeInsetsMake(top, left, bottom, right) NSEdgeInsetsMake(top, left, bottom, right)
// Mac supports NS-Style Text Attributes since 10.0
#define DTCORETEXT_SUPPORT_NS_ATTRIBUTES 1
#define DTCORETEXT_SUPPORT_NSPARAGRAPHSTYLE_TABS 1
// theoretically MacOS before 10.8 might have a leak in CoreText replacing attributes
#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7
#define DTCORETEXT_NEEDS_ATTRIBUTE_REPLACEMENT_LEAK_FIX 1
#endif
// NSValue has sizeValue on Mac, CGSizeValue on iOS
#define CGSizeValue sizeValue
// String functions named differently on Mac
static inline NSString *NSStringFromCGRect(const CGRect rect)
{
return NSStringFromRect(NSRectFromCGRect(rect));
}
static inline NSString *NSStringFromCGSize(const CGSize size)
{
return NSStringFromSize(NSSizeFromCGSize(size));
}
static inline NSString *NSStringFromCGPoint(const CGPoint point)
{
return NSStringFromPoint(NSPointFromCGPoint(point));
}
// runtime-check if NS-style attributes are allowed
static inline BOOL DTCoreTextModernAttributesPossible()
{
return YES;
}
// runtime-check if CoreText draws underlines
static inline BOOL DTCoreTextDrawsUnderlinesWithGlyphs()
{
return NO;
}
#define DTNSNumberFromCGFloat(x) [NSNumber numberWithDouble:x]
#endif
// this enables generic ceil, floor, abs, round functions that work for 64 and 32 bit
#include <tgmath.h>