Re: Font With NSBezierPath Help
Re: Font With NSBezierPath Help
- Subject: Re: Font With NSBezierPath Help
- From: Robert Clair <email@hidden>
- Date: Sun, 23 Jan 2005 17:38:52 -0500
<x-tad-bigger>So I've tried a bunch of stuff, for instance:
NSGlyph* gly = [musicFont glyphIndexForCharacter:'A'];
NSConvertGlyphsToPackedGlyphs(gly, 1, [musicFont glyphPacking], (char*) gly);
but that explodes,
</x-tad-bigger>
I imagine it would, -glyphIndexForCharacter: isn't a method for NSFont in any version
of the AppKit I've ever seen. Where did you get it ?
Two ways:
1) You could set up an attributed string and the use the attributed string's -drawAtPoint: method.
But this is horribly slow, and since you are trying to draw music symbols, let's assume you want
draw them one at a time in arbitrary locations. Then:
2)
NSFont* myFont = // whatever
NSPoint initialPoint = // whatever
NSGlyhph glyph = // get the glyph. Where ? Good question...
NSImage* dummyImage = [[NSImage alloc] initWithSize: NSMakeSize( 100, 100 )];
NSBezierPath* path = [NSBezierPath bezierPath];
[path moveToPoint: initalPoint];
[dummyImage lockFocus];
[path appendBezierPathWithGlyphs:&glyph count: 1 inFont: myFont];
[dummyImage unlockFocus];
[dummyImage release];
you can then fill the path:
NSColor* myColor = //whatever
[myColor set];
[path fill];
The dummyImage business is because, while the docs unhelpfully neglect to mention this,
appendBezierPathWithGlyphs:count:inFont: doesn't work unless you have locked focus on
something (it doesn't seem to matter what).
The only trick to this is finding the glyph (an unsigned int) corresponding to the symbol you want.
This isn't easy even for a normal font. IIRC the docs somewhere tell you "look it up for yourself."
Music fonts are even worse (at least the ones I have - the ones that Finale and Sibelius install):
they have weird encodings - random glyphs stuck in the unicode positions belonging
to parts of the roman alphabet and such. Trial and error ?
.........Bob Clair
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden