2

我从 NSAttributedString 中获取单个字符的字形,然后使用 NSBezierPath 获取appendBezierPathWithGlyphs:count:inFont:并最终将扁平路径点输出到 NSArray(请参见下面的代码)以在 Quartz Composer 中使用 OpenGL 显示它们。

对于某些 NSFonts,包括标准字体(American Typewriter、Baskerville、...),字母完全错误(见下图)。

说我正在使用法语键盘和语言可能很重要。

NSBezierPath* path = [NSBezierPath bezierPath];

NSTextStorage *storage = [[[NSTextStorage alloc] initWithString:character] autorelease];
NSLayoutManager *manager = [[[NSLayoutManager alloc] init] autorelease];
NSTextContainer *container = [[[NSTextContainer alloc] init] autorelease];

[storage addLayoutManager:manager];
[manager addTextContainer:container];


NSRange glyphRange = [manager glyphRangeForTextContainer:container];
NSGlyph glyphArray[glyphRange.length];
NSUInteger glyphCount = [manager getGlyphs:glyphArray range:glyphRange];

[manager getGlyphs:glyphArray range:glyphRange];

// ---- Necesary
[path moveToPoint: NSMakePoint(0, 0)];


// STRANGE CHARACTERS
[path appendBezierPathWithGlyphs:glyphArray count:glyphCount inFont:selectedFont];

用宋体 与巴斯克维尔 有人知道这种行为的解释吗?有没有办法用这些字体找到正确的路径

4

1 回答 1

2

问题是您没有为您使用的字体生成字形-appendBezierPathWithGlyphs:count:inFont:。由于您没有将NSFontAttributeName属性设置NSTextStorage为字形,因此使用默认字体生成。

使用正确的字体创建您NSTextStorage的问题,您的问题将得到解决:

NSTextStorage *storage = [[[NSTextStorage alloc] initWithString:character
                                                     attributes:@{NSFontAttributeName : selectedFont}] autorelease];
于 2014-03-25T12:45:31.997 回答