Tag: 核心文字

核心文本在iOS中计算字母框架

我需要为NSAttributedString(核心文本)中的每个字符(字形)计算确切的边界框。 把一些用来解决类似问题的代码(核心文本select等)放在一起后,结果是相当不错的,但是只有几帧(红色)正在计算正确: 大多数框架是水平或垂直错位(微小的一点)。 这是什么原因? 我怎样才能完善这个代码? -(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); […]