Class WCanvasPaintDevice

java.lang.Object
eu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WCanvasPaintDevice
All Implemented Interfaces:
WPaintDevice

public class WCanvasPaintDevice extends WObject implements WPaintDevice
A paint device for rendering using the HTML 5 <canvas> element.

The WCanvasPaintDevice is used by WPaintedWidget to render to the browser using the HTML 5 <canvas> element. You usually will not use the device directly, but rather rely on WPaintedWidget to use this device when appropriate.

Note: Older browsers do not have text support in <canvas>. Text is then rendered in an overlayed DIV and a consequence text is not subject to rotation and scaling components of the current transformation (but does take into account translation). On most browser you can use the WSvgImage or WVmlImage paint devices which do support text natively.

  • Constructor Details

    • WCanvasPaintDevice

      public WCanvasPaintDevice(WLength width, WLength height, boolean paintUpdate)
      Create a canvas paint device.
    • WCanvasPaintDevice

      public WCanvasPaintDevice(WLength width, WLength height)
      Create a canvas paint device.

      Calls this(width, height, false)

  • Method Details

    • getFeatures

      public EnumSet<PaintDeviceFeatureFlag> getFeatures()
      Description copied from interface: WPaintDevice
      Returns device features.
      Specified by:
      getFeatures in interface WPaintDevice
    • setChanged

      public void setChanged(EnumSet<PainterChangeFlag> flags)
      Description copied from interface: WPaintDevice
      Indicates changes in painter state.

      The flags argument is the logical OR of one or more change flags.

      Specified by:
      setChanged in interface WPaintDevice
    • drawArc

      public void drawArc(WRectF rect, double startAngle, double spanAngle)
      Description copied from interface: WPaintDevice
      Draws an arc.

      The arc describes the segment of an ellipse enclosed by the rect. The segment starts at startAngle, and spans an angle given by spanAngle. These angles have as unit degree, and are measured counter-clockwise starting from the 3 o'clock position.

      The arc must be stroked, filled, and transformed using the current painter settings.

      Specified by:
      drawArc in interface WPaintDevice
    • drawImage

      public void drawImage(WRectF rect, String imageUri, int imgWidth, int imgHeight, WRectF sourceRect)
      Description copied from interface: WPaintDevice
      Draws an image.

      Draws sourceRect from the image with URL imageUri and original dimensions imgWidth and imgHeight to the location, into the rectangle defined by rect.

      The image is transformed using the current painter settings.

      Specified by:
      drawImage in interface WPaintDevice
    • drawLine

      public void drawLine(double x1, double y1, double x2, double y2)
      Description copied from interface: WPaintDevice
      Draws a line.

      The line must be stroked and transformed using the current painter settings.

      Specified by:
      drawLine in interface WPaintDevice
    • drawPath

      public void drawPath(WPainterPath path)
      Description copied from interface: WPaintDevice
      Draws a path.

      The path must be stroked, filled, and transformed using the current painter settings.

      Specified by:
      drawPath in interface WPaintDevice
    • drawStencilAlongPath

      public void drawStencilAlongPath(WPainterPath stencil, WPainterPath path, boolean softClipping)
    • drawRect

      public void drawRect(WRectF rectangle)
      Description copied from interface: WPaintDevice
      Draws a rectangle.

      The rect must be stroked, filled, and transformed using the current painter settings.

      Specified by:
      drawRect in interface WPaintDevice
    • drawText

      public void drawText(WRectF rect, EnumSet<AlignmentFlag> flags, TextFlag textFlag, CharSequence text, WPointF clipPoint)
      Description copied from interface: WPaintDevice
      Draws text.

      The text must be rendered, stroked and transformed using the current painter settings.

      If clipPoint is not null, a check is performed whether the point is inside of the current clip area. If not, the text is not drawn.

      Specified by:
      drawText in interface WPaintDevice
    • drawTextOnPath

      public void drawTextOnPath(WRectF rect, EnumSet<AlignmentFlag> alignmentFlags, List<WString> text, WTransform transform, WPainterPath path, double angle, double lineHeight, boolean softClipping)
    • measureText

      public WTextItem measureText(CharSequence text, double maxWidth, boolean wordWrap)
      Description copied from interface: WPaintDevice
      Measures rendered text size.

      Returns the bounding rect of the given text when rendered using the current font.

      If maxWidth != -1, then the text is truncated to fit in the width.

      If wordWrap = true then text is truncated only at word boundaries. Note that in this case the whitespace at the truncated position is included in the text but not accounted for by the returned width (since usually you will not render the whitespace at the end of a line).

      Throws a std::logic_error if the underlying device does not provide font metrics.

      Specified by:
      measureText in interface WPaintDevice
    • getFontMetrics

      public WFontMetrics getFontMetrics()
      Description copied from interface: WPaintDevice
      Returns font metrics.

      This returns font metrics for the current font.

      Throws a std::logic_error if the underlying device does not provide font metrics.

      Specified by:
      getFontMetrics in interface WPaintDevice
    • init

      public void init()
      Description copied from interface: WPaintDevice
      Initializes the device for painting.

      This method is called when a WPainter starts painting.

      Specified by:
      init in interface WPaintDevice
      See Also:
    • done

      public void done()
      Description copied from interface: WPaintDevice
      Finishes painting on the device.

      This method is called when a WPainter stopped painting.

      Specified by:
      done in interface WPaintDevice
      See Also:
    • isPaintActive

      public boolean isPaintActive()
      Description copied from interface: WPaintDevice
      Returns whether painting is active.

      Specified by:
      isPaintActive in interface WPaintDevice
      See Also:
    • render

      public void render(String paintedWidgetJsRef, String canvasId, DomElement text, String updateAreasJs)
    • renderPaintCommands

      public void renderPaintCommands(StringWriter js_target, String canvasElement)
    • getWidth

      public WLength getWidth()
      Description copied from interface: WPaintDevice
      Returns the device width.

      The device width, in pixels, establishes the width of the device coordinate system.

      Specified by:
      getWidth in interface WPaintDevice
    • getHeight

      public WLength getHeight()
      Description copied from interface: WPaintDevice
      Returns the device height.

      The device height, in pixels, establishes the height of the device coordinate system.

      Specified by:
      getHeight in interface WPaintDevice
    • getPainter

      public WPainter getPainter()
      Description copied from interface: WPaintDevice
      Returns the painter that is currently painting on the device.

      Specified by:
      getPainter in interface WPaintDevice
      See Also:
    • setPainter

      public void setPainter(WPainter painter)
      Description copied from interface: WPaintDevice
      Sets the painter.
      Specified by:
      setPainter in interface WPaintDevice