• 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: Customized NSTextView drawing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Customized NSTextView drawing


  • Subject: Re: Customized NSTextView drawing
  • From: Douglas Davidson <email@hidden>
  • Date: Mon, 10 May 2004 09:59:24 -0700

On May 10, 2004, at 9:03 AM, Mark Alldritt wrote:

I have some Carbon/WASTE code that does syntax highlighting that I want to
port to Cocoa. The approach I use is to hook into WASTE's drawing code to
syntax color "on-the-fly". This avoids the overheads and delays of having
to style all the text as the user types.

How would one go about this with Cocoa's NSTextView/NSTextStorage
combination? I've poked around in the documentation, but I cannot find a
method that I need to override that delivers styled text runs to NSTextView
for rendering. Where should I be looking?

The Cocoa text system offers several mechanisms that you could use. First, of course, you could alter the colors in the NSTextStorage. That would change the actual contents of the document, and would give you colors that would be persistent during saving or copy/pasting as rich text. It would also incur extra processing costs, as you describe.

A second alternative would be to use NSLayoutManager's temporary attributes. These are non-persistent, drawing-only attributes that the layout manager stores, manages, and displays for you. That is probably the simplest way of doing what you suggest. Look in the NSLayoutManager documentation for more information.

Finally, you can subclass NSLayoutManager and override certain of the drawing methods, since it is NSLayoutManager that actually prepares the glyphs for rendering by Quartz. The basic drawing methods are -drawBackgroundForGlyphRange:atPoint: and -drawGlyphsForGlyphRange:atPoint:. The latter divides the glyphs up into runs and then calls showPackedGlyphs:length:glyphRange:atPoint:font:color: printingAdjustment:. If you want to do extra drawing behind or before the glyphs, then you would probably override one of the former two methods. If you merely want to change the color used for the glyphs, then you would probably override the latter. However, temporary attributes are probably easier if that is all you need to do.

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.


  • Follow-Ups:
    • Re: Customized NSTextView drawing
      • From: Mark Alldritt <email@hidden>
References: 
 >Customized NSTextView drawing (From: Mark Alldritt <email@hidden>)

  • Prev by Date: Re: use of c select() style events with the objc run loop
  • Next by Date: Re: use of c select() style events with the objc run loop
  • Previous by thread: Customized NSTextView drawing
  • Next by thread: Re: Customized NSTextView drawing
  • Index(es):
    • Date
    • Thread