• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Ascertaining the top line in a view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ascertaining the top line in a view


  • Subject: Re: Ascertaining the top line in a view
  • From: Fritz Anderson <email@hidden>
  • Date: Fri, 7 Nov 2003 11:05:25 -0600

For the first character of each paragraph,
charRange is NSMakeRange(first char offset, 1)
noRange is NSMakeRange(NSNotFound, 0)
container is [theTextView container]
layoutManager is [theTextView layoutManager]
unsigned rectCount
NSRect * rects = [layoutManager rectArrayForCharacterRange: charRange
withinSelectedCharacterRange: noRange
inTextContainer: container rectCount: &rectCount

rectCount will always be 1. NSMinY(rects[0]) will be the top of the first line in the paragraph.

For all the line-fragment rectangles,

allChars is NSMakeRange(0, [textStorage length])
allGlyphs is allChars converted to a glyph range by layoutManager
currRange starts at NSMakeRange(0, 0)
while NSMaxRange(currRange) < NSMaxRange(allGlyphs)
currFragmentRect is [layoutManager lineFragmentRectForGlyphAtIndex: currRange.location
effectiveRange: &currRange];
process currFragmentRect. There may be more than one per line; look for the rect at the left margin
currRange.location = NSMaxRange(currRange)
currRange.length = 0;

-- F

On 7 Nov 2003, at 1:11 AM, Vincent Coetzee wrote:

Hi there

I have a requirement for drawing line numbers next to a text view. Obviously the easiest way to do this in Cocoa is by means of a subclass of NSRuler. How all this works I can figure out, what is confusing me is how to ascertain the line number that is currently at the top of the NSTextView. In the case of unformatted text, i.e. one line == one paragraph, the number of paragraphs in the NSTextStorage is the number of lines, but how does one ascertain the relative positions of paragraphs with respect to the top of the NSTextView. I have spent hours reading NSTextStorage, NSLayoutManager, NSTextContainer, NSText, and NSTextView documentation without being able to figure this out. Has anyone any more in-depth knowledge on this subject that perhaps suggested a route ?
_______________________________________________
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.

  • Follow-Ups:
    • Re: Ascertaining the top line in a view
      • From: Vincent Coetzee <email@hidden>
References: 
 >Ascertaining the top line in a view (From: Vincent Coetzee <email@hidden>)

  • Prev by Date: Re: Key down issue
  • Next by Date: Re: NSButton w Image not redrawing
  • Previous by thread: Ascertaining the top line in a view
  • Next by thread: Re: Ascertaining the top line in a view
  • Index(es):
    • Date
    • Thread