Bad solution for RTF template?
Bad solution for RTF template?
- Subject: Bad solution for RTF template?
- From: Carl Norum <email@hidden>
- Date: Mon, 02 Jun 2003 13:40:29 -0600
Carl Norum presents....
Yet another question in a seemingly endless series!
OK - so now to simplify the printing system in this program I want to
use an RTF file as a template. Then I want to run through and replace
strings in the file like "[String X]" with some value depending on the
current document model object.
Then to do the printing, I'd just make an NSTextView programmatically
and give it the appropriate RTF data. I saw this approach recommended
somewhere in the archives, but I can't for the life of me seem to track
it down again.
The problem I'm having is in doing this in a sane way -
NSMutableAttributedString doesn't have a
replaceOccurrencesOfString:withString:options:range: method like
NSMutableString does, and I can't find a way to replace characters in
the string and maintain overall text attributes (bold in the right
spots, font size, etc).
So the current solution I have is to read the RTF file into an
NSMutableString, run through it doing all of my string substitutions,
and write it to a temporary file (in /tmp). Then I use NSTextView's
readRTFDFromFile: to get the string back in RTF format with all of the
attributes correct.
I'd like to have a better solution - anyone have any suggestions? I'd
be happy with just being able to rid myself of the temporary file
solution, but I'd rather there was a good way to go about it.
I'm sure this is one of those times when I've just blatantly missed the
appropriate tidbit in the documentation. The way I'm doing it is the
hard way, and if there's one thing that Cocoa has taught me it's that
it's not hard.
Thanks folks!
--
Carl J Norum
5th Year Electrical Engineering/Computer Science Student
University of Saskatchewan
Saskatoon, Canada
http://norum.homeunix.net/~carl/
_______________________________________________
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.