Re: Drawing text with NSLayoutManager
Re: Drawing text with NSLayoutManager
- Subject: Re: Drawing text with NSLayoutManager
- From: Eric Wang <email@hidden>
- Date: Wed, 02 Jul 2003 11:31:01 -0400
Hi Douglas,
Thanks for your thoughts on this subject.
>
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.
That is the approach I am currently taking. My main problem is that Quartz's
notion of a point seems to differ from that of NSLayoutManager's. For
example, drawing into a flipped view by calling CGContextShowGlyphsAtPoint()
with a point of 0,0 causes the text to be cut off from the top. Moving the
drawing point lower to a point like 0,10 causes the text to show up, however
I can't seem to find a way to determine the size of text drawn with Quartz
so that I can accurately position it. How does NSLayoutManager/NSTypesetter
do it? The documentation seems to suggest that they just make Quartz calls
to do their drawing, so they must somehow be able to determine the
dimensions of text drawn using Quartz.
>
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.
Thanks for elucidating that aspect of the Cocoa text system. Perhaps
NSLayoutManager might be more aptly named NSGlyphGenerator, and NSTypesetter
named NSLayoutManager, since NSLayoutManager's primary responsibility is
glyph generation and it seems to just pass its layout responsibilities to
NSTypesetter.
In any case, your explanation highlights one of the reasons why I'm hesitant
to use Quartz to do my text drawing. The Cocoa text system gives you so many
things for free that I'd rather use it to do my drawing so I don't miss out
on any of the functionality it provides. Unfortunately, it seems the only
way I'd be able to control layout using the Cocoa text system is by writing
a custom typesetter, which is a mystery to me right now. Hopefully, the
documention for this will improve over time.
Eric Wang
_______________________________________________
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.