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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to