Class RTFWriter
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 Summary
FieldsModifier and TypeFieldDescription(package private) static final int(package private) static final intFields inherited from class StyledTextWriterBase
styledText -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the writer.(package private) StringescapeText(String string) Takes plain text and returns the same text escaped using the rules of the output format.private intgetColorIndex(Color color, int defaultIndex) Returns the index of the specified color in the RTF color table.private intgetFontIndex(Font font) Returns the index of the specified color in the RTF color table.(package private) voidInvoked at the end of each line, writeLineEnd, if there was no text output.(package private) voidWrites the RTF header including font table and color table.voidwriteLineDelimiter(String lineDelimiter) Appends the specified line delimiter to the data.(package private) StringwriteLineStart(Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify) Invoked at the beginning of each line in the original widget.(package private) StringwriteSpanStart(StyleRange style) Invoked at the beginning of each styled span fragment in the original widget.Methods inherited from class StyledTextWriterBase
writeEscaped, writeLine, writeLineEnd, writeSpanEnd, writeStyledLineMethods inherited from class TextWriter
getCharCount, getStart, isClosed, toString, write, write, write, write
-
Field Details
-
DEFAULT_FOREGROUND
static final int DEFAULT_FOREGROUND- See Also:
-
DEFAULT_BACKGROUND
static final int DEFAULT_BACKGROUND- See Also:
-
colorTable
-
fontTable
-
-
Constructor Details
-
RTFWriter
-
-
Method Details
-
close
public void close()Description copied from class:TextWriterCloses 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:
closein classTextWriter
-
writeHeader
void writeHeader()Writes the RTF header including font table and color table.- Specified by:
writeHeaderin classStyledTextWriterBase
-
writeLineDelimiter
Description copied from class:TextWriterAppends the specified line delimiter to the data.- Overrides:
writeLineDelimiterin classTextWriter- Parameters:
lineDelimiter- line delimiter to write
-
writeLineStart
String writeLineStart(Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify) Description copied from class:StyledTextWriterBaseInvoked 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:
writeLineStartin classStyledTextWriterBase- Returns:
- the text to append at the end of the line
-
writeEmptyLine
void writeEmptyLine()Description copied from class:StyledTextWriterBaseInvoked 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:
writeEmptyLinein classStyledTextWriterBase
-
writeSpanStart
Description copied from class:StyledTextWriterBaseInvoked 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:
writeSpanStartin classStyledTextWriterBase- Returns:
- the text to append at the end of the styled span
-
escapeText
Description copied from class:StyledTextWriterBaseTakes plain text and returns the same text escaped using the rules of the output format.- Specified by:
escapeTextin classStyledTextWriterBase- Parameters:
string- the text to escape- Returns:
- the escaped text
-
getColorIndex
Returns the index of the specified color in the RTF color table.- Parameters:
color- the colordefaultIndex- 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
Returns the index of the specified color in the RTF color table.- Parameters:
color- the colordefaultIndex- return value if color is null- Returns:
- the index of the specified color in the RTF color table or "defaultIndex" if "color" is null.
-