Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AliSoftware committed Oct 2, 2013
2 parents becfc94 + 72efe35 commit 23330e7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions OHAttributedLabel/PrivateUtils/CoreTextUtils.h
Expand Up @@ -62,5 +62,6 @@ NSRange NSRangeFromCFRange(CFRange range);

CGRect CTLineGetTypographicBoundsAsRect(CTLineRef line, CGPoint lineOrigin);
CGRect CTRunGetTypographicBoundsAsRect(CTRunRef run, CTLineRef line, CGPoint lineOrigin);
CGRect CTRunGetTypographicBoundsForRangeAsRect(CTRunRef run, CTLineRef line, CGPoint lineOrigin, CFRange range, CGContextRef ctx);
BOOL CTLineContainsCharactersFromStringRange(CTLineRef line, NSRange range);
BOOL CTRunContainsCharactersFromStringRange(CTRunRef run, NSRange range);
10 changes: 10 additions & 0 deletions OHAttributedLabel/PrivateUtils/CoreTextUtils.m
Expand Up @@ -137,6 +137,16 @@ CGRect CTRunGetTypographicBoundsAsRect(CTRunRef run, CTLineRef line, CGPoint lin
height);
}

CGRect CTRunGetTypographicBoundsForRangeAsRect(CTRunRef run, CTLineRef line, CGPoint lineOrigin, CFRange range, CGContextRef ctx)
{
CGRect boundsOfRun = CTRunGetTypographicBoundsAsRect(run, line, lineOrigin);
CGRect boundsOfImageForRun = CTRunGetImageBounds(run, ctx, range);
return CGRectMake(boundsOfRun.origin.x + boundsOfImageForRun.origin.x,
boundsOfRun.origin.y,
boundsOfImageForRun.size.width,
boundsOfRun.size.height);
}

BOOL CTLineContainsCharactersFromStringRange(CTLineRef line, NSRange range)
{
NSRange lineRange = NSRangeFromCFRange(CTLineGetStringRange(line));
Expand Down
15 changes: 13 additions & 2 deletions OHAttributedLabel/Source/OHAttributedLabel.m
Expand Up @@ -656,8 +656,19 @@ -(void)drawActiveLinkHighlightForRect:(CGRect)rect
}
continue; // with next run
}

CGRect linkRunRect = CTRunGetTypographicBoundsAsRect(run, line, lineOrigins[lineIndex]);

// Fix for issue #136
CFRange fullRunRange = CTRunGetStringRange(run);
CFRange inRunRange;
inRunRange.location = (CFIndex)activeLinkRange.location - (CFIndex)fullRunRange.location;
inRunRange.length = (CFIndex)activeLinkRange.length;
if (inRunRange.location < 0) {
inRunRange.length += inRunRange.location;
inRunRange.location = 0;
}
// End Fix #136
CGRect linkRunRect = CTRunGetTypographicBoundsForRangeAsRect(run, line, lineOrigins[lineIndex], inRunRange, ctx);

linkRunRect = CGRectIntegral(linkRunRect); // putting the rect on pixel edges
linkRunRect = CGRectInset(linkRunRect, -1, -1); // increase the rect a little
if (CGRectIsEmpty(unionRect))
Expand Down

0 comments on commit 23330e7

Please sign in to comment.