class StyledText.RTFWriter extends StyledText.TextWriter
RTFWriter
class is used to write widget content as
rich text. The implementation complies with the RTF specification
version 1.5.
toString() is guaranteed to return a valid RTF 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 RTF stream like they are rendered by the widget. In addition, the widget font name and size is used for the whole text.
Modifier and Type | Field and Description |
---|---|
(package private) java.util.Vector |
colorTable |
(package private) static int |
DEFAULT_BACKGROUND |
(package private) static int |
DEFAULT_FOREGROUND |
(package private) java.util.Vector |
fontTable |
(package private) boolean |
WriteUnicode |
Constructor and Description |
---|
StyledText.RTFWriter(int start,
int length)
Creates a RTF writer that writes content starting at offset "start"
in the document.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the RTF writer.
|
(package private) int |
getColorIndex(Color color,
int defaultIndex)
Returns the index of the specified color in the RTF color table.
|
(package private) int |
getFontIndex(Font font)
Returns the index of the specified color in the RTF color table.
|
(package private) void |
setUnicode()
Determines if Unicode RTF should be written.
|
(package private) void |
write(java.lang.String string,
int start,
int end)
Appends the specified segment of "string" to the RTF data.
|
(package private) void |
writeHeader()
Writes the RTF header including font table and color table.
|
void |
writeLine(java.lang.String line,
int lineOffset)
Appends the specified line text to the RTF data.
|
void |
writeLineDelimiter(java.lang.String lineDelimiter)
Appends the specified line delimiter to the RTF data.
|
(package private) void |
writeStyledLine(java.lang.String line,
int lineOffset,
int[] ranges,
StyleRange[] styles,
Color lineBackground,
int indent,
int alignment,
boolean justify)
Appends the specified line text to the RTF data.
|
getCharCount, getStart, isClosed, toString, write, write, write, write
static final int DEFAULT_FOREGROUND
static final int DEFAULT_BACKGROUND
java.util.Vector colorTable
java.util.Vector fontTable
boolean WriteUnicode
public StyledText.RTFWriter(int start, int length)
start
and length
can be set to specify partial
lines.start
- start offset of content to write, 0 based from
beginning of documentlength
- length of content to writepublic void close()
toString()
does not return a valid RTF string until
close()
has been called.close
in class StyledText.TextWriter
int getColorIndex(Color color, int defaultIndex)
color
- the colordefaultIndex
- return value if color is nullint getFontIndex(Font font)
color
- the colordefaultIndex
- return value if color is nullvoid setUnicode()
void write(java.lang.String string, int start, int end)
start
up to, but excluding, end
.string
- string to copy a segment from. Must not contain
line breaks. Line breaks should be written using writeLineDelimiter()start
- start offset of segment. 0 based.end
- end offset of segmentvoid writeHeader()
public void writeLine(java.lang.String line, int lineOffset)
writeLine
in class StyledText.TextWriter
line
- line text to write as RTF. Must not contain line breaks
Line breaks should be written using writeLineDelimiter()lineOffset
- offset of the line. 0 based from the start of the
widget document. Any text occurring before the start offset or after the
end offset specified during object creation is ignored.SWTException
- public void writeLineDelimiter(java.lang.String lineDelimiter)
writeLineDelimiter
in class StyledText.TextWriter
lineDelimiter
- line delimiter to write as RTF.SWTException
- void writeStyledLine(java.lang.String line, int lineOffset, int[] ranges, StyleRange[] styles, Color lineBackground, int indent, int alignment, boolean justify)
Use the colors and font styles specified in "styles" and "lineBackground". Formatting is written to reflect the text rendering by the text widget. Style background colors take precedence over the line background color. Background colors are written using the \highlight tag (vs. the \cb tag).
line
- line text to write as RTF. Must not contain line breaks
Line breaks should be written using writeLineDelimiter()lineOffset
- offset of the line. 0 based from the start of the
widget document. Any text occurring before the start offset or after the
end offset specified during object creation is ignored.styles
- styles to use for formatting. Must not be null.lineBackground
- line background color to use for formatting.
May be null.