• 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
Properly wrapping non-contiguous NSTextViews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Properly wrapping non-contiguous NSTextViews


  • Subject: Properly wrapping non-contiguous NSTextViews
  • From: Nick Zitzmann <email@hidden>
  • Date: Fri, 12 Aug 2011 16:23:17 -0600

I've got a problem that has been driving me nuts all day. I tried searching around and didn't see anything that helped.

I have a series of non-contiguous NSTextViews (not to be confused with non-contiguous NSLayoutManager layout), with each text view representing a single page, and each text view has one NSTextContainer. There is one NSLayoutManager and one NSTextStorage behind each text view. When each text view & container is created, it is set to a size equal to the size of a page minus some margins.

I've found out that the last line of a text view can get cut off at the bottom, so after the text storage is filled out, I wrote this loop to lay out each text container and resize the text view to be smaller than the cut-off text:

for (i = 0UL ; i < self.layoutManager.textContainers.count ; i++)
{
	NSTextContainer *tc = [self.layoutManager.textContainers objectAtIndex:i];
	NSTextView *tv = tc.textView;
	NSRect usedRect;
	NSSize containerSize;

	(void)[self.layoutManager glyphRangeForTextContainer:tc];	// force layout to occur now
	usedRect = [self.layoutManager usedRectForTextContainer:tc];
	containerSize = tc.containerSize;

	if (usedRect.size.height > containerSize.height)	// if true, then we're cutting off some text
	{
		NSRect tvFrame = tv.frame;

		tvFrame.size.height = containerSize.height-(usedRect.size.height-containerSize.height);
		[tv setFrameSize:tvFrame.size];
	}
}

That had the effect of not displaying any cut-off text, but there's a problem - the cut-off text is still "laid out" in the view in a place where users won't see it. I was expecting this to push the now-invisible line off to the next text container/view the next time layout is performed, but it doesn't happen. If I make the height one or two pixels smaller, then the invisible line does bounce to the next text view, but then text gets cut off once again.

So how do I prevent NSLayoutManager from drawing cut-off glyphs in a series of non-contiguous text views? Yes, I did make sure that the text container's size tracks the text view's size.

Nick Zitzmann
<http://www.chronosnet.com/>

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Properly wrapping non-contiguous NSTextViews
      • From: Ross Carter <email@hidden>
  • Prev by Date: Core Animation for Dummies?
  • Next by Date: Re: Core Animation for Dummies?
  • Previous by thread: Re: Core Animation for Dummies?
  • Next by thread: Re: Properly wrapping non-contiguous NSTextViews
  • Index(es):
    • Date
    • Thread