• 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: Vectorising text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vectorising text


  • Subject: Re: Vectorising text
  • From: Douglas Davidson <email@hidden>
  • Date: Mon, 22 Oct 2001 11:26:46 -0700

On Monday, October 22, 2001, at 10:15 AM, Ken Tabb wrote:

is it possible in Cocoa (/ Quartz) to vectorise text, so that if text is
typed in, you can end up with a set of NSBezierPaths? I'm deliberating
over the design of a freeware vector drawing app which allows (for
instance) gradients on text, text on a path etc. and, although it would
make later changing the font of some text a pain, it seems the logical
way to do this in Cocoa is to make everything an NSBezierPath. Or maybe
I'm missing something obvious here and you can already do this sort of
thing while keeping the object as editable text?

NSBezierPath has methods for obtaining a path corresponding to a glyph or sequence of glyphs. You can obtain glyphs from NSLayoutManager, and I will describe how to do that. What this would give you is means to obtain a path from given text, which you could then presumably modify as desired and draw yourself. What it does not do is supply everything else necessary for editing the text while it is so modified. A standard NSTextView allows text to be displayed and edited in its usual form, not as modified bezier paths. For example, if you wanted to make text editable while it was displayed along a path, you would need to consider how to display selections, insertion points, and so on.

Here is what I have written about how to get glyphs from NSLayoutManager: NSLayoutManager defines

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

It is necessary to set up an NSLayoutManager instance in order to use these; they do not expose means, for example, to convert a single character into a glyph. That is because 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


  • Prev by Date: Re: Preferred vector art file format?
  • Next by Date: Re: Transparent fill, opaque stroke
  • Previous by thread: Re: Vectorising text
  • Next by thread: menu things
  • Index(es):
    • Date
    • Thread