Microsoft Rich Text Format

1. RTF output handler, XT only

1.

RTF output handler, XT only

Eric van der Vlist

See 4xt.org

The good news is that you don't need to fight with the text output method any longer to generate RTF, the bad news is that you still need to know RTF to use this output method!

RTFOutputHandler is an output method 4xt that serializes a XML tree following a RTF syntax.

This method is working at a pure syntaxic level and doesn't know (nor test) any of the semantic of RTF.

The conversion from XML elements and attributes is done using a straightforward and automatic algorithm:

1) Control names:

The control names are the concatenation of the element name and the value of all its attributes.

<rtf>           -->  \rtf
<author>        -->  \author
<fs id="20">    -->  \fs20
<fs ref="20">   -->  \fs20

2) Blocks:

A new block is started for each element with children elements:

<rtf>
  <ansi/>
...

will generate 

{\rtf\ansi...

This simple algorithm is... too simple, some controls need to be always enclosed in a group and a list of controls will have to be created in future releases.

3) "Special" characters:

The RTF reserved characters ("\", "{" and "}") are escaped and the ANSI characters with a value greater then 127 are translated as specified by the RTF specification.

4) Unicode support:

Unicode isn't supported yet.

5) Whitespaces:

This is probably one of the biggest limitation of the current version: no treatment is done regarding whitespaces.

This means that your XSLT transformation should strip the spaces (<xsl:strip-space elements="*"/>) and include whitespaces where there are expected even in first position of values (such as "author" or "froman" in our example).

6) Samples

This Java class is provided with the following samples :

 - hello.fxml, hello.xsl and hello.rtf 
   (Hello world kind of example)

 - xhtlm2rtf.fxml, xhtlm2rtf.xsl and xhtlm2rtf.rtf 
   (Sample transformation from XHTML to RTF
   supporting only "p" anf "h1")