FROM : Douglas Davidson
DATE : Sun Dec 12 21:26:58 2004
On Dec 11, 2004, at 10:34 PM, Jonathan Jackel wrote:
> On Dec 10, 2004, at 5:10 PM, Moray Taylor wrote:
>
>> Hi,
>>
>> In my program I require an NSAttributedString that can not only
>> contain styles such as bold, italic etc.. , but contain 'named
>> styles' much like Quark Xpress or MS Word would have.
>>
>> I assume I can use the addAttribute:withRange to set where my 'named
>> styles' are,
>
> Absolutely -- except you probably want to use an NSTextStorage, which
> is a subclass of NSMutableAttributedString.
>
>> but how would I make the NSAttributedString lookup what these styles
>> meant, and render itself accordingly? Is this possible, or do I need
>> to make my own attributedstring class?
>
> Hopefully John Randolph will chime in on this one, but I suspect you
> would need to subclass NSLayoutManager. I don't even want to guess
> how.
Actually, for this an NSTextStorage subclass ought to work. The
primary thing that an NSTextStorage subclass has to do is to be able to
return the character and attributes at a given index. If you have an
alternate model for your attributes--for example, as a hierarchy of
named styles--then you could simply resolve those, when asked, into a
dictionary of computed attributes of the sort that the text system
expects--font, color, etc.--and return that as the attribute
dictionary. Editing could be a bit trickier, but there should be
sufficient hooks for you to handle that.
Douglas Davidson
DATE : Sun Dec 12 21:26:58 2004
On Dec 11, 2004, at 10:34 PM, Jonathan Jackel wrote:
> On Dec 10, 2004, at 5:10 PM, Moray Taylor wrote:
>
>> Hi,
>>
>> In my program I require an NSAttributedString that can not only
>> contain styles such as bold, italic etc.. , but contain 'named
>> styles' much like Quark Xpress or MS Word would have.
>>
>> I assume I can use the addAttribute:withRange to set where my 'named
>> styles' are,
>
> Absolutely -- except you probably want to use an NSTextStorage, which
> is a subclass of NSMutableAttributedString.
>
>> but how would I make the NSAttributedString lookup what these styles
>> meant, and render itself accordingly? Is this possible, or do I need
>> to make my own attributedstring class?
>
> Hopefully John Randolph will chime in on this one, but I suspect you
> would need to subclass NSLayoutManager. I don't even want to guess
> how.
Actually, for this an NSTextStorage subclass ought to work. The
primary thing that an NSTextStorage subclass has to do is to be able to
return the character and attributes at a given index. If you have an
alternate model for your attributes--for example, as a hierarchy of
named styles--then you could simply resolve those, when asked, into a
dictionary of computed attributes of the sort that the text system
expects--font, color, etc.--and return that as the attribute
dictionary. Editing could be a bit trickier, but there should be
sufficient hooks for you to handle that.
Douglas Davidson
| Related mails | Author | Date |
|---|---|---|
| Moray Taylor | Dec 10, 23:10 | |
| Jonathan Jackel | Dec 12, 07:34 | |
| Douglas Davidson | Dec 12, 21:26 |






Cocoa mail archive

