Class RTFWriter


class RTFWriter extends StyledTextWriterBase
The RTFWriter class is used to write styled content as rich text. The implementation complies with the RTF specification version 1.5.

toString() is guaranteed to return a valid formatted string only after close() has been called.

Whole and partial lines and line breaks can be written. Lines will be formatted using the styles queried from the LineStyleListener, if set, or those set directly in the widget. All styles are applied to the stream like they are rendered by the widget. In addition, the widget font name and size is used for the whole text.

  • Field Details

  • Constructor Details

    • RTFWriter

      public RTFWriter(StyledText styledText, int start, int length)
  • Method Details

    • close

      public void close()
      Description copied from class: TextWriter
      Closes the writer. Once closed no more content can be written. NOTE: toString() is not guaranteed to return a valid string unless the writer is closed.
      Overrides:
      close in class TextWriter
    • writeHeader

      void writeHeader()
      Writes the RTF header including font table and color table.
      Specified by:
      writeHeader in class StyledTextWriterBase
    • writeLineDelimiter

      public void writeLineDelimiter(String lineDelimiter)
      Description copied from class: TextWriter
      Appends the specified line delimiter to the data.
      Overrides:
      writeLineDelimiter in class TextWriter
      Parameters:
      lineDelimiter - line delimiter to write
    • writeLineStart

      String writeLineStart(Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify)
      Description copied from class: StyledTextWriterBase
      Invoked at the beginning of each line in the original widget.

      It should output whatever tags are appropriate to start a new line in the output format.
      It will return the text that has to be output at the end of the line.

      Specified by:
      writeLineStart in class StyledTextWriterBase
      Returns:
      the text to append at the end of the line
    • writeEmptyLine

      void writeEmptyLine()
      Description copied from class: StyledTextWriterBase
      Invoked at the end of each line, writeLineEnd, if there was no text output.

      This is needed for HTML, which does not render empty paragraphs.

      Specified by:
      writeEmptyLine in class StyledTextWriterBase
    • writeSpanStart

      String writeSpanStart(StyleRange style)
      Description copied from class: StyledTextWriterBase
      Invoked at the beginning of each styled span fragment in the original widget.

      It should output whatever tags are appropriate to start a formatted span in the output format.
      It will return the text that has to be output at the end of the span (to close it).

      Specified by:
      writeSpanStart in class StyledTextWriterBase
      Returns:
      the text to append at the end of the styled span
    • escapeText

      String escapeText(String string)
      Description copied from class: StyledTextWriterBase
      Takes plain text and returns the same text escaped using the rules of the output format.
      Specified by:
      escapeText in class StyledTextWriterBase
      Parameters:
      string - the text to escape
      Returns:
      the escaped text
    • getColorIndex

      private int getColorIndex(Color color, int defaultIndex)
      Returns the index of the specified color in the RTF color table.
      Parameters:
      color - the color
      defaultIndex - return value if color is null
      Returns:
      the index of the specified color in the RTF color table or "defaultIndex" if "color" is null.
    • getFontIndex

      private int getFontIndex(Font font)
      Returns the index of the specified color in the RTF color table.
      Parameters:
      color - the color
      defaultIndex - return value if color is null
      Returns:
      the index of the specified color in the RTF color table or "defaultIndex" if "color" is null.