public class RichTextPainter
extends java.lang.Object
RichTextPainter
is used to parse and render HTML input to a GC
. It works well
with HTML input generated by ckeditor.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ATTRIBUTE_PARAGRAPH_MARGIN_LEFT |
static java.lang.String |
ATTRIBUTE_PARAGRAPH_TEXT_ALIGN |
static java.lang.String |
ATTRIBUTE_PARAGRAPH_TEXT_ALIGN_VALUE_RIGHT |
static java.lang.String |
ATTRIBUTE_STYLE |
static java.lang.String |
ATTRIBUTE_STYLE_BACKGROUND_COLOR |
static java.lang.String |
ATTRIBUTE_STYLE_COLOR |
static java.lang.String |
ATTRIBUTE_STYLE_FONT_FAMILY |
static java.lang.String |
ATTRIBUTE_STYLE_FONT_SIZE |
static java.lang.String[] |
BULLETS |
static java.lang.String |
CONTROL_CHARACTER_REGEX |
(package private) javax.xml.stream.XMLInputFactory |
factory |
static java.lang.String |
FAKE_ROOT_TAG_END |
static java.lang.String |
FAKE_ROOT_TAG_START |
static java.lang.String |
SPACE |
static java.lang.String |
TAG_BR |
static java.lang.String |
TAG_EM |
static java.lang.String |
TAG_LIST_ITEM |
static java.lang.String |
TAG_ORDERED_LIST |
static java.lang.String |
TAG_PARAGRAPH |
static java.lang.String |
TAG_SPAN |
static java.lang.String |
TAG_STRIKETHROUGH |
static java.lang.String |
TAG_STRONG |
static java.lang.String |
TAG_UNDERLINE |
static java.lang.String |
TAG_UNORDERED_LIST |
Constructor and Description |
---|
RichTextPainter()
Create a new
RichTextPainter with disabled word wrapping. |
RichTextPainter(boolean wordWrap)
Create a new
RichTextPainter . |
Modifier and Type | Method and Description |
---|---|
protected int |
calculateListIndentation(org.eclipse.swt.graphics.GC gc)
Calculates the indentation to use for list items.
|
protected java.lang.String |
getBulletCharacter(int listDepth) |
int |
getParagraphSpace() |
org.eclipse.swt.graphics.Point |
getPreferredSize()
Returns the preferred size of the content.
|
void |
paintHTML(java.lang.String html,
org.eclipse.swt.graphics.GC gc,
org.eclipse.swt.graphics.Rectangle bounds)
Processes the HTML input and paints the result to the given
GC . |
protected void |
paintHTML(java.lang.String html,
org.eclipse.swt.graphics.GC gc,
org.eclipse.swt.graphics.Rectangle bounds,
boolean render)
Processes the HTML input.
|
void |
preCalculate(java.lang.String html,
org.eclipse.swt.graphics.GC gc,
org.eclipse.swt.graphics.Rectangle bounds,
boolean calculateWithWrapping)
Processes the HTML input to calculate the preferred size.
|
void |
setEntityReplacer(EntityReplacer entityReplacer)
Set an
EntityReplacer that should be used to replace EntityReference s in the
HTML snippet to parse. |
void |
setParagraphSpace(int paragraphSpace) |
void |
setWordSplitRegex(java.lang.String wordSplitRegex) |
public static final java.lang.String TAG_SPAN
public static final java.lang.String TAG_STRONG
public static final java.lang.String TAG_EM
public static final java.lang.String TAG_UNDERLINE
public static final java.lang.String TAG_STRIKETHROUGH
public static final java.lang.String TAG_PARAGRAPH
public static final java.lang.String TAG_UNORDERED_LIST
public static final java.lang.String TAG_ORDERED_LIST
public static final java.lang.String TAG_LIST_ITEM
public static final java.lang.String TAG_BR
public static final java.lang.String ATTRIBUTE_STYLE
public static final java.lang.String ATTRIBUTE_STYLE_COLOR
public static final java.lang.String ATTRIBUTE_STYLE_BACKGROUND_COLOR
public static final java.lang.String ATTRIBUTE_STYLE_FONT_SIZE
public static final java.lang.String ATTRIBUTE_STYLE_FONT_FAMILY
public static final java.lang.String ATTRIBUTE_PARAGRAPH_MARGIN_LEFT
public static final java.lang.String ATTRIBUTE_PARAGRAPH_TEXT_ALIGN
public static final java.lang.String ATTRIBUTE_PARAGRAPH_TEXT_ALIGN_VALUE_RIGHT
public static final java.lang.String CONTROL_CHARACTER_REGEX
public static final java.lang.String FAKE_ROOT_TAG_START
public static final java.lang.String FAKE_ROOT_TAG_END
public static final java.lang.String[] BULLETS
public static final java.lang.String SPACE
javax.xml.stream.XMLInputFactory factory
public RichTextPainter()
RichTextPainter
with disabled word wrapping.public RichTextPainter(boolean wordWrap)
RichTextPainter
.wordWrap
- true
if automatic word wrapping should be enabled, false
if not.public void preCalculate(java.lang.String html, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds, boolean calculateWithWrapping)
html
- The HTML string to process.gc
- The GC
to operate on.bounds
- The available space for painting.calculateWithWrapping
- true
if calculation should be performed with enabled word wrapping,
false
if notpublic void paintHTML(java.lang.String html, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds)
GC
.html
- The HTML string to process.gc
- The GC
to operate on.bounds
- The available space for painting.protected void paintHTML(java.lang.String html, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds, boolean render)
html
- The HTML string to process.gc
- The GC
to operate on.bounds
- The available space for painting.render
- true
if the processing result should be painted to the GC
,
false
if not (in case of pre calculation).protected int calculateListIndentation(org.eclipse.swt.graphics.GC gc)
gc
- The current GC
for calculating the text extend.protected java.lang.String getBulletCharacter(int listDepth)
listDepth
- The list depth of the current list. Needs to be 1 for the top level list.public void setEntityReplacer(EntityReplacer entityReplacer)
EntityReplacer
that should be used to replace EntityReference
s in the
HTML snippet to parse.entityReplacer
- The EntityReplacer
to use.public org.eclipse.swt.graphics.Point getPreferredSize()
preCalculate(String, GC, Rectangle, boolean)
public int getParagraphSpace()
public void setParagraphSpace(int paragraphSpace)
paragraphSpace
- The space that should be applied before and after a paragraph.public void setWordSplitRegex(java.lang.String wordSplitRegex)
wordSplitRegex
- The regular expression that will be used to determine word boundaries. The default
is "\s".