我需要为NSAttributedString(Core Text)中的每个字符(字形)计算精确的边界框.在整理了一些用于解决类似问题的代码(核心文本选择等)之后,结果非常好,但只有少数帧(红色)正在被正确计算:

大多数帧都是水平或垂直错位(微小位).这是什么原因?我怎样才能完善这段代码?:
-(void)recalculate{
// get characters from NSString
NSUInteger len = [_attributedString.string length];
UniChar *characters = (UniChar *)malloc(sizeof(UniChar)*len);
CFStringGetCharacters((__bridge CFStringRef)_attributedString.string, CFRangeMake(0, [_attributedString.string length]), characters);
// allocate glyphs and bounding box arrays for holding the result
// assuming that each character is only one glyph, which is wrong
CGGlyph *glyphs = (CGGlyph *)malloc(sizeof(CGGlyph)*len);
CTFontGetGlyphsForCharacters(_font, characters, glyphs, len);
// get bounding boxes for glyphs
CTFontGetBoundingRectsForGlyphs(_font, kCTFontDefaultOrientation, glyphs, _characterFrames, len);
free(characters); free(glyphs);
// Measure how mush specec will be needed for this …Run Code Online (Sandbox Code Playgroud)