Re: calculating line heights in a NSTextView
Re: calculating line heights in a NSTextView
- Subject: Re: calculating line heights in a NSTextView
- From: Douglas Davidson <email@hidden>
- Date: Tue, 21 May 2002 14:34:57 -0700
On Tuesday, May 21, 2002, at 01:59 PM, Scott Royston wrote:
Anyone have any pointers on how to calculate each line's height in a
NSTextView?
Looking through the documentation, the only things that look promising
are the LayoutManager's lineFragmentUsedRectForGlyphAtIndex functions,
or maybe the paragraph attributes in the TextStorage...
The layout manager will tell you the positioning and size of each line
within the container, via
lineFragmentRectForGlyphAtIndex:effectiveRange: and
lineFragmentUsedRectForGlyphAtIndex:effectiveRange:. The difference
between the two is that the first tells you the entire rect chosen by
the text container for the line, while the second tells you how much of
that line is actually occupied by glyphs.
You can iterate through these using NSMaxRange() on the effective glyph
range to tell you where the next line starts. Keep in mind that
everything is in container coordinates, not view coordinates; to convert
to view coordinates, you would add the NSTextView's
textContainerOrigin. Of course, this doesn't affect sizes, only
positions.
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.