Permalink
Browse files

fixed iOS 6 attribute crash

  • Loading branch information...
1 parent bc23ca8 commit a8abdbb08f24f51aa95a7bfdb212deb107f1278a @odrobnik odrobnik committed Dec 30, 2012
Showing with 39 additions and 13 deletions.
  1. +39 −13 Core/Source/DTHTMLElement.m
@@ -446,25 +446,51 @@ - (NSAttributedString *)attributedString
{
NSRange paragraphRange = [[tmpString string] rangeOfParagraphAtIndex:[tmpString length]-1];
- CTParagraphStyleRef paraStyle = (__bridge CTParagraphStyleRef)[tmpString attribute:(id)kCTParagraphStyleAttributeName atIndex:paragraphRange.location effectiveRange:NULL];
- DTCoreTextParagraphStyle *paragraphStyle = [DTCoreTextParagraphStyle paragraphStyleWithCTParagraphStyle:paraStyle];
-
- if (paragraphStyle.paragraphSpacing < self.paragraphStyle.paragraphSpacing)
+#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
+ if (___useiOS6Attributes)
{
- paragraphStyle.paragraphSpacing = self.paragraphStyle.paragraphSpacing;
+ NSParagraphStyle *paraStyle = [tmpString attribute:NSParagraphStyleAttributeName atIndex:paragraphRange.location effectiveRange:NULL];
- // make new paragraph style
- CTParagraphStyleRef newParaStyle = [paragraphStyle createCTParagraphStyle];
+ DTCoreTextParagraphStyle *paragraphStyle = [DTCoreTextParagraphStyle paragraphStyleWithNSParagraphStyle:paraStyle];
- // remove old (works around iOS 4.3 leak)
- [tmpString removeAttribute:(id)kCTParagraphStyleAttributeName range:paragraphRange];
-
- // set new
- [tmpString addAttribute:(id)kCTParagraphStyleAttributeName value:(__bridge_transfer id)newParaStyle range:paragraphRange];
+ if (paragraphStyle.paragraphSpacing < self.paragraphStyle.paragraphSpacing)
+ {
+ paragraphStyle.paragraphSpacing = self.paragraphStyle.paragraphSpacing;
+
+ // make new paragraph style
+ NSParagraphStyle *newParaStyle = [paragraphStyle NSParagraphStyle];
+
+ // remove old (works around iOS 4.3 leak)
+ [tmpString removeAttribute:NSParagraphStyleAttributeName range:paragraphRange];
+
+ // set new
+ [tmpString addAttribute:NSParagraphStyleAttributeName value:newParaStyle range:paragraphRange];
+ }
+ else
+#endif
+ {
+ CTParagraphStyleRef paraStyle = (__bridge CTParagraphStyleRef)[tmpString attribute:(id)kCTParagraphStyleAttributeName atIndex:paragraphRange.location effectiveRange:NULL];
+
+ DTCoreTextParagraphStyle *paragraphStyle = [DTCoreTextParagraphStyle paragraphStyleWithCTParagraphStyle:paraStyle];
+
+ if (paragraphStyle.paragraphSpacing < self.paragraphStyle.paragraphSpacing)
+ {
+ paragraphStyle.paragraphSpacing = self.paragraphStyle.paragraphSpacing;
+
+ // make new paragraph style
+ CTParagraphStyleRef newParaStyle = [paragraphStyle createCTParagraphStyle];
+
+ // remove old (works around iOS 4.3 leak)
+ [tmpString removeAttribute:(id)kCTParagraphStyleAttributeName range:paragraphRange];
+
+ // set new
+ [tmpString addAttribute:(id)kCTParagraphStyleAttributeName value:(__bridge_transfer id)newParaStyle range:paragraphRange];
+ }
+ }
}
}
-
+
return tmpString;
}

0 comments on commit a8abdbb

Please sign in to comment.