2

NSAttributedString から個々の文字のグリフを取得してから、NSBezierPath を取得しappendBezierPathWithGlyphs:count:inFont:、最終的に平坦化されたパス ポイントを NSArray に出力して (以下のコードを参照)、Quartz Composer で OpenGL を使用して表示します。

標準フォント (American Typewriter、Baskerville など) を含む一部の NSFont では、文字が完全に間違っています(下の画像を参照)。

私はフランス語のキーボードと言語で作業していると言うことが重要かもしれません。

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 に答える