Re: Stripping formatting ...
Re: Stripping formatting ...
- Subject: Re: Stripping formatting ...
- From: Douglas Davidson <email@hidden>
- Date: Tue, 23 Dec 2003 13:36:02 -0800
On Dec 23, 2003, at 12:55 PM, J Nozzi wrote:
I'm attempting to strip ALL formatting of any kind EXCEPT bold,
underline, and italic. The documentation seems to be leading me in
circles. Even the old standby reference books aren't offering much
clarity. They all show how to modify each individual one, but I'm
looking for a very efficient way of zapping everything but those
attributes.
Say somebody pastes some rich text into a NSTextView with every
format imaginable ... is this ALL handled with attributed strings or
(as what I've read would seem to suggest) is some handled by NSFont /
NSFontManager?
Iterate over your NSAttributedString by effective attribute ranges.
Remove all attributes except NSUnderlineStyleAttributeName and
NSFontAttributeName. You haven't said whether you want to allow
different styles of underlines, but if you don't, then change the value
of NSUnderlineStyleAttributeName as appropriate. Use NSFontManager to
examine the font that is the value of NSFontAttributeName, determine
whether it is bold or italic, and generate a new value for the font
attribute accordingly. Bear in mind that some fonts do not have bold
or italic forms, while some have only bold or only italic forms; you
should decide what you wish to do about these--a font that has only an
italic form, for example, will be reported as italic. In addition, if
your text may have attachments, then you may wish to remove any
occurrences of the NSAttachmentCharacter in the text.
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.