Skip to content

Commit

Permalink
Merge pull request Cocoanetics#166 from tonycn/master
Browse files Browse the repository at this point in the history
Updated: use __unsafe_unretained and fix key from CTParagraphStyleRef
  • Loading branch information
odrobnik committed Apr 10, 2012
2 parents 30859d4 + 33319d1 commit 0c38cf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Core/Source/DTAttributedTextContentView.m
Expand Up @@ -660,7 +660,7 @@ - (DTCoreTextLayoutFrame *)layoutFrame

if (_delegateFlags.delegateSupportsNotificationBeforeTextBoxDrawing)
{
__block __weak DTAttributedTextContentView *weakself = self;
__unsafe_unretained DTAttributedTextContentView *weakself = self;

[_layoutFrame setTextBlockHandler:^(DTTextBlock *textBlock, CGRect frame, CGContextRef context, BOOL *shouldDrawDefaultBackground) {
BOOL result = [weakself->_delegate attributedTextContentView:weakself shouldDrawBackgroundForTextBlock:textBlock frame:frame context:context forLayoutFrame:weakself->_layoutFrame];
Expand Down
21 changes: 18 additions & 3 deletions Core/Source/DTCoreTextParagraphStyle.m
Expand Up @@ -42,6 +42,23 @@ + (DTCoreTextParagraphStyle *)defaultParagraphStyle
return [[DTCoreTextParagraphStyle alloc] init];
}

+ (NSString *)niceKeyFromParagraghStyle:(CTParagraphStyleRef)ctParagraphStyle {

// this is naughty: CTParagraphStyle has a description
NSString *key = [(__bridge id)ctParagraphStyle description];

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"0x[0123456789abcdef]{1,8}"
options:NSRegularExpressionCaseInsensitive
error:nil];

NSString *newKey = [regex stringByReplacingMatchesInString:key
options:0
range:NSMakeRange(0, [key length])
withTemplate:@""];

return newKey;
}

+ (DTCoreTextParagraphStyle *)paragraphStyleWithCTParagraphStyle:(CTParagraphStyleRef)ctParagraphStyle
{
DTCoreTextParagraphStyle *returnParagraphStyle = NULL;
Expand All @@ -58,9 +75,7 @@ + (DTCoreTextParagraphStyle *)paragraphStyleWithCTParagraphStyle:(CTParagraphSty
dispatch_semaphore_wait(selfLock, DISPATCH_TIME_FOREVER);
{

// this is naughty: CTParagraphStyle has a description
NSString *key = [(__bridge id)ctParagraphStyle description];

NSString *key = [self niceKeyFromParagraghStyle:ctParagraphStyle];
returnParagraphStyle = [_paragraphStyleCache objectForKey:key];

if (!returnParagraphStyle)
Expand Down

0 comments on commit 0c38cf0

Please sign in to comment.