🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #441

Re: Handling custom RTF directives in Text.

#441
From: Michael Mellinger
Date: Tue, 04 Aug 1992 17:30
74 lines
4214 bytes
In article <SCOTT.92Aug2124752@nic.gac.edu> scott@nic.gac.edu (Scott Hess)  
writes:
 
> First off, it appears that the \attachment directive is somehow
> special cased.  I can't say exactly how, or why, because nobody
> has replied to my posting (well, nobody has replied with any answers
> or even hints).  But, if I name my directive \attach, or anything
> but \attachment, things work out fine.  Perhaps \attachment is a
> Microsoft pre-defined directive.

Hmmm.  I didn't realize that someone else was having this same problem.
I've spent the past few days trying to figure this out, but I've had no  
luck.

My guess is that the word attachment is already registered under some  
other class.  If you try to register a word twice, the second time it is  
ignored.  For example, after this code is executed, the word GraphicImage  
will still be registered with the GraphicImage class.

  [Text registerDirective:"GraphicImage" forClass:[GraphicImage class]];
  [Text registerDirective:"GraphicImage" forClass:[FooImage class]];

So, I figure that the word attachment might already be registered.  If we  
knew the class name, it might be possible to substitute in the proper  
object.
 
> Now, my problem is retrieving the data from a stream.  The delegate
> method -textWillReadRichText:* is called when Text comes across an
> \attachment directive in the input.  It is simple enough for me to
> then read the pathname from the stream, _but_, there's no apparent
> method by which I can create a Cell and place it in the Text!  If
> I use Text's -replaceSelWithCell:, it places the Cell wherever the
> selection was before the Paste was initiated without regard to which
> point in the stream we are reading from.  This means that all of
> the Cells are pasted first, followed by any text.

The attachment directives in Mail contain the file position where the  
attachment belongs.  You can edit your mail documents and move the  
attachment statements around and the attachments will appear in the same  
place.  If you change the character position that is appended to the end,  
then the attachment will move in your message.  I was considering just  
extracting the attachments separately by parsing the rtf myself then  
inserting the attachments in their proper locations.

> Now, this I can probably fix using an _extremely_ hacked solution
> - I can record the positions and filename for each Cell, and then
> insert them after the Paste.  But this is _ugly_.  Is there any
> way I can say "Put this Cell at the point we are in our reading of
> the NXStream?".


Personally, I wouldn't use the word attachment unless I was planning on  
being able to read NeXT Mail documents.  I think that it is the only thing  
that currently uses this keyword.  RTFD uses the word NeXTGraphic,  
followed by the character position.  One multimedia text standard would be  
best, so applications can cut and paste among themselves.  Under 3.0 there  
is some sort of filter to allow Edit documents with attachments(apps,  
sounds, tiffs) etc. to be copied into mail.  Under 2.0, attachments were  
copied as filenames from Edit to Mail.

Anyway, the moral of the story is that standards are nice.  Btw, does NeXT  
document their RTFD "standard" in 3.0?
 
> [BTW, I just implemented the above.  My, oh my, it _is_ disgusting.
> Works, though.  One problem - why don't my Text delegate methods
> -textWillStartReadingRichText: and -textWillFinishReadingRichText:
> get called before and after RTF is read?  I ended up putting the
> functionality in a Text subclass, but I'd still be interested in
> knowing ...]

I'll probably need -textWillFinishReadingRichText to scan for attachments,  
if I don't find out the proper hack, so I'll let you know.

-Mike
Technical Details
Message-ID: <1992Aug4.173035.1864@Trirex.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!trirex!root
References: <SCOTT.92Aug2124752@nic.gac.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!trirex!root
From: mmelling@Trirex.com(Michael Mellinger)
Subject: Re: Handling custom RTF directives in Text.
Message-ID: <1992Aug4.173035.1864@Trirex.COM>
Sender: root@Trirex.COM (Operator)
Organization: Trirex Systems Inc.
References: <SCOTT.92Aug2124752@nic.gac.edu>
Date: Tue, 4 Aug 1992 17:30:35 GMT
Lines: 74