Created
August 6, 2012 22:12
-
-
Save wess/3278911 to your computer and use it in GitHub Desktop.
Tapping in fucking CoreText
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A small chunk of it. | |
- (void)tapGestureAction:(UITapGestureRecognizer *)gesture | |
{ | |
CGPoint location = [gesture locationInView:self]; | |
_linkLocation = location; | |
location.y += (ARTICLE_BODY_FONT_SIZE / lineHeightFactor); | |
CFArrayRef lines = CTFrameGetLines(_frame); | |
CGPoint origins[CFArrayGetCount(lines)]; | |
CTFrameGetLineOrigins(_frame, CFRangeMake(0, 0), origins); | |
CTLineRef line = NULL; | |
CGPoint lineOrigin = CGPointZero; | |
for (int i= 0; i < CFArrayGetCount(lines); i++) | |
{ | |
CGPoint origin = origins[i]; | |
CGPathRef path = CTFrameGetPath(_frame); | |
CGRect rect = CGPathGetBoundingBox(path); | |
CGFloat y = rect.origin.y + rect.size.height - origin.y; | |
if ((location.y >= y) && (location.x >= origin.x)) | |
{ | |
line = CFArrayGetValueAtIndex(lines, i); | |
lineOrigin = origin; | |
} | |
} | |
location.x -= lineOrigin.x; | |
CFIndex index = CTLineGetStringIndexForPosition(line, location); | |
for (BJLinkObject *link in _links) | |
{ | |
if (((index >= [link range].location) && (index <= ([link range].length + [link range].location)))) | |
NSLog(@"LINK: %@", [self.aHrefDictionary objectForKey:link.string]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment