Skip to content

Instantly share code, notes, and snippets.

@uchuugaka
Forked from wess/gist:3278911
Created Nov 29, 2012
Embed
What would you like to do?
Tapping in fucking CoreText
// 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