Re: Suggestions on text display problem
Re: Suggestions on text display problem
- Subject: Re: Suggestions on text display problem
- From: Douglas Davidson <email@hidden>
- Date: Mon, 29 Mar 2004 10:23:35 -0800
On Mar 28, 2004, at 5:00 PM, Scott Thompson wrote:
What I want is two text views that are both displaying the same string
(the same NSTextStorage object) but I want the attributes displayed
differently in each view. For example, one of the views might display
all the text attributes except fix the font to 12 point Time while the
other view will display the text in it's full glory with arbitrary
font changes in the glyph range.
From reading the Text System documentation, I gather that what I want
to do is have a single NSTextStorage that has more than one
NSLayoutManager. Each Layout Manager, in turn, will have it's own
NSTextContainer and NSTextView. No problem it was almost spooky how
easy it was to set up a pair of views that both display the same
NSTextStorage object so that the changes in one view are reflected,
magically, in the other.
This is a standard setup. The two layout managers can have different
layouts for the text, but usually that happens when they are laying it
out into different numbers and/or sizes of text container. However,
you should be able to get what you want.
Now what I think I want to do is change one of the layout managers so
that, as it is laying out the text, it selectively changes the
attributes that it uses to draw the text.
There is a difference between layout and drawing. The layout manager
calls on the typesetter to perform layout, and the stores the
result--that is, the size and position of each line of text, and the
location of each glyph within it. Drawing is a separate operation,
performed later, and possibly many times with the same layout.
Temporary attributes affect drawing and not layout, which is why they
are restricted to attributes that do not affect layout.
The layout manager, however, does not manage the contents of the text,
either characters or attributes. The layout manager, text view, and
any other objects that need the text go directly to the text storage.
For that reason, I would recommend is that you work at the text storage
level.
Create one or more custom subclasses of NSTextStorage, and arrange to
have two distinct text storage instances, but implement them so that
the two share the same underlying storage. However, arrange for one of
these objects to strip out most attributes when it is asked to return
attributes. Attach one layout manager to the rich-text-returning text
storage, and another to the plain-text-returning text storage. Look at
NSTextStorage.h for information on subclassing the semi-abstract
NSTextStorage; possibly you might be able to find examples somewhere as
well.
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.