I'm trying to get the location of glyphs in an NSLayoutManager
, but on a few isolated occasions I'm getting what appears to be incorrect values.
For example: two f
's together in Helvetica Neue size 16. The x value of the 2nd f
should be around 4, but I'm getting 9.232000..? Anyone know why this is?
NSString *lettersString = @"ff";
NSDictionary *attrsDictionary = @{
NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:16]
};
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:lettersString attributes:attrsDictionary];
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:attributedString];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager:layoutManager];
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:CGSizeMake(100, 100)];
textContainer.lineFragmentPadding = 0;
[layoutManager addTextContainer:textContainer];
CGPoint location = [layoutManager locationForGlyphAtIndex:1];
// location.x == 9.232000