Re: Drawing text with NSLayoutManager
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.