Question

I'm getting glyphs of individual characters from an NSAttributedString, then get the NSBezierPath with appendBezierPathWithGlyphs:count:inFont: and finally output the flattened path points to a NSArray (see my code below) to display them with OpenGL in Quartz Composer.

For some NSFonts, including standard ones (American Typewriter, Baskerville, ...), the letters are totally wrong (see the image below).

It might be important to say that I'm working with French keyboard and language.

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];

With Arial With Baskerville Does someone knows the explanation of this behavior ? Is there a solution to get the right path with these fonts ?

Was it helpful?

Solution

The problem is that you don't generate the glyphs for the font you use in -appendBezierPathWithGlyphs:count:inFont:. As you don't set NSFontAttributeName attribute to the NSTextStorage the glyphs are generated with default font.

Create your NSTextStorage with correct font and your problem will be solved :

NSTextStorage *storage = [[[NSTextStorage alloc] initWithString:character
                                                     attributes:@{NSFontAttributeName : selectedFont}] autorelease];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top