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

Re: Drawing text with NSLayoutManager


  • Subject: Re: Drawing text with NSLayoutManager
  • From: Douglas Davidson <email@hidden>
  • Date: Mon, 30 Jun 2003 09:39:45 -0700

On Saturday, June 28, 2003, at 09:28 AM, Brian Webster wrote:

Well, the reason that your glyphs are being drawn like that is because the point that you pass into drawGlyphsForGlyphRange:atPoint: is the point at which the first glyph in the layout manager is to be located, not the first glyph in the range that you've specified. So in your example, you would need to move the point to the left by the width of the previous glyph each time you draw the next glyph to have them aligned vertically.

That's not exactly right either. The point you pass in is the origin of the container in which the glyphs are laid out. If you're trying to draw the glyphs as they would ordinarily be laid out, then you would pass in the same point each time you draw. If you want to move the glyphs around, you can change the point, or you can change the current transform (which also allows rotation, shearing, dilatation, etc.). Take a look at /Developer/Examples/AppKit/CircleView.

If you really do want to draw glyphs one at a time, using CoreGraphics may well speed up your display. I don't know exactly what the speed implications of using NSLayoutManager in this way are, but I could certainly imagine there being a speed hit, especially for large amounts of text.

There are speed implications, but not quite of that sort. When you use NSLayoutManager, it performs glyph generation and layout lazily as needed, then stores the generated information until the text changes or you manually invalidate it. If the text hasn't changed since glyph generation and layout were last performed, then the call to display the glyphs will not need to do any of that work. It does need to do a certain amount of work to determine whether e.g. underlines need to be drawn, and to draw them if necessary, but that work is more or less independent of the amount of text (although it would depend on the amount of underlined text).

So while this may indeed be an appropriate occasion for using CoreGraphics directly to display glyphs, the overhead of using NSLayoutManager instead is probably not excessive. However, it is certainly possible to use NSLayoutManager to generate glyphs and then use CoreGraphics rather than NSLayoutManager to display them. That would be something I would especially consider in cases in which the layout information from NSLayoutManager is not being used.

There is one subtle point to keep in mind, and that is that glyph generation and layout are separate steps in the Cocoa text system, and that layout may change the already-generated glyphs. For example, if hyphenation is used, then hyphens may be inserted during layout. This is not the only example, however; there are many writing systems and fonts in which there are differences between the forms used for certain glyphs at the end of a line as opposed to the middle of a line, and these sorts of modifications can be considered only at layout time. So the glyphs you obtain may differ depending on whether layout has been performed, and on what container size you use.

Douglas Davidson
_______________________________________________
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: Drawing text with NSLayoutManager (From: Brian Webster <email@hidden>)

  • Prev by Date: Re: NSProgressIdicator Image Problems
  • Next by Date: NSWindow/NSPanel UI-violating question
  • Previous by thread: Re: Drawing text with NSLayoutManager
  • Next by thread: JNLP file to launch Java Web Start
  • Index(es):
    • Date
    • Thread