Re: Drawing text with NSLayoutManager
Re: Drawing text with NSLayoutManager
- Subject: Re: Drawing text with NSLayoutManager
- From: Eric Wang <email@hidden>
- Date: Tue, 01 Jul 2003 15:25:38 -0400
on 6/28/03 12:28 PM, Brian Webster at email@hidden 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.
>
>
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.
Hi Brian,
Thanks for your reply. After much experimentation with NSLayoutManager, I
eventually came to the same conclusion. In order to get the glyphs
vertically aligned, I'd have to compensate for the horizontal advancement
NSLayoutManager itself performs. Repeatedly calling
drawGlyphsForGlyphRange:atPoint: and trying to position the drawing location
each time seems like the wrong way to go.
I tried drawing using Quartz (specifically CGContextShowTextAtPoint()), but
it seems to ignore the fact that I'm drawing into a flipped view. For
example, drawing at point 0,0 causes the text to be cut off from the top, so
I'd end up having to adjust the drawing point in order to compensate. I also
had some issues with the text being drawn really huge, which I had to work
around by adjusting the text matrix.
I get the sense from encountering these issues that Quartz might be too
low-level for my needs. I think I'll give ATSUI a try next. The ideal
solution to my problem would be to figure out how to subclass NSTypesetter
correctly and use that to lay out my text. That way I could avoid the
low-level text drawing APIs and stick with pure Cocoa, in turn getting the
functionality that the Cocoa text system provides for free. Unfortunately,
there isn't much documentation on how to write a custom typesetter, and the
default typesetting functionality is hidden behind a private AppKit class,
NSATSTypesetter. Hopefully, Panther will expose this.
Eric
_______________________________________________
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.