• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting glyphs and their outlines
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting glyphs and their outlines


  • Subject: Re: Getting glyphs and their outlines
  • From: Steve Sims <email@hidden>
  • Date: Tue, 6 Apr 2004 12:01:27 -0400

Hi John,

Thanks for the advice.

I had actually solved this one with the help of a couple of other people on this list a little while ago now and I too ended up using the basic technique you have below. I then moved on to strings, which is slightly more complicated, since you need to use the text layout objects. This is basically what you need though:


NSTextStorage *textStore = [[NSTextStorage alloc] initWithString:textString];
NSTextContainer *textContainer = [[NSTextContainer alloc] init];
NSLayoutManager *myLayout = [[NSLayoutManager alloc] init];
[myLayout addTextContainer:textContainer];
[textStore addLayoutManager:myLayout];
[textStore setFont:font];

// Work out how many glyphs we've got and get them all
NSRange glyphRange = [myLayout glyphRangeForTextContainer:textContainer];
NSGlyph glyphArray[glyphRange.length];
unsigned glyphCount = [myLayout getGlyphs:glyphArray range:glyphRange];
NSBezierPath bezier = [NSBezierPath bezierPath];
[bezier moveToPoint:(NSPoint){0.,0.}];

// Add in all the beziers for our glyphs
[bezier appendBezierPathWithGlyphs:glyphArray count:glyphCount inFont:font];


This code assumes that textString and font are already set up.

If you want to render the glyphs one at a time it's slightly more complicated, since you'll also need to work out where to render the glyph. To do this you'll need to use the glyphAtIndex and locationForGlyphAtIndex calls provided by NSLayoutManager and the notShownAttributeForGlyphAtIndex is also useful. You may also wish to render glyphs into a temporary bezier and then use the NSBezierPath appendBezierPath call to add it to your main bezier.

Enjoy! :-)

Steve




On 6 Apr 2004, at 00:32, John Labovitz wrote:

On Mar 29, 2004, at 9:01 AM, Steve Sims wrote:

I want to do something that I feel is fairly simple, namely get a glyph for a character in a particular font, and then grab its outline.

(Sorry to respond late, but I'm behind on the mailing list.)

I just did this yesterday, when I wrote my first screensaver. Here's more or less what I did (consolidated from several methods, so I may have typos):

// get the glyph for the "g" character from Helvetica

NSFont *font = [NSFont fontWithName:@"Helvetica" size:100.0];
NSGlyph glyph = [font glyphWithName:@"g"];

// render the glyph into a bezier path

NSBezierPath *path = [NSBezierPath bezierPath];
[path moveToPoint:NSMakePoint(0, 0)];
[path appendBezierPathWithGlyph:glyph inFont:font];

// go through each point in the path (if you need to)

for (i = 0; i < [path elementCount]; i++) {
NSBezierPathElement elemType;
NSPoint points[3];

elemType = [path elementAtIndex:i associatedPoints:points];

// look at the point -- see docs for above call for details
}

Hope this helps.

--
John Labovitz Consulting, LLC
http://mac.johnlabovitz.com
email@hidden
+1 503.949.3492
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Getting glyphs and their outlines (From: John Labovitz <email@hidden>)

  • Prev by Date: [OT] Any Cocoa early-bird sessions?
  • Next by Date: Re: Interface Builder Is Driving Me Nuts
  • Previous by thread: Re: Getting glyphs and their outlines
  • Next by thread: Interface Builder Is Driving Me Nuts
  • Index(es):
    • Date
    • Thread