Re: Drawing text with NSLayoutManager
Re: Drawing text with NSLayoutManager
- Subject: Re: Drawing text with NSLayoutManager
- From: Douglas Davidson <email@hidden>
- Date: Wed, 2 Jul 2003 13:10:56 -0700
On Wednesday, July 2, 2003, at 08:31 AM, Eric Wang wrote:
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.
Yes, NSLayoutManager's notion of drawing at a point differs from that
of CGContextShowGlyphsAtPoint(). As I said, the layout manager method
takes as its point argument the origin of the container within which
the text is laid out. The CG function takes as its point argument the
location of the first glyph, which is quite different. To convert from
one to the other, you need to add the location of the first glyph
within its line fragment (from NSLayoutManager's
locationForGlyphAtIndex:) and the origin of the line fragment (from
NSLayoutManager's lineFragmentRectForGlyphAtIndex:effectiveRange:).
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.
No, that's not really correct. NSLayoutManager is so called because it
manages all of the processes involved; the actual work of glyph
generation and typesetting is devolved onto two subsidiary classes,
NSGlyphGenerator and NSTypesetter. NSGlyphGenerator is private in
Jaguar, however. I went into all of this in some detail in my talk at
this year's WWDC, and for that matter also at last year's WWDC.
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.