3333#warning [OHAttributedLabel integration] You should include OHAttributedLabel project in your workspace instead of copying the files in your own app project. Or better, use CocoaPods to integrate your 3rd party libs. See README for instructions.
3434#endif
3535
36- #if __has_feature(objc_arc)
37- #define BRIDGE_CAST __bridge
38- #define BRIDGE_TRANSFER_CAST __bridge_transfer
39- #define MRC_AUTORELEASE (x ) (x)
40- #else
41- #define BRIDGE_CAST
42- #define BRIDGE_TRANSFER_CAST
43- #define MRC_AUTORELEASE (x ) [(x) autorelease ]
44- #endif
45-
4636NSString * kOHLinkAttributeName = @" NSLinkAttributeName" ; // Use the same value as OSX, to be compatible in case Apple port this to iOS one day too
4737
4838// ///////////////////////////////////////////////////////////////////////////////////
@@ -53,7 +43,7 @@ +(NSAttributedString*)attributedStringWithString:(NSString*)string
5343{
5444 if (string)
5545 {
56- return MRC_AUTORELEASE ( [[self alloc ] initWithString: string]) ;
46+ return [[self alloc ] initWithString: string];
5747 } else {
5848 return nil ;
5949 }
@@ -62,7 +52,7 @@ +(NSAttributedString*)attributedStringWithAttributedString:(NSAttributedString*)
6252{
6353 if (attrStr)
6454 {
65- return MRC_AUTORELEASE ( [[self alloc ] initWithAttributedString: attrStr]) ;
55+ return [[self alloc ] initWithAttributedString: attrStr];
6656 } else {
6757 return nil ;
6858 }
@@ -75,7 +65,7 @@ -(CGSize)sizeConstrainedToSize:(CGSize)maxSize
7565
7666-(CGSize)sizeConstrainedToSize : (CGSize)maxSize fitRange : (NSRange *)fitRange
7767{
78- CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString ((BRIDGE_CAST CFAttributedStringRef)self);
68+ CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString ((__bridge CFAttributedStringRef)self);
7969 CGSize sz = CGSizeMake (0 .f , 0 .f );
8070 if (framesetter)
8171 {
@@ -94,14 +84,14 @@ -(CGSize)sizeConstrainedToSize:(CGSize)maxSize fitRange:(NSRange*)fitRange
9484
9585-(CTFontRef)fontAtIndex : (NSUInteger )index effectiveRange : (NSRangePointer )aRange
9686{
97- id attr = [self attribute: (BRIDGE_CAST NSString *)kCTFontAttributeName atIndex: index effectiveRange: aRange];
98- return (BRIDGE_CAST CTFontRef)attr;
87+ id attr = [self attribute: (__bridge NSString *)kCTFontAttributeName atIndex: index effectiveRange: aRange];
88+ return (__bridge CTFontRef)attr;
9989}
10090
10191-(UIColor*)textColorAtIndex : (NSUInteger )index effectiveRange : (NSRangePointer )aRange
10292{
103- id attr = [self attribute: (BRIDGE_CAST NSString *)kCTForegroundColorAttributeName atIndex: index effectiveRange: aRange];
104- return [UIColor colorWithCGColor: (BRIDGE_CAST CGColorRef)attr];
93+ id attr = [self attribute: (__bridge NSString *)kCTForegroundColorAttributeName atIndex: index effectiveRange: aRange];
94+ return [UIColor colorWithCGColor: (__bridge CGColorRef)attr];
10595}
10696
10797-(BOOL )textIsUnderlinedAtIndex : (NSUInteger )index effectiveRange : (NSRangePointer )aRange
@@ -112,7 +102,7 @@ -(BOOL)textIsUnderlinedAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)
112102
113103-(int32_t )textUnderlineStyleAtIndex : (NSUInteger )index effectiveRange : (NSRangePointer )aRange
114104{
115- id attr = [self attribute: (BRIDGE_CAST NSString *)kCTUnderlineStyleAttributeName atIndex: index effectiveRange: aRange];
105+ id attr = [self attribute: (__bridge NSString *)kCTUnderlineStyleAttributeName atIndex: index effectiveRange: aRange];
116106 return [(NSNumber *)attr intValue ];
117107}
118108
@@ -125,26 +115,26 @@ -(BOOL)textIsBoldAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange
125115
126116-(CTTextAlignment)textAlignmentAtIndex : (NSUInteger )index effectiveRange : (NSRangePointer )aRange
127117{
128- id attr = [self attribute: (BRIDGE_CAST NSString *)kCTParagraphStyleAttributeName atIndex: index effectiveRange: aRange];
129- CTParagraphStyleRef style = (BRIDGE_CAST CTParagraphStyleRef)attr;
118+ id attr = [self attribute: (__bridge NSString *)kCTParagraphStyleAttributeName atIndex: index effectiveRange: aRange];
119+ CTParagraphStyleRef style = (__bridge CTParagraphStyleRef)attr;
130120 CTTextAlignment textAlign = kCTNaturalTextAlignment ;
131121 CTParagraphStyleGetValueForSpecifier (style, kCTParagraphStyleSpecifierAlignment , sizeof (CTTextAlignment), &textAlign);
132122 return textAlign;
133123}
134124
135125-(CTLineBreakMode)lineBreakModeAtIndex : (NSUInteger )index effectiveRange : (NSRangePointer )aRange
136126{
137- id attr = [self attribute: (BRIDGE_CAST NSString *)kCTParagraphStyleAttributeName atIndex: index effectiveRange: aRange];
138- CTParagraphStyleRef style = (BRIDGE_CAST CTParagraphStyleRef)attr;
127+ id attr = [self attribute: (__bridge NSString *)kCTParagraphStyleAttributeName atIndex: index effectiveRange: aRange];
128+ CTParagraphStyleRef style = (__bridge CTParagraphStyleRef)attr;
139129 CTLineBreakMode lineBreakMode = kCTLineBreakByWordWrapping ;
140130 CTParagraphStyleGetValueForSpecifier (style, kCTParagraphStyleSpecifierLineBreakMode , sizeof (CTLineBreakMode), &lineBreakMode);
141131 return lineBreakMode;
142132}
143133
144134-(OHParagraphStyle*)paragraphStyleAtIndex : (NSUInteger )index effectiveRange : (NSRangePointer )aRange
145135{
146- id attr = [self attribute: (BRIDGE_CAST NSString *)kCTParagraphStyleAttributeName atIndex: index effectiveRange: aRange];
147- CTParagraphStyleRef style = (BRIDGE_CAST CTParagraphStyleRef)attr;
136+ id attr = [self attribute: (__bridge NSString *)kCTParagraphStyleAttributeName atIndex: index effectiveRange: aRange];
137+ CTParagraphStyleRef style = (__bridge CTParagraphStyleRef)attr;
148138 return [OHParagraphStyle paragraphStyleWithCTParagraphStyle: style];
149139}
150140
@@ -181,11 +171,11 @@ -(void)setFontName:(NSString*)fontName size:(CGFloat)size
181171-(void )setFontName : (NSString *)fontName size : (CGFloat)size range : (NSRange )range
182172{
183173 // kCTFontAttributeName
184- CTFontRef aFont = CTFontCreateWithName ((BRIDGE_CAST CFStringRef)fontName, size, NULL );
174+ CTFontRef aFont = CTFontCreateWithName ((__bridge CFStringRef)fontName, size, NULL );
185175 if (aFont)
186176 {
187- [self removeAttribute: (BRIDGE_CAST NSString *)kCTFontAttributeName range: range]; // Work around for Apple leak
188- [self addAttribute: (BRIDGE_CAST NSString *)kCTFontAttributeName value: (BRIDGE_CAST id )aFont range: range];
177+ [self removeAttribute: (__bridge NSString *)kCTFontAttributeName range: range]; // Work around for Apple leak
178+ [self addAttribute: (__bridge NSString *)kCTFontAttributeName value: (__bridge id )aFont range: range];
189179 CFRelease (aFont);
190180 }
191181}
@@ -194,19 +184,19 @@ -(void)setFontFamily:(NSString*)fontFamily size:(CGFloat)size bold:(BOOL)isBold
194184 // kCTFontFamilyNameAttribute + kCTFontTraitsAttribute
195185 CTFontSymbolicTraits symTrait = (isBold?kCTFontBoldTrait :0 ) | (isItalic?kCTFontItalicTrait :0 );
196186 NSDictionary * trait = [NSDictionary dictionaryWithObject: [NSNumber numberWithUnsignedLong: symTrait]
197- forKey: (BRIDGE_CAST NSString *)kCTFontSymbolicTrait ];
187+ forKey: (__bridge NSString *)kCTFontSymbolicTrait ];
198188 NSDictionary * attr = [NSDictionary dictionaryWithObjectsAndKeys:
199189 fontFamily,kCTFontFamilyNameAttribute ,
200190 trait,kCTFontTraitsAttribute ,nil ];
201191
202- CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes ((BRIDGE_CAST CFDictionaryRef)attr);
192+ CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes ((__bridge CFDictionaryRef)attr);
203193 if (!desc) return ;
204194 CTFontRef aFont = CTFontCreateWithFontDescriptor (desc, size, NULL );
205195 CFRelease (desc);
206196 if (!aFont) return ;
207197
208- [self removeAttribute: (BRIDGE_CAST NSString *)kCTFontAttributeName range: range]; // Work around for Apple leak
209- [self addAttribute: (BRIDGE_CAST NSString *)kCTFontAttributeName value: (BRIDGE_CAST id )aFont range: range];
198+ [self removeAttribute: (__bridge NSString *)kCTFontAttributeName range: range]; // Work around for Apple leak
199+ [self addAttribute: (__bridge NSString *)kCTFontAttributeName value: (__bridge id )aFont range: range];
210200 CFRelease (aFont);
211201}
212202
@@ -217,8 +207,8 @@ -(void)setTextColor:(UIColor*)color
217207-(void )setTextColor : (UIColor*)color range : (NSRange )range
218208{
219209 // kCTForegroundColorAttributeName
220- [self removeAttribute: (BRIDGE_CAST NSString *)kCTForegroundColorAttributeName range: range]; // Work around for Apple leak
221- [self addAttribute: (BRIDGE_CAST NSString *)kCTForegroundColorAttributeName value: (BRIDGE_CAST id )color.CGColor range: range];
210+ [self removeAttribute: (__bridge NSString *)kCTForegroundColorAttributeName range: range]; // Work around for Apple leak
211+ [self addAttribute: (__bridge NSString *)kCTForegroundColorAttributeName value: (__bridge id )color.CGColor range: range];
222212}
223213
224214-(void )setTextIsUnderlined : (BOOL )underlined
@@ -232,8 +222,8 @@ -(void)setTextIsUnderlined:(BOOL)underlined range:(NSRange)range
232222}
233223-(void )setTextUnderlineStyle : (int32_t )style range : (NSRange )range
234224{
235- [self removeAttribute: (BRIDGE_CAST NSString *)kCTUnderlineStyleAttributeName range: range]; // Work around for Apple leak
236- [self addAttribute: (BRIDGE_CAST NSString *)kCTUnderlineStyleAttributeName value: [NSNumber numberWithInt: style] range: range];
225+ [self removeAttribute: (__bridge NSString *)kCTUnderlineStyleAttributeName range: range]; // Work around for Apple leak
226+ [self addAttribute: (__bridge NSString *)kCTUnderlineStyleAttributeName value: [NSNumber numberWithInt: style] range: range];
237227}
238228
239229-(void )changeFontWithTraits : (CTFontSymbolicTraits)traits
@@ -246,11 +236,10 @@ -(void)changeFontWithTraits:(CTFontSymbolicTraits)traits
246236 [self beginEditing ];
247237 do {
248238 // Get font at startPoint
249- CTFontRef currentFont = (BRIDGE_CAST CTFontRef)[self attribute: (BRIDGE_CAST NSString *)kCTFontAttributeName atIndex: startPoint effectiveRange: &effectiveRange];
239+ CTFontRef currentFont = (__bridge CTFontRef)[self attribute: (__bridge NSString *)kCTFontAttributeName atIndex: startPoint effectiveRange: &effectiveRange];
250240 if (!currentFont)
251241 {
252242 currentFont = CTFontCreateUIFontForLanguage (kCTFontLabelFontType , 0.0 , NULL );
253- (void )MRC_AUTORELEASE ((BRIDGE_TRANSFER_CAST id )currentFont);
254243 }
255244 // The range for which this font is effective
256245 NSRange fontRange = NSIntersectionRange (range, effectiveRange);
@@ -263,12 +252,12 @@ -(void)changeFontWithTraits:(CTFontSymbolicTraits)traits
263252 // font for labels in XIB, but fail to detect its italic variant correctly prior to iOS 6.1
264253 if (fontFinderBlock)
265254 {
266- NSString * newFontName = fontFinderBlock ((BRIDGE_CAST NSString *)fontNameRef);
255+ NSString * newFontName = fontFinderBlock ((__bridge NSString *)fontNameRef);
267256 if (newFontName)
268257 {
269258 CTFontDescriptorRef fontDesc = CTFontCopyFontDescriptor (currentFont);
270259 NSDictionary * nameAttr = [NSDictionary dictionaryWithObject: newFontName forKey: @" NSFontNameAttribute" ];
271- CTFontDescriptorRef newFontDesc = CTFontDescriptorCreateCopyWithAttributes (fontDesc, (BRIDGE_CAST CFDictionaryRef)nameAttr);
260+ CTFontDescriptorRef newFontDesc = CTFontDescriptorCreateCopyWithAttributes (fontDesc, (__bridge CFDictionaryRef)nameAttr);
272261 newFont = CTFontCreateWithFontDescriptor (newFontDesc, CTFontGetSize (currentFont), NULL );
273262 CFRelease (fontDesc);
274263 CFRelease (newFontDesc);
@@ -278,16 +267,16 @@ -(void)changeFontWithTraits:(CTFontSymbolicTraits)traits
278267 if (!newFont)
279268 {
280269 NSLog (@" [OHAttributedLabel] Warning: can't find an italic font variant for font family %@ . "
281- @" Try another font family (like Helvetica) instead." , (BRIDGE_CAST NSString *)fontNameRef);
270+ @" Try another font family (like Helvetica) instead." , (__bridge NSString *)fontNameRef);
282271 }
283272 if (fontNameRef) CFRelease (fontNameRef);
284273 }
285274
286275 // Apply the new font with new traits
287276 if (newFont)
288277 {
289- [self removeAttribute: (BRIDGE_CAST NSString *)kCTFontAttributeName range: fontRange]; // Work around for Apple leak
290- [self addAttribute: (BRIDGE_CAST NSString *)kCTFontAttributeName value: (BRIDGE_CAST id )newFont range: fontRange];
278+ [self removeAttribute: (__bridge NSString *)kCTFontAttributeName range: fontRange]; // Work around for Apple leak
279+ [self addAttribute: (__bridge NSString *)kCTFontAttributeName value: (__bridge id )newFont range: fontRange];
291280 CFRelease (newFont);
292281 }
293282
@@ -376,7 +365,7 @@ -(void)modifyParagraphStylesInRange:(NSRange)range withBlock:(void(^)(OHParagrap
376365 [self beginEditing ];
377366 while (NSLocationInRange (loc, range))
378367 {
379- CTParagraphStyleRef currentCTStyle = (BRIDGE_CAST CTParagraphStyleRef)[self attribute: (BRIDGE_CAST NSString *)kCTParagraphStyleAttributeName
368+ CTParagraphStyleRef currentCTStyle = (__bridge CTParagraphStyleRef)[self attribute: (__bridge NSString *)kCTParagraphStyleAttributeName
380369 atIndex: loc longestEffectiveRange: rangePtr inRange: range];
381370 __block OHParagraphStyle* paraStyle = [OHParagraphStyle paragraphStyleWithCTParagraphStyle: currentCTStyle];
382371 block (paraStyle);
@@ -395,8 +384,8 @@ -(void)setParagraphStyle:(OHParagraphStyle *)style
395384-(void )setParagraphStyle : (OHParagraphStyle*)style range : (NSRange )range
396385{
397386 CTParagraphStyleRef newParaStyle = [style createCTParagraphStyle ];
398- [self removeAttribute: (BRIDGE_CAST NSString *)kCTParagraphStyleAttributeName range: range]; // Work around for Apple leak
399- [self addAttribute: (BRIDGE_CAST NSString *)kCTParagraphStyleAttributeName value: (BRIDGE_CAST id )newParaStyle range: range];
387+ [self removeAttribute: (__bridge NSString *)kCTParagraphStyleAttributeName range: range]; // Work around for Apple leak
388+ [self addAttribute: (__bridge NSString *)kCTParagraphStyleAttributeName value: (__bridge id )newParaStyle range: range];
400389 CFRelease (newParaStyle);
401390}
402391
0 commit comments