Class StyledTextWriterBase
- Direct Known Subclasses:
HTMLWriter, RTFWriter
StyleRange(s).
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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionStyledTextWriterBase(StyledText styledText, int start, int length) Creates a writer that processed content starting at offset "start" in the document. -
Method Summary
Modifier and TypeMethodDescription(package private) abstract StringescapeText(String text) Takes plain text and returns the same text escaped using the rules of the output format.(package private) abstract voidInvoked at the end of each line, writeLineEnd, if there was no text output.(package private) voidwriteEscaped(String string, int start, int end) Appends the specified segment of "string" to the output data.(package private) abstract voidWrites the part that only shows once, at the beginning of the output data.voidAppends the specified line text to the output data.(package private) voidwriteLineEnd(String prepared) Invoked at the end of of each line in the original widget.(package private) abstract StringwriteLineStart(Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify) Invoked at the beginning of each line in the original widget.(package private) voidwriteSpanEnd(String prepared) Invoked at the end of of each styled span fragment in the original widget.(package private) abstract StringwriteSpanStart(StyleRange style) Invoked at the beginning of each styled span fragment in the original widget.(package private) voidwriteStyledLine(String line, int lineOffset, int[] ranges, StyleRange[] styles, Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify) Appends the specified line text to the output data.Methods inherited from class TextWriter
close, getCharCount, getStart, isClosed, toString, write, write, write, write, writeLineDelimiter
-
Field Details
-
styledText
-
-
Constructor Details
-
StyledTextWriterBase
Creates a writer that processed content starting at offset "start" in the document.startandlengthcan be set to specify partial lines.- Parameters:
styledText- the widget to produce the RTF fromstart- start offset of content to write, 0 based from beginning of documentlength- length of content to write
-
-
Method Details
-
writeEscaped
Appends the specified segment of "string" to the output data. Copy fromstartup to, but excluding,end.- Parameters:
string- string to copy a segment from. Must not contain line breaks. Line breaks should be written usinginvalid reference
#writeLineDelimiter()start- start offset of segment. 0 based.end- end offset of segment
-
writeLine
Appends the specified line text to the output data. Lines will be formatted using the styles queried from the LineStyleListener, if set, or those set directly in the widget.- Overrides:
writeLinein classTextWriter- Parameters:
line- line text to write. Must not contain line breaks Line breaks should be written usingTextWriter.writeLineDelimiter(String)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.- Throws:
SWTException-ERROR_IOwhen the writer is closed.
-
writeStyledLine
void writeStyledLine(String line, int lineOffset, int[] ranges, StyleRange[] styles, Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify) Appends the specified line text to the output data.Use the colors and font styles specified in
stylesandlineBackground. Formatting is written to reflect the text rendering by the text widget. Style background colors take precedence over the line background color.- Parameters:
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.
-
writeHeader
abstract void writeHeader()Writes the part that only shows once, at the beginning of the output data. -
escapeText
-
writeLineStart
abstract String writeLineStart(Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify) 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.- Returns:
- the text to append at the end of the line
-
writeLineEnd
Invoked at the end of of each line in the original widget.It receives whatever text
writeLineStart(Color,int,int,int,boolean)returned and it will output it. A class might override it to do more.- Parameters:
prepared- the leftover text prepared bywriteLineStart
-
writeEmptyLine
abstract void writeEmptyLine()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.
-
writeSpanStart
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).- Returns:
- the text to append at the end of the styled span
-
writeSpanEnd
Invoked at the end of of each styled span fragment in the original widget.It receives whatever text
writeSpanStart(StyleRange)returned and it will output it. A class might override it to do more.- Parameters:
prepared- the leftover text prepared bywriteSpanStart
-