Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wess
Created August 6, 2012 22:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wess/3278911 to your computer and use it in GitHub Desktop.
Save wess/3278911 to your computer and use it in GitHub Desktop.
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