Displaying one NSTextStorage with two sets of temporary attributes
Displaying one NSTextStorage with two sets of temporary attributes
- Subject: Displaying one NSTextStorage with two sets of temporary attributes
- From: "Adam C.M. Solove" <email@hidden>
- Date: Thu, 1 May 2008 17:25:33 -0700
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:
This email sent to email@hidden