Class HTMLWriter
java.lang.Object
org.eclipse.swt.custom.TextWriter
org.eclipse.swt.custom.StyledTextWriterBase
org.eclipse.swt.custom.HTMLWriter
The
HTMLWriter class is used to write styled content as HTML.
The implementation creates a very-very simple HTML, as compatible
as possible: simple styles, no JavaScript.
How the concepts are mapped to HTML:
- The global
StyledTextproperties (for exampleStyledText.getBackground()are written in a wrapping<div>or<span>(for line fragments). - The line specific properties (for example
StyledText.getLineBackground(int)are written the<p>elements - if the copied range contains more then a line fragment. - The
StyleRangeproperties inside the line are written the<span>elements.
-
Field Summary
FieldsFields inherited from class StyledTextWriterBase
styledText -
Constructor Summary
ConstructorsConstructorDescriptionHTMLWriter(StyledText styledText, int start, int length, StyledTextContent content) -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidappendAlignAndJustify(StringBuilder buffer, int alignment, boolean justify) private static StringappendFont(StringBuilder buffer, Font font, int fontStyle) private static voidappendStyle(StringBuilder buffer, String value) private static voidappendStyle(StringBuilder buffer, String prefix, int value, String postfix) private static voidappendStyle(StringBuilder buffer, String prefix, String value, String postfix) private static voidappendStyle(StringBuilder buffer, String prefix, Color value, String postfix) voidclose()Closes the writer.private static StringcolorToHex(Color color) (package private) StringescapeText(String string) Takes plain text and returns the same text escaped using the rules of the output format.(package private) voidInvoked at the end of each line, writeLineEnd, if there was no text output.(package private) voidWrites the part that only shows once, at the beginning of the output data.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
-
tag
-
multiline
private boolean multiline
-
-
Constructor Details
-
HTMLWriter
-
-
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()Description copied from class:StyledTextWriterBaseWrites the part that only shows once, at the beginning of the output data.- 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
-
colorToHex
-
appendStyle
-
appendStyle
-
appendStyle
-
appendStyle
-
appendFont
-
appendAlignAndJustify
-