Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6579763

RTFEditorKit does not parse \super or \sub keywords

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • client-libs

      FULL PRODUCT VERSION :
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-164)
      Java HotSpot(TM) Client VM (build 1.5.0_07-87, mixed mode, sharing)
      JDK 1.6.0_01

      ADDITIONAL OS VERSION INFORMATION :
      OS-independent

      A DESCRIPTION OF THE PROBLEM :
      RTFEditorKit does not parse superscript (keyword super) or subscript (keyword sub). There is a TODO on this in the JDK 5.0 source code (RTFReader line 1214).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Open up Microsoft Word, put in some superscripts and subscripts, output to rtf. Read in using RTFEditorKit. Thrill at the element containing your super/subscripts -- yet is not super/subscripted.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Separate element with super/subscript attribute.
      ACTUAL -
      No super/subscript attribute present.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.FileInputStream;

      import javax.swing.text.*;
      import javax.swing.text.rtf.*;

      public class Bug
      {
          public static void main(String[] args) throws Exception
          {
              RTFEditorKit kit = new RTFEditorKit();
              DefaultStyledDocument doc = new DefaultStyledDocument();
              
              // hardcode your own RTF file here!

              kit.read(new FileInputStream("/Users/ek/Desktop/A2.rtf"), doc, 0);
              
              Element root = doc.getDefaultRootElement();
              
              for (int i=0; i<root.getElementCount(); i++)
              {
                  Element paragraph = root.getElement(i);
                  System.out.println("Paragraph:");
                  
                  for (int j=0; j<paragraph.getElementCount(); j++)
                  {
                      Element data = paragraph.getElement(j);
                      AttributeSet attrs = data.getAttributes();
                      int begin = data.getStartOffset();
                      int len = data.getEndOffset() - begin;
                      
                      String text = doc.getText(begin, len);
                      
                      System.out.println(" Text: " + text);
                      if (StyleConstants.isSuperscript(attrs))
                          System.out.println(" [superscripted]");
                      if (StyleConstants.isSubscript(attrs))
                          System.out.println(" [subscripted]");
                  }
              }
          }
      }

      ---------- END SOURCE ----------

            peterz Peter Zhelezniakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: