Class RichTextPainter


  • public class RichTextPainter
    extends java.lang.Object
    The RichTextPainter is used to parse and render HTML input to a GC. It works well with HTML input generated by ckeditor.
    • Field Detail

      • TAG_STRIKETHROUGH

        public static final java.lang.String TAG_STRIKETHROUGH
        See Also:
        Constant Field Values
      • TAG_UNORDERED_LIST

        public static final java.lang.String TAG_UNORDERED_LIST
        See Also:
        Constant Field Values
      • TAG_ORDERED_LIST

        public static final java.lang.String TAG_ORDERED_LIST
        See Also:
        Constant Field Values
      • ATTRIBUTE_STYLE_COLOR

        public static final java.lang.String ATTRIBUTE_STYLE_COLOR
        See Also:
        Constant Field Values
      • ATTRIBUTE_STYLE_BACKGROUND_COLOR

        public static final java.lang.String ATTRIBUTE_STYLE_BACKGROUND_COLOR
        See Also:
        Constant Field Values
      • ATTRIBUTE_STYLE_FONT_SIZE

        public static final java.lang.String ATTRIBUTE_STYLE_FONT_SIZE
        See Also:
        Constant Field Values
      • ATTRIBUTE_STYLE_FONT_FAMILY

        public static final java.lang.String ATTRIBUTE_STYLE_FONT_FAMILY
        See Also:
        Constant Field Values
      • ATTRIBUTE_PARAGRAPH_MARGIN_LEFT

        public static final java.lang.String ATTRIBUTE_PARAGRAPH_MARGIN_LEFT
        See Also:
        Constant Field Values
      • ATTRIBUTE_PARAGRAPH_TEXT_ALIGN

        public static final java.lang.String ATTRIBUTE_PARAGRAPH_TEXT_ALIGN
        See Also:
        Constant Field Values
      • ATTRIBUTE_PARAGRAPH_TEXT_ALIGN_VALUE_RIGHT

        public static final java.lang.String ATTRIBUTE_PARAGRAPH_TEXT_ALIGN_VALUE_RIGHT
        See Also:
        Constant Field Values
      • CONTROL_CHARACTER_REGEX

        public static final java.lang.String CONTROL_CHARACTER_REGEX
        See Also:
        Constant Field Values
      • FAKE_ROOT_TAG_START

        public static final java.lang.String FAKE_ROOT_TAG_START
        See Also:
        Constant Field Values
      • FAKE_ROOT_TAG_END

        public static final java.lang.String FAKE_ROOT_TAG_END
        See Also:
        Constant Field Values
      • BULLETS

        public static final java.lang.String[] BULLETS
      • paragraphSpace

        private int paragraphSpace
      • wordWrap

        private boolean wordWrap
      • preferredSize

        private final org.eclipse.swt.graphics.Point preferredSize
      • factory

        javax.xml.stream.XMLInputFactory factory
      • wordSplitRegex

        private java.lang.String wordSplitRegex
    • Constructor Detail

      • RichTextPainter

        public RichTextPainter()
        Create a new RichTextPainter with disabled word wrapping.
      • RichTextPainter

        public RichTextPainter​(boolean wordWrap)
        Create a new RichTextPainter.
        Parameters:
        wordWrap - true if automatic word wrapping should be enabled, false if not.
    • Method Detail

      • preCalculate

        public 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. Does not perform rendering.
        Parameters:
        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 not
      • paintHTML

        public 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.
        Parameters:
        html - The HTML string to process.
        gc - The GC to operate on.
        bounds - The available space for painting.
      • paintHTML

        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.
        Parameters:
        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).
      • handleAlignmentConfiguration

        private AlignmentStyle handleAlignmentConfiguration​(javax.xml.stream.events.StartElement element)
      • getStyleProperties

        private java.util.Map<java.lang.String,​java.lang.String> getStyleProperties​(java.lang.String styleString)
      • calculateListIndentation

        protected int calculateListIndentation​(org.eclipse.swt.graphics.GC gc)
        Calculates the indentation to use for list items.
        Parameters:
        gc - The current GC for calculating the text extend.
        Returns:
        The indentation to use for list items.
      • getBulletCharacter

        protected java.lang.String getBulletCharacter​(int listDepth)
        Parameters:
        listDepth - The list depth of the current list. Needs to be 1 for the top level list.
        Returns:
        The bullet character to use for list items of an unordered list.
      • setEntityReplacer

        public void setEntityReplacer​(EntityReplacer entityReplacer)
        Set an EntityReplacer that should be used to replace EntityReferences in the HTML snippet to parse.
        Parameters:
        entityReplacer - The EntityReplacer to use.
      • getPreferredSize

        public org.eclipse.swt.graphics.Point getPreferredSize()
        Returns the preferred size of the content. It is calculated after processing the content.
        Returns:
        The preferred size of the content.
        See Also:
        preCalculate(String, GC, Rectangle, boolean)
      • getParagraphSpace

        public int getParagraphSpace()
        Returns:
        The space that should be used before and after a paragraph.
        Note: Between two paragraphs the paragraphSpace * 2 is added as space.
      • setParagraphSpace

        public void setParagraphSpace​(int paragraphSpace)
        Parameters:
        paragraphSpace - The space that should be applied before and after a paragraph.
        Note: Between two paragraphs the paragraphSpace * 2 is added as space.
      • setWordSplitRegex

        public void setWordSplitRegex​(java.lang.String wordSplitRegex)
        Parameters:
        wordSplitRegex - The regular expression that will be used to determine word boundaries. The default is "\s".
        Since:
        1.3.0