Skip navigation.
 
mlRe: Displaying one NSTextStorage with two sets of temporary attributes
FROM : Ross Carter
DATE : Fri May 02 19:38:09 2008

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_removed>> 
> 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_removed>)
>>>
>>> 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/rosscarter
>>> %40mac.com
>>>
>>> This email sent to <email_removed>
>>>
>>>

>>
>>

>

Related mailsAuthorDate
mlDisplaying one NSTextStorage with two sets of temporary attributes Adam C.M. Solove May 2, 02:25
mlRe: Displaying one NSTextStorage with two sets of temporary attributes Ross Carter May 2, 16:57
mlRe: Displaying one NSTextStorage with two sets of temporary attributes Adam C.M. Solove May 2, 18:47
mlRe: Displaying one NSTextStorage with two sets of temporary attributes Ross Carter May 2, 19:38
mlRe: Displaying one NSTextStorage with two sets of temporary attributes Adam C.M. Solove May 2, 20:52
mlRe: Displaying one NSTextStorage with two sets of temporary attributes Martin Wierschin May 7, 03:35