• 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: Invisible characters in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Invisible characters in NSTextView


  • Subject: Re: Invisible characters in NSTextView
  • From: Peter Borg <email@hidden>
  • Date: Mon, 3 Jan 2005 10:40:57 +0100

Hi!

As far as I know setShowsControlCharacters/setShowsInvisibleCharacters
does not work or they only work with some special fonts. But it is
fairly easy to implement it yourself (but it does make it slightly
slower). What you need to do is use your own NSLayoutManager in your
NSTextView and override -
(void)drawGlyphsForGlyphRange:(NSRange)glyphRange
atPoint:(NSPoint)containerOrigin and there basically check if the
glyph is one that you want visible and, if so, draw it yourself.
Something like this:

- (void)drawGlyphsForGlyphRange:(NSRange)glyphRange
atPoint:(NSPoint)containerOrigin
{
    if (showInvisibleCharacters) {
		completeString = [[self textStorage] string];
		lengthToRedraw = NSMaxRange(glyphRange);

		for (index = glyphRange.location; index < lengthToRedraw; index++) {
			characterToCheck = [completeString characterAtIndex:index];
			if (characterToCheck == '\t') {
				pointToDrawAt = [self locationForGlyphAtIndex:index];
				glyphFragment = [self lineFragmentRectForGlyphAtIndex:index
effectiveRange:NULL];
				pointToDrawAt.x += glyphFragment.origin.x;
				pointToDrawAt.y = glyphFragment.origin.y;
				[tabCharacter drawAtPoint:pointToDrawAt withAttributes:attributes];

			}
		}
    }

    [super drawGlyphsForGlyphRange:glyphRange atPoint:containerOrigin];
}

You can check out some complete workable code at
http://smultron.sourceforge.net (the SMLLayoutManager class).

Peter


On Sun, 2 Jan 2005 18:36:56 -0800, Jean Bovet
<email@hidden> wrote:
> Hello all!
>
> Is it possible to show invisible/controls characters (like carriage
> return, tab, etc) in a NSTextView using
> setShowsControlCharacters/setShowsInvisibleCharacters ? I have tried
> both methods but nothing is displayed: is this related to the font I'm
> using ?
>
> Thanks.
>
> Jean
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Invisible characters in NSTextView
      • From: Jean Bovet <email@hidden>
    • Re: Invisible characters in NSTextView
      • From: glenn andreas <email@hidden>
References: 
 >Invisible characters in NSTextView (From: Jean Bovet <email@hidden>)

  • Prev by Date: MySQl Manager source
  • Next by Date: how to write programatically greek letters to an NSTextField? solved
  • Previous by thread: Invisible characters in NSTextView
  • Next by thread: Re: Invisible characters in NSTextView
  • Index(es):
    • Date
    • Thread