Skip to main content

Found a bug in RTFEditorKit

No replies
Joined: 2006-05-02

this code exposes a problem with rtf editor kit:

<p>import;<br />
import javax.swing.text.BadLocationException;<br />
import javax.swing.text.Document;<br />
import javax.swing.text.DefaultStyledDocument;<br />
import javax.swing.text.rtf.RTFEditorKit;<br />
import org.junit.After;<br />
import org.junit.AfterClass;<br />
import org.junit.Before;<br />
import org.junit.BeforeClass;<br />
import org.junit.Test;<br />
import static org.junit.Assert.*;</p>
<p>public class ParserTest {</p>
<p>    public ParserTest() {<br />
<p>    @BeforeClass<br />
    public static void setUpClass() throws Exception {<br />
<p>    @AfterClass<br />
    public static void tearDownClass() throws Exception {<br />
<p>    @Before<br />
    public void setUp() {<br />
<p>    @After<br />
    public void tearDown() {<br />
<p>    @Test<br />
    public synchronized void rtfParse() throws BadLocationException {</p>
<p>String test =<br />
        "{\\rtf1\\fbidis\\ansi\\ansicpg1252\\deff0\\deflang3084\\deflangfe3084{" +<br />
        "\\fonttbl{\\f0\\froman\\fprq2\fcharset0 Fournier MT Std Regular;}}"+<br />
        "\\viewkind4\\uc1\\pard\\ltrpar\\fi227\\qr\\lang1033\\kerning16\\f0\\fs18\\par"+<br />
        "\\pard\\ltrpar\\fi227\\sb160\\sa120\\qr Saint Augustine has seen that one" +<br />
        "\\line labors in uncertainty at sea\\line and in battles and in " +<br />
        "all the rest,\\line but he has not seen the rules of the game.\\par}";<br />
        try{<br />
        StringReader stringReader = new;<br />
        Document result = new RTFEditorKit().read(stringReader , new DefaultStyledDocument(), 0);<br />
         } catch (Exception io) {</p>
<p>         }</p>
<p>        text = result.getText(0, result.getLength());<br />
        assertEquals("Saint Augustine has seen that one labors\n" +<br />
                "in uncertainty at sea\nand in battles and in all" +<br />
                " the rest,\nbut he has not seen the rules of the game.", text);<br />
<p>}<br />

The assert fails because the \line keyword in rtf is ignored.
The real output is:
"Saint Augustine has seen that onelabors in", no \n added. I'm going to open a issue on the bug parade, but offcourse i don't expect results. Swing text has been in the dregs for some time now.

Message was edited by: i30817

Message was edited by: i30817