Re: Displaying one NSTextStorage with two sets of temporary attributes
Re: Displaying one NSTextStorage with two sets of temporary attributes
- Subject: Re: Displaying one NSTextStorage with two sets of temporary attributes
- From: Martin Wierschin <email@hidden>
- Date: Tue, 6 May 2008 18:35:37 -0700
I think any way you do this things are going to get messy. However,
in terms of simplicity using break characters to split one
NSTextStorage between containers might be the easiest. Yes, you'd
have to filter incoming content to be sure that "real" break
characters don't pollute your content, but all the layout business is
handled for you. Of course, some other free behavior may or may not
be desirable, eg: Select All would select all content across all
containers.
It might be worthwhile looking at creating a custom NSTextStorage
subclass that provides a window into a larger storage. This has the
benefit that everything is absolutely under your control and the
interface points are all well defined. The problem will be mapping
changes back and forth between the master storage. You need to be
sure to inform all attached layout managers if the content in its
respective window changes.
It looks like Keith has managed to use typesetter overrides to hide
text, but I've never tried it myself:
http://www.cocoabuilder.com/archive/message/cocoa/2008/3/11/200965
As for footnotes, I don't know if there is a "normal" way to do them.
Obviously you need a placeholder for the footnote reference in the
main content stream. I would recommend a text attachment subclass, or
some other unit that appears atomic to the text system. If you don't,
then you get into hairy situations when footnote references require
renumbering, eg: consider undo, which tracks changes by character
offsets.
Pagination with footnotes get very tricky. The biggest issue is that
while a line fragment with a footnote reference may fit on a page,
the corresponding footnote text may not fit on that same page, eg:
you'll need to force the layout system to move the line fragment
containing the reference to the next container. There unfortunately
isn't any standard way to do this. You'll need to write a typesetter
subclass that can detect the situation and reject line fragments as
appropriate, eg: override "willSetLineFragmentRect:etc:". These posts
may help:
http://www.cocoabuilder.com/archive/message/cocoa/2004/7/5/111040
http://www.cocoabuilder.com/archive/message/cocoa/2007/3/20/180546
Best of luck!
~Martin
On May 2, 2008, at 11:52 AM, Adam C.M. Solove wrote:
First, Ross, thank you for your comments. I was going about this
somewhat wrong and you took the time to think it through.
I think you are right that it would be easiest to separate the
different note series into their own TextStorage. Then I could add
custom attributes to each text that determine where they are tied
together. The delegate methods would be lots of code, but fairly
straight-forward.
I also would be curious to hear from text experts how footnotes are
normally done. I have the luxury of small blocks of text and not
worrying about page breaks, which makes the situation somewhat easier.
-Adam
On Fri, May 2, 2008 at 10:38 AM, Ross Carter <email@hidden>
wrote:
Hi Adam,
I guess that the approach you will take depends on how the
textStorage
string is set up. Sorry, I don't know anything about TEI, so I can
only
offer general comments.
If the textStorage series are sequential and the number and
sequence of
series are known in advance, and the text has no page break
characters
(NSFormFeedCharacter), you could insert a page break at the end of
each
series. That will throw layout over to the next textContainer. If
you have a
textContainer/textView set up for each series, then the text will
flow into
the textViews that you have set up to show the content of each
series.
If you know the character range of each series, you could override
NSLayoutManager drawGlyphsForGlyphRange:atPoint: and have it send the
message to super only if the glyphs in glyphRange are in the
character range
you want to display.
In short, if the question is "Is there a simple way to tell
NSLayoutManager
not to display certain character ranges," then the answer is: I
don't think
so. Personally, I wouldn't adopt either of the approaches I mentioned
because of the complications in coordinating the various displays
using one
textStorage. For example, if the user pasted in some text that
contains a
form feed character, it could throw off everything.
XML is easy to parse. I think you'll find it simpler in the end
to split
the original string into separate series, make each series the
textStorage
for a textView, let the user edit each series as he desires, and then
reassemble the series into a single string when you archive. Even
if there
were a way to tell the layoutManagers to be selective about what they
display, you've still got a lot of work to do in keeping them all
synchronized as the user adds and removes text.
That's just my opinion, though. Text experts like Douglas and
Martin might
have a better idea. I'd be happy to continue this discussion
offline if you
to want to kick around some more ideas.
Ross
On May 2, 2008, at 12:47 PM, Adam C.M. Solove wrote:
Actually, you're right that merely suppressing display is all I
need.
I was assuming this would have to be done with temporary attributes,
but is there an easier way?
THank you,
Adam Solove
On Fri, May 2, 2008 at 7:57 AM, Ross Carter <email@hidden>
wrote:
I'm not sure whether you need to change a particular set of
attributes
(font, line spacing, tabs, etc) in each layout manager or merely
suppress
the display of text in other series. If the former, I would
think that
the
layout manager is not best place to handle the attribute fixing.
I'd
think
about either subclassing NSTextStorage and have it modify the
attributes
that it receives from and sends to the various layout managers, or
subclassing the typesetter and overriding setAttributedString:
to change
the
attributes as needed. I haven't ever done either of those
things, mind
you,
so I don't know whether they would work.
It just seems to me that by the time the layout manager goes to
work,
it's
difficult to change the attributes (except for things that don't
affect
the
layout, such as underlining) because of the complex interaction
between
the
layout manager and the typesetter. You probably want to
intervene before
the
attributedString gets converted into glyphs.
On May 1, 2008, at 8:25 PM, Adam C.M. Solove wrote:
Hello all,
In the episode of Late Night Cocoa on the text system, [
http://www.macdevnet.com/index.php/shows/latenightcocoa/37-
latenightcocoa/93-lnc005
] Juan Pablo Claude described a setup with multiple
NSLayoutManagers
editing text from the same NSTextStorage and then said, off-
hand, that
you might do this if you wanted to display the same text with
different fonts. I am curious if anyone could discuss how this
might
be done: displaying the same underlying attributed string, but
formatting it before the NSLayoutManager tries to lay it out and
formatting it back when the NSTextView sends back changes. I
cannot
find specific information on subclassing NSLayoutManager to
make these
sorts of changes.
(I know there is an Apple demo [TextViewConfig,
http://developer.apple.com/samplecode/TextViewConfig/
index.html] which
shows multiple layout managers, but these both render the exact
same
attributed string (except that one view has been essentially
zoomed to
twice the size). I am curious if it is possible to actually change
temporary attributes in one LayoutManager but not the other,
and then
change them back appropriately before sending events to the
NSTextStorage.)
End technical discussion
----
Begin back story for those interested:
I am a relatively new Cocoa developer working on an open-source
project for academics. I recently spent considerable time
working on
a web-based version of this application before learning that the
hardest part was technically infeasible because of some
limitations in
HTML's designmode. In starting with Cocoa, I will be happy if the
project and required learning takes many years, so long as
there is an
answer in advance to this one difficult question.
The application is an editor for a specific subset of the TEI XML
guidelines for encoding literary works and scholarly
commentaries on
them. The underlying data maps very nicely into an attributed
string,
because it is a single text divided up into separate
'series' (main
text, footnotes, cross-links) The series are all anchored
together,
but would best be displayed apart, with first the main text,
then each
series of notes. I believe the easiest way to do this would be
to have
a single underlying NSTextStorage, to attribute every range of
text to
one series, and then to create various subclasses (or
formatters) for
NSLayoutManager that each display only text in one particular
series.
I suspect this could also be done with a custom Typesetter and the
method setNotShownAttribute:forGlyphAtIndex:, but am curious if
there
is a more general hook to set attributes on the string before
layout.
Thank you,
Adam Solove
_______________________________________________
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:
40mac.com
This email sent to email@hidden
_______________________________________________
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
_______________________________________________
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