• 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: Newbie: NSGlyph <-> unicode ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie: NSGlyph <-> unicode ?


  • Subject: Re: Newbie: NSGlyph <-> unicode ?
  • From: Douglas Davidson <email@hidden>
  • Date: Tue, 8 Jan 2002 16:01:29 -0800

On Monday, January 7, 2002, at 03:31 PM, Anabelle Masour wrote:

I don't know if this is the right list to ask this but i have this problem.
I want to convert a number of unicode chars to NSGlyph for use with NSBezierPath. It would be good if I could convert a NSGlyph back too. The font to use is variable.
I do not find a method to convert between the two.
Can anybody help me please ?

Here's what I wrote the last time this came up:

Certainly there is public API for getting NSGlyphs. NSLayoutManager defines

- (NSGlyph)glyphAtIndex:(unsigned)glyphIndex;
- (NSGlyph)glyphAtIndex:(unsigned)glyphIndex isValidIndex:(BOOL *)isValidIndex;
- (unsigned)getGlyphs:(NSGlyph *)glyphArray range:(NSRange)glyphRange;

To be sure, it is necessary to set up an NSLayoutManager instance in order to use these; there is no way, for example, to convert a single character into a glyph. That is because, as you note, glyph management is quite complex; the mapping from characters to glyphs is many-to-many, and in general requires access to the whole string, rather than a single character, for correctness. The NSLayoutManager will also cache the glyphs for you.

For an example of using NSLayoutManager without an NSTextView, see the CircleView example. That example uses the layout manager for both glyph generation and layout; to perform glyph generation without layout, you would simply call some of the methods listed above rather than the methods glyphRangeForTextContainer:, usedRectForTextContainer:, and drawGlyphsForGlyphRange:atPoint: used in the example.

Remember that the font that should be used to display the glyph is not necessarily the font you supplied in your text storage. If the font you supply does not have a glyph for a particular character, the text system will find an appropriate font during font fixing. You will need to inspect the text storage to find the fonts actually used.

Douglas Davidson


References: 
 >Newbie: NSGlyph <-> unicode ? (From: "Anabelle Masour" <email@hidden>)

  • Prev by Date: Re: Newbie: NSGlyph <-> unicode ?
  • Next by Date: Find Function in text
  • Previous by thread: Re: Newbie: NSGlyph <-> unicode ?
  • Next by thread: disabling TableView
  • Index(es):
    • Date
    • Thread