On Aug 16, 2011, at 12:59 PM, Nick Zitzmann wrote:

> 
> On Aug 16, 2011, at 9:09 AM, Ross Carter wrote:
> 
>> On Aug 15, 2011, at 6:19 PM, Nick Zitzmann wrote:
>> 
>>> Of course, if there is a better way of using the Cocoa text system to 
>>> layout multiple non-contiguous pages of text with margins, I'd like to hear 
>>> about it. Maybe it'll even solve the problem I'm having.
>> 
>> Well, it should just work without any fiddling of container or text view 
>> geometry. The Cocoa text system knows how much text will fit in a text 
>> container and  does a very good job of wrapping to the next container. It 
>> does not cut off lines of text (most of the time; some extreme fonts such as 
>> Zapfino might get clipped ascenders and descenders).
> 
> But how? I can't use a single NSTextView because this is for a view where 
> each text view corresponds to a single page of text, and so AFAICT text 
> containers and views must be created manually as the layout manager lays out 
> text.

Right. You do have to add and remove the text containers and text views as 
needed. What I meant was, you shouldn't need to do anything to insure that the 
text is drawn correctly in the views and flows correctly between the 
containers. What you are experiencing is an anomaly. The question is not how to 
make the Cocoa text system draw correctly, but rather what in this case is 
causing it to get confused.

I've been using NSTextView and friends in a multi-page layout for years, and 
Martin has too. I'm very curious what is causing this problem because I haven't 
seen it before. I'm particularly curious about your saying that after you add a 
page, "At that point, their frame sizes are synchronized, and the text 
container is set to track the text view's width but not its height." I don't 
understand why this is necessary. Aren't all text views the same size? Why do 
you synchronize their frames? (Or did you mean just the tv origins?) If you 
create the tv and the tc with the correct geometry, then when you add the tc to 
the layout manager it should all draw correctly.

If the tc is not tracking the tv height, and you change the tv height to make 
it shorter, then the tc will be taller than the tv and text will get clipped.

Also, FWIW, my experience has led me to take these precautions:

First, beware the delegate method 
-layoutManager:didCompleteLayoutForTextContainer:atEnd:. That method can fire 
when layout is still underway. The only safe thing to do with that method is 
add pages, as you do. It is not a good place to to remove pages.

Second, messaging the text system while layout is happening can wreck layout, 
and there is no way to know when layout is underway. Therefore, when sending 
any message that might affect layout, wrap the call in 
performSelector:withObject:after delay:. For example, to remove pages you could 
subclass NSLayoutManager and override 
textStorage:edited:range:changeInLength:invalidatedRange: to send something 
like [someController performSelector:@selector(checkForRemovablePages:) 
withObject:self afterDelay:0]. 

Cheers,

Ross
_______________________________________________

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