Class HtmlGraphicsContext

java.lang.Object
dev.webfx.kit.mapper.peers.javafxgraphics.gwtj2cl.html.HtmlGraphicsContext
All Implemented Interfaces:
GraphicsContext

public class HtmlGraphicsContext extends Object implements GraphicsContext
Author:
Bruno Salmon
  • Constructor Summary

    Constructors
    Constructor
    Description
    HtmlGraphicsContext(Canvas canvas, boolean willReadFrequently)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Appends an SVG Path string to the current path.
    void
    Applies the given effect to the entire bounds of the canvas and stores the result back into the same canvas.
    void
    arc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length)
    Adds path elements to the current path to make an arc that uses Euclidean degrees.
    void
    arcTo(double x1, double y1, double x2, double y2, double radius)
    Adds segments to the current path to make an arc.
    void
    Resets the current path to empty.
    void
    bezierCurveTo(double xc1, double yc1, double xc2, double yc2, double x1, double y1)
    Adds segments to the current path to make a cubic Bezier curve.
    void
    clearRect(double x, double y, double w, double h)
    Clears a portion of the canvas with a transparent color value.
    void
    Intersects the current clip with the current path and applies it to subsequent rendering operation as an anti-aliased mask.
    void
    Closes the path.
    void
    drawImage(Image img, double x, double y)
    Draws an image at the given x, y position using the width and height of the given image.
    void
    drawImage(Image img, double x, double y, double w, double h)
    Draws an image into the given destination rectangle of the canvas.
    void
    drawImage(Image img, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)
    Draws the specified source rectangle of the given image to the given destination rectangle of the Canvas.
    void
    Fills the path with the current fill paint.
    void
    fillArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)
    Fills an arc using the current fill paint.
    void
    fillPolygon(double[] xPoints, double[] yPoints, int nPoints)
    Fills a polygon with the given points using the currently set fill paint.
    void
    fillRect(double x, double y, double w, double h)
    Fills a rectangle using the current fill paint.
    void
    fillRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)
    Fills a rounded rectangle using the current fill paint.
    void
    fillText(String text, double x, double y)
    Fills the given string of text at position x, y with the current fill paint attribute.
    void
    fillText(String text, double x, double y, double maxWidth)
    Fills text and includes a maximum width of the string.
    Gets the Canvas that the GraphicsContext is issuing draw commands to.
    Gets a copy of the effect to be applied after the next draw call.
    Gets the current fill paint attribute.
    Gets the current Font.
    double
    Gets the current global alpha.
    Gets the global blend mode.
    static elemental2.dom.HTMLImageElement
     
    Gets the current stroke line cap.
    double[]
    Gets a copy of the current line dash array.
    double
    Gets the current line dash offset.
    Gets the current stroke line join.
    double
    Gets the current line width.
    double
    Gets the current miter limit.
    Returns a PixelWriter object that can be used to modify the pixels of the Canvas associated with this GraphicsContext.
    Gets the current stroke.
    Gets the current TextAlignment.
    Gets the current Text Baseline.
    Copies the current transform into the supplied object, creating a new Affine object if it is null, and returns the object containing the copy.
    boolean
    Gets the current image smoothing state.
    boolean
    isPointInPath(double x, double y)
    Returns true if the the given x,y point is inside the path.
    void
    lineTo(double x1, double y1)
    Adds segments to the current path to make a line to the given x,y coordinate.
    void
    moveTo(double x0, double y0)
    Issues a move command for the current path to the given x,y coordinate.
    void
    quadraticCurveTo(double xc, double yc, double x1, double y1)
    Adds segments to the current path to make a quadratic Bezier curve.
    void
    rect(double x, double y, double w, double h)
    Adds path elements to the current path to make a rectangle.
    void
    Pops the state off of the stack, setting the following attributes to their value at the time when that state was pushed onto the stack.
    void
    rotate(double degrees)
    Rotates the current transform in degrees.
    void
    Saves the following attributes onto a stack.
    void
    scale(double x, double y)
    Scales the current transform by x, y.
    void
    Sets the effect to be applied after the next draw call, or null to disable effects.
    void
    Sets the current fill paint attribute.
    void
    Sets the current Font.
    void
    setGlobalAlpha(double alpha)
    Sets the global alpha of the current state.
    void
    Sets the global blend mode.
    void
    setImageSmoothing(boolean imageSmoothing)
    Sets the image smoothing state.
    void
    Sets the current stroke line cap.
    void
    setLineDashes(double... dashes)
    Sets the current stroke line dash pattern to a normalized copy of the argument.
    void
    setLineDashOffset(double dashOffset)
    Sets the line dash offset.
    void
    Sets the current stroke line join.
    void
    setLineWidth(double lw)
    Sets the current line width.
    void
    setMiterLimit(double ml)
    Sets the current miter limit.
    void
    Sets the current stroke paint attribute.
    void
    Defines horizontal text alignment, relative to the text x origin.
    void
    Sets the current Text Baseline.
    void
    setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt)
    Sets the current transform.
    void
    Strokes the path with the current stroke paint.
    void
    strokeArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)
    Strokes an Arc using the current stroke paint.
    void
    strokeLine(double x1, double y1, double x2, double y2)
    Strokes a line using the current stroke paint.
    void
    strokePolygon(double[] xPoints, double[] yPoints, int nPoints)
    Strokes a polygon with the given points using the currently set stroke paint.
    void
    strokePolyline(double[] xPoints, double[] yPoints, int nPoints)
    Strokes a polyline with the given points using the currently set stroke paint attribute.
    void
    strokeRect(double x, double y, double w, double h)
    Strokes a rectangle using the current stroke paint.
    void
    strokeRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)
    Strokes a rounded rectangle using the current stroke paint.
    void
    strokeText(String text, double x, double y)
    Draws the given string of text at position x, y with the current stroke paint attribute.
    void
    strokeText(String text, double x, double y, double maxWidth)
    Draws text with stroke paint and includes a maximum width of the string.
    void
    transform(double mxx, double myx, double mxy, double myy, double mxt, double myt)
    Concatenates the input with the current transform.
    void
    translate(double x, double y)
    Translates the current transform by x, y.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface javafx.scene.canvas.GraphicsContext

    fillOval, getTransform, setTransform, strokeOval, transform
  • Constructor Details

    • HtmlGraphicsContext

      public HtmlGraphicsContext(Canvas canvas, boolean willReadFrequently)
  • Method Details

    • getCanvas

      public Canvas getCanvas()
      Description copied from interface: GraphicsContext
      Gets the Canvas that the GraphicsContext is issuing draw commands to. There is only ever one Canvas for a GraphicsContext.
      Specified by:
      getCanvas in interface GraphicsContext
      Returns:
      Canvas the canvas that this GraphicsContext is issuing draw commands to.
    • save

      public void save()
      Description copied from interface: GraphicsContext
      Saves the following attributes onto a stack.
      • Global Alpha
      • Global Blend Operation
      • Transform
      • Fill Paint
      • Stroke Paint
      • Line Width
      • Line Cap
      • Line Join
      • Miter Limit
      • Clip
      • Font
      • Text Align
      • Text Baseline
      • Effect
      • Fill Rule
      This method does NOT alter the current state in any way. Also, note that the current path is not saved.
      Specified by:
      save in interface GraphicsContext
    • restore

      public void restore()
      Description copied from interface: GraphicsContext
      Pops the state off of the stack, setting the following attributes to their value at the time when that state was pushed onto the stack. If the stack is empty then nothing is changed.
      • Global Alpha
      • Global Blend Operation
      • Transform
      • Fill Paint
      • Stroke Paint
      • Line Width
      • Line Cap
      • Line Join
      • Miter Limit
      • Clip
      • Font
      • Text Align
      • Text Baseline
      • Effect
      • Fill Rule
      Note that the current path is not restored.
      Specified by:
      restore in interface GraphicsContext
    • translate

      public void translate(double x, double y)
      Description copied from interface: GraphicsContext
      Translates the current transform by x, y.
      Specified by:
      translate in interface GraphicsContext
      Parameters:
      x - value to translate along the x axis.
      y - value to translate along the y axis.
    • scale

      public void scale(double x, double y)
      Description copied from interface: GraphicsContext
      Scales the current transform by x, y.
      Specified by:
      scale in interface GraphicsContext
      Parameters:
      x - value to scale in the x axis.
      y - value to scale in the y axis.
    • rotate

      public void rotate(double degrees)
      Description copied from interface: GraphicsContext
      Rotates the current transform in degrees.
      Specified by:
      rotate in interface GraphicsContext
      Parameters:
      degrees - value in degrees to rotate the current transform.
    • transform

      public void transform(double mxx, double myx, double mxy, double myy, double mxt, double myt)
      Description copied from interface: GraphicsContext
      Concatenates the input with the current transform.
      Specified by:
      transform in interface GraphicsContext
      Parameters:
      mxx - - the X coordinate scaling element of the 3x4 matrix
      myx - - the Y coordinate shearing element of the 3x4 matrix
      mxy - - the X coordinate shearing element of the 3x4 matrix
      myy - - the Y coordinate scaling element of the 3x4 matrix
      mxt - - the X coordinate translation element of the 3x4 matrix
      myt - - the Y coordinate translation element of the 3x4 matrix
    • setTransform

      public void setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt)
      Description copied from interface: GraphicsContext
      Sets the current transform.
      Specified by:
      setTransform in interface GraphicsContext
      Parameters:
      mxx - - the X coordinate scaling element of the 3x4 matrix
      myx - - the Y coordinate shearing element of the 3x4 matrix
      mxy - - the X coordinate shearing element of the 3x4 matrix
      myy - - the Y coordinate scaling element of the 3x4 matrix
      mxt - - the X coordinate translation element of the 3x4 matrix
      myt - - the Y coordinate translation element of the 3x4 matrix
    • getTransform

      public Affine getTransform(Affine xform)
      Description copied from interface: GraphicsContext
      Copies the current transform into the supplied object, creating a new Affine object if it is null, and returns the object containing the copy.
      Specified by:
      getTransform in interface GraphicsContext
      Parameters:
      xform - A transform object that will be used to hold the result. If xform is non null, then this method will copy the current transform into that object. If xform is null a new transform object will be constructed. In either case, the return value is a copy of the current transform.
      Returns:
      A copy of the current transform.
    • setGlobalAlpha

      public void setGlobalAlpha(double alpha)
      Description copied from interface: GraphicsContext
      Sets the global alpha of the current state. The default value is 1.0. Any valid double can be set, but only values in the range [0.0, 1.0] are valid and the nearest value in that range will be used for rendering. The global alpha is a common attribute used for nearly all rendering methods as specified in the Rendering Attributes Table.
      Specified by:
      setGlobalAlpha in interface GraphicsContext
      Parameters:
      alpha - the new alpha value, clamped to [0.0, 1.0] during actual use.
    • getGlobalAlpha

      public double getGlobalAlpha()
      Description copied from interface: GraphicsContext
      Gets the current global alpha. The default value is 1.0. The global alpha is a common attribute used for nearly all rendering methods as specified in the Rendering Attributes Table.
      Specified by:
      getGlobalAlpha in interface GraphicsContext
      Returns:
      the current global alpha.
    • setGlobalBlendMode

      public void setGlobalBlendMode(BlendMode op)
      Description copied from interface: GraphicsContext
      Sets the global blend mode. The default value is SRC_OVER. A null value will be ignored and the current value will remain unchanged. The blend mode is a common attribute used for nearly all rendering methods as specified in the Rendering Attributes Table.
      Specified by:
      setGlobalBlendMode in interface GraphicsContext
      Parameters:
      op - the BlendMode that will be set or null.
    • getGlobalBlendMode

      public BlendMode getGlobalBlendMode()
      Description copied from interface: GraphicsContext
      Gets the global blend mode. The default value is SRC_OVER. The blend mode is a common attribute used for nearly all rendering methods as specified in the Rendering Attributes Table.
      Specified by:
      getGlobalBlendMode in interface GraphicsContext
      Returns:
      the global BlendMode of the current state.
    • setFill

      public void setFill(Paint p)
      Description copied from interface: GraphicsContext
      Sets the current fill paint attribute. The default value is BLACK. The fill paint is a fill attribute used for any of the fill methods as specified in the Rendering Attributes Table. A null value will be ignored and the current value will remain unchanged.
      Specified by:
      setFill in interface GraphicsContext
      Parameters:
      p - The Paint to be used as the fill Paint or null.
    • getFill

      public Paint getFill()
      Description copied from interface: GraphicsContext
      Gets the current fill paint attribute. The default value is BLACK. The fill paint is a fill attribute used for any of the fill methods as specified in the Rendering Attributes Table.
      Specified by:
      getFill in interface GraphicsContext
      Returns:
      p The Paint to be used as the fill Paint.
    • setStroke

      public void setStroke(Paint p)
      Description copied from interface: GraphicsContext
      Sets the current stroke paint attribute. The default value is BLACK. The stroke paint is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table. A null value will be ignored and the current value will remain unchanged.
      Specified by:
      setStroke in interface GraphicsContext
      Parameters:
      p - The Paint to be used as the stroke Paint or null.
    • getStroke

      public Paint getStroke()
      Description copied from interface: GraphicsContext
      Gets the current stroke. The default value is BLACK. The stroke paint is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table.
      Specified by:
      getStroke in interface GraphicsContext
      Returns:
      the Paint to be used as the stroke Paint.
    • setLineWidth

      public void setLineWidth(double lw)
      Description copied from interface: GraphicsContext
      Sets the current line width. The default value is 1.0. The line width is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table. An infinite or non-positive value outside of the range (0, +inf) will be ignored and the current value will remain unchanged.
      Specified by:
      setLineWidth in interface GraphicsContext
      Parameters:
      lw - value in the range {0-positive infinity}, with any other value being ignored and leaving the value unchanged.
    • getLineWidth

      public double getLineWidth()
      Description copied from interface: GraphicsContext
      Gets the current line width. The default value is 1.0. The line width is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table.
      Specified by:
      getLineWidth in interface GraphicsContext
      Returns:
      value between 0 and infinity.
    • setLineCap

      public void setLineCap(StrokeLineCap cap)
      Description copied from interface: GraphicsContext
      Sets the current stroke line cap. The default value is SQUARE. The line cap is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table. A null value will be ignored and the current value will remain unchanged.
      Specified by:
      setLineCap in interface GraphicsContext
      Parameters:
      cap - StrokeLineCap with a value of Butt, Round, or Square or null.
    • getLineCap

      public StrokeLineCap getLineCap()
      Description copied from interface: GraphicsContext
      Gets the current stroke line cap. The default value is SQUARE. The line cap is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table.
      Specified by:
      getLineCap in interface GraphicsContext
      Returns:
      StrokeLineCap with a value of Butt, Round, or Square.
    • setLineJoin

      public void setLineJoin(StrokeLineJoin join)
      Description copied from interface: GraphicsContext
      Sets the current stroke line join. The default value is StrokeLineJoin.MITER. The line join is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table. A null value will be ignored and the current value will remain unchanged.
      Specified by:
      setLineJoin in interface GraphicsContext
      Parameters:
      join - StrokeLineJoin with a value of Miter, Bevel, or Round or null.
    • getLineJoin

      public StrokeLineJoin getLineJoin()
      Description copied from interface: GraphicsContext
      Gets the current stroke line join. The default value is StrokeLineJoin.MITER. The line join is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table.
      Specified by:
      getLineJoin in interface GraphicsContext
      Returns:
      StrokeLineJoin with a value of Miter, Bevel, or Round.
    • setMiterLimit

      public void setMiterLimit(double ml)
      Description copied from interface: GraphicsContext
      Sets the current miter limit. The default value is 10.0. The miter limit is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table. An infinite or non-positive value outside of the range (0, +inf) will be ignored and the current value will remain unchanged.
      Specified by:
      setMiterLimit in interface GraphicsContext
      Parameters:
      ml - miter limit value between 0 and positive infinity with any other value being ignored and leaving the value unchanged.
    • getMiterLimit

      public double getMiterLimit()
      Description copied from interface: GraphicsContext
      Gets the current miter limit. The default value is 10.0. The miter limit is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table.
      Specified by:
      getMiterLimit in interface GraphicsContext
      Returns:
      the miter limit value in the range 0.0-positive infinity
    • setLineDashes

      public void setLineDashes(double... dashes)
      Description copied from interface: GraphicsContext
      Sets the current stroke line dash pattern to a normalized copy of the argument. The default value is null. The line dash array is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table. If the array is null or empty or contains all 0 elements then dashing will be disabled and the current dash array will be set to null. If any of the elements of the array are a negative, infinite, or NaN value outside the range [0, +inf) then the entire array will be ignored and the current dash array will remain unchanged. If the array is an odd length then it will be treated as if it were two copies of the array appended to each other.
      Specified by:
      setLineDashes in interface GraphicsContext
      Parameters:
      dashes - the array of finite non-negative dash lengths
    • getLineDashes

      public double[] getLineDashes()
      Description copied from interface: GraphicsContext
      Gets a copy of the current line dash array. The default value is null. The array may be normalized by the validation tests in the GraphicsContext.setLineDashes(double...) method. The line dash array is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table.
      Specified by:
      getLineDashes in interface GraphicsContext
      Returns:
      a copy of the current line dash array.
    • setLineDashOffset

      public void setLineDashOffset(double dashOffset)
      Description copied from interface: GraphicsContext
      Sets the line dash offset. The default value is 0.0. The line dash offset is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table. An infinite or NaN value outside of the range (-inf, +inf) will be ignored and the current value will remain unchanged.
      Specified by:
      setLineDashOffset in interface GraphicsContext
      Parameters:
      dashOffset - the line dash offset in the range (-inf, +inf)
    • getLineDashOffset

      public double getLineDashOffset()
      Description copied from interface: GraphicsContext
      Gets the current line dash offset. The default value is 0.0. The line dash offset is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table.
      Specified by:
      getLineDashOffset in interface GraphicsContext
      Returns:
      the line dash offset in the range (-inf, +inf)
    • setFont

      public void setFont(Font f)
      Description copied from interface: GraphicsContext
      Sets the current Font. The default value is specified by Font.getDefault(). The font is a text attribute used for any of the text methods as specified in the Rendering Attributes Table. A null value will be ignored and the current value will remain unchanged.
      Specified by:
      setFont in interface GraphicsContext
      Parameters:
      f - the Font or null.
    • getFont

      public Font getFont()
      Description copied from interface: GraphicsContext
      Gets the current Font. The default value is specified by Font.getDefault(). The font is a text attribute used for any of the text methods as specified in the Rendering Attributes Table.
      Specified by:
      getFont in interface GraphicsContext
      Returns:
      the Font
    • setTextAlign

      public void setTextAlign(TextAlignment align)
      Description copied from interface: GraphicsContext
      Defines horizontal text alignment, relative to the text x origin. The default value is LEFT. The text alignment is a text attribute used for any of the text methods as specified in the Rendering Attributes Table.

      Let horizontal bounds represent the logical width of a single line of text. Where each line of text has a separate horizontal bounds.

      Then TextAlignment is specified as:

      • Left: the left edge of the horizontal bounds will be at x.
      • Center: the center, halfway between left and right edge, of the horizontal bounds will be at x.
      • Right: the right edge of the horizontal bounds will be at x.

      Note: Canvas does not support line wrapping, therefore the text alignment Justify is identical to left aligned text.

      A null value will be ignored and the current value will remain unchanged.

      Specified by:
      setTextAlign in interface GraphicsContext
      Parameters:
      align - TextAlignment with values of Left, Center, Right or null.
    • getTextAlign

      public TextAlignment getTextAlign()
      Description copied from interface: GraphicsContext
      Gets the current TextAlignment. The default value is LEFT. The text alignment is a text attribute used for any of the text methods as specified in the Rendering Attributes Table.
      Specified by:
      getTextAlign in interface GraphicsContext
      Returns:
      TextAlignment with values of Left, Center, Right, or Justify.
    • setTextBaseline

      public void setTextBaseline(VPos baseline)
      Description copied from interface: GraphicsContext
      Sets the current Text Baseline. The default value is BASELINE. The text baseline is a text attribute used for any of the text methods as specified in the Rendering Attributes Table. A null value will be ignored and the current value will remain unchanged.
      Specified by:
      setTextBaseline in interface GraphicsContext
      Parameters:
      baseline - VPos with values of Top, Center, Baseline, or Bottom or null.
    • getTextBaseline

      public VPos getTextBaseline()
      Description copied from interface: GraphicsContext
      Gets the current Text Baseline. The default value is BASELINE. The text baseline is a text attribute used for any of the text methods as specified in the Rendering Attributes Table.
      Specified by:
      getTextBaseline in interface GraphicsContext
      Returns:
      VPos with values of Top, Center, Baseline, or Bottom
    • fillText

      public void fillText(String text, double x, double y)
      Description copied from interface: GraphicsContext
      Fills the given string of text at position x, y with the current fill paint attribute. A null text value will be ignored.

      This method will be affected by any of the global common, fill, or text attributes as specified in the Rendering Attributes Table.

      Specified by:
      fillText in interface GraphicsContext
      Parameters:
      text - the string of text or null.
      x - position on the x axis.
      y - position on the y axis.
    • strokeText

      public void strokeText(String text, double x, double y)
      Description copied from interface: GraphicsContext
      Draws the given string of text at position x, y with the current stroke paint attribute. A null text value will be ignored.

      This method will be affected by any of the global common, stroke, or text attributes as specified in the Rendering Attributes Table.

      Specified by:
      strokeText in interface GraphicsContext
      Parameters:
      text - the string of text or null.
      x - position on the x axis.
      y - position on the y axis.
    • fillText

      public void fillText(String text, double x, double y, double maxWidth)
      Description copied from interface: GraphicsContext
      Fills text and includes a maximum width of the string. If the width of the text extends past max width, then it will be sized to fit. A null text value will be ignored.

      This method will be affected by any of the global common, fill, or text attributes as specified in the Rendering Attributes Table.

      Specified by:
      fillText in interface GraphicsContext
      Parameters:
      text - the string of text or null.
      x - position on the x axis.
      y - position on the y axis.
      maxWidth - maximum width the text string can have.
    • strokeText

      public void strokeText(String text, double x, double y, double maxWidth)
      Description copied from interface: GraphicsContext
      Draws text with stroke paint and includes a maximum width of the string. If the width of the text extends past max width, then it will be sized to fit. A null text value will be ignored.

      This method will be affected by any of the global common, stroke, or text attributes as specified in the Rendering Attributes Table.

      Specified by:
      strokeText in interface GraphicsContext
      Parameters:
      text - the string of text or null.
      x - position on the x axis.
      y - position on the y axis.
      maxWidth - maximum width the text string can have.
    • beginPath

      public void beginPath()
      Description copied from interface: GraphicsContext
      Resets the current path to empty. The default path is empty. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table and is not affected by the GraphicsContext.save() and GraphicsContext.restore() operations.
      Specified by:
      beginPath in interface GraphicsContext
    • moveTo

      public void moveTo(double x0, double y0)
      Description copied from interface: GraphicsContext
      Issues a move command for the current path to the given x,y coordinate. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table and is not affected by the GraphicsContext.save() and GraphicsContext.restore() operations.
      Specified by:
      moveTo in interface GraphicsContext
      Parameters:
      x0 - the X position for the move to command.
      y0 - the Y position for the move to command.
    • lineTo

      public void lineTo(double x1, double y1)
      Description copied from interface: GraphicsContext
      Adds segments to the current path to make a line to the given x,y coordinate. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table and is not affected by the GraphicsContext.save() and GraphicsContext.restore() operations.
      Specified by:
      lineTo in interface GraphicsContext
      Parameters:
      x1 - the X coordinate of the ending point of the line.
      y1 - the Y coordinate of the ending point of the line.
    • quadraticCurveTo

      public void quadraticCurveTo(double xc, double yc, double x1, double y1)
      Description copied from interface: GraphicsContext
      Adds segments to the current path to make a quadratic Bezier curve. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table and is not affected by the GraphicsContext.save() and GraphicsContext.restore() operations.
      Specified by:
      quadraticCurveTo in interface GraphicsContext
      Parameters:
      xc - the X coordinate of the control point
      yc - the Y coordinate of the control point
      x1 - the X coordinate of the end point
      y1 - the Y coordinate of the end point
    • bezierCurveTo

      public void bezierCurveTo(double xc1, double yc1, double xc2, double yc2, double x1, double y1)
      Description copied from interface: GraphicsContext
      Adds segments to the current path to make a cubic Bezier curve. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table and is not affected by the GraphicsContext.save() and GraphicsContext.restore() operations.
      Specified by:
      bezierCurveTo in interface GraphicsContext
      Parameters:
      xc1 - the X coordinate of first Bezier control point.
      yc1 - the Y coordinate of the first Bezier control point.
      xc2 - the X coordinate of the second Bezier control point.
      yc2 - the Y coordinate of the second Bezier control point.
      x1 - the X coordinate of the end point.
      y1 - the Y coordinate of the end point.
    • arcTo

      public void arcTo(double x1, double y1, double x2, double y2, double radius)
      Description copied from interface: GraphicsContext
      Adds segments to the current path to make an arc. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table and is not affected by the GraphicsContext.save() and GraphicsContext.restore() operations.

      If p0 is the current point in the path and p1 is the point specified by (x1, y1) and p2 is the point specified by (x2, y2), then the arc segments appended will be segments along the circumference of a circle of the specified radius touching and inscribed into the convex (interior) side of p0->p1->p2. The path will contain a line segment (if needed) to the tangent point between that circle and p0->p1 followed by circular arc segments to reach the tangent point between the circle and p1->p2 and will end with the current point at that tangent point (not at p2). Note that the radius and circularity of the arc segments will be measured or considered relative to the current transform, but the resulting segments that are computed from those untransformed points will then be transformed when they are added to the path. Since all computation is done in untransformed space, but the pre-existing path segments are all transformed, the ability to correctly perform the computation may implicitly depend on being able to inverse transform the current end of the current path back into untransformed coordinates.

      If there is no way to compute and inscribe the indicated circle for any reason then the entire operation will simply append segments to force a line to point p1. Possible reasons that the computation may fail include:

      • The current path is empty.
      • The segments p0->p1->p2 are colinear.
      • the current transform is non-invertible so that the current end point of the current path cannot be untransformed for computation.
      Specified by:
      arcTo in interface GraphicsContext
      Parameters:
      x1 - the X coordinate of the first point of the arc.
      y1 - the Y coordinate of the first point of the arc.
      x2 - the X coordinate of the second point of the arc.
      y2 - the Y coordinate of the second point of the arc.
      radius - the radius of the arc in the range {0.0-positive infinity}.
    • arc

      public void arc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length)
      Description copied from interface: GraphicsContext
      Adds path elements to the current path to make an arc that uses Euclidean degrees. This Euclidean orientation sweeps from East to North, then West, then South, then back to East. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table and is not affected by the GraphicsContext.save() and GraphicsContext.restore() operations.
      Specified by:
      arc in interface GraphicsContext
      Parameters:
      centerX - the center x position of the arc.
      centerY - the center y position of the arc.
      radiusX - the x radius of the arc.
      radiusY - the y radius of the arc.
      startAngle - the starting angle of the arc in the range 0-360.0
      length - the length of the baseline of the arc.
    • rect

      public void rect(double x, double y, double w, double h)
      Description copied from interface: GraphicsContext
      Adds path elements to the current path to make a rectangle. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table and is not affected by the GraphicsContext.save() and GraphicsContext.restore() operations.
      Specified by:
      rect in interface GraphicsContext
      Parameters:
      x - x position of the upper left corner of the rectangle.
      y - y position of the upper left corner of the rectangle.
      w - width of the rectangle.
      h - height of the rectangle.
    • appendSVGPath

      public void appendSVGPath(String svgPath)
      Description copied from interface: GraphicsContext
      Appends an SVG Path string to the current path. If there is no current path the string must then start with either type of move command. A null value or incorrect SVG path will be ignored. The coordinates are transformed by the current transform as they are added to the path and unaffected by subsequent changes to the transform. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table and is not affected by the GraphicsContext.save() and GraphicsContext.restore() operations.
      Specified by:
      appendSVGPath in interface GraphicsContext
      Parameters:
      svgPath - the SVG Path string.
    • closePath

      public void closePath()
      Description copied from interface: GraphicsContext
      Closes the path. The current path is a path attribute used for any of the path methods as specified in the Rendering Attributes Table and is not affected by the GraphicsContext.save() and GraphicsContext.restore() operations.
      Specified by:
      closePath in interface GraphicsContext
    • fill

      public void fill()
      Description copied from interface: GraphicsContext
      Fills the path with the current fill paint.

      This method will be affected by any of the global common, fill, or path attributes as specified in the Rendering Attributes Table. Note that the path segments were transformed as they were originally added to the current path so the current transform will not affect those path segments again, but it may affect other attributes in affect at the time of the fill() operation.

      Specified by:
      fill in interface GraphicsContext
    • stroke

      public void stroke()
      Description copied from interface: GraphicsContext
      Strokes the path with the current stroke paint.

      This method will be affected by any of the global common, stroke, or path attributes as specified in the Rendering Attributes Table. Note that the path segments were transformed as they were originally added to the current path so the current transform will not affect those path segments again, but it may affect other attributes in affect at the time of the stroke() operation.

      Specified by:
      stroke in interface GraphicsContext
    • clip

      public void clip()
      Description copied from interface: GraphicsContext
      Intersects the current clip with the current path and applies it to subsequent rendering operation as an anti-aliased mask. The current clip is a common attribute used for nearly all rendering operations as specified in the Rendering Attributes Table.

      This method will itself be affected only by the path attributes as specified in the Rendering Attributes Table. Note that the path segments were transformed as they were originally added to the current path so the current transform will not affect those path segments again, but it may affect other attributes in affect at the time of the stroke() operation.

      Specified by:
      clip in interface GraphicsContext
    • isPointInPath

      public boolean isPointInPath(double x, double y)
      Description copied from interface: GraphicsContext
      Returns true if the the given x,y point is inside the path.
      Specified by:
      isPointInPath in interface GraphicsContext
      Parameters:
      x - the X coordinate to use for the check.
      y - the Y coordinate to use for the check.
      Returns:
      true if the point given is inside the path, false otherwise.
    • clearRect

      public void clearRect(double x, double y, double w, double h)
      Description copied from interface: GraphicsContext
      Clears a portion of the canvas with a transparent color value.

      This method will be affected only by the current transform, clip, and effect.

      Specified by:
      clearRect in interface GraphicsContext
      Parameters:
      x - X position of the upper left corner of the rectangle.
      y - Y position of the upper left corner of the rectangle.
      w - width of the rectangle.
      h - height of the rectangle.
    • fillRect

      public void fillRect(double x, double y, double w, double h)
      Description copied from interface: GraphicsContext
      Fills a rectangle using the current fill paint.

      This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table.

      Specified by:
      fillRect in interface GraphicsContext
      Parameters:
      x - the X position of the upper left corner of the rectangle.
      y - the Y position of the upper left corner of the rectangle.
      w - the width of the rectangle.
      h - the height of the rectangle.
    • strokeRect

      public void strokeRect(double x, double y, double w, double h)
      Description copied from interface: GraphicsContext
      Strokes a rectangle using the current stroke paint.

      This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.

      Specified by:
      strokeRect in interface GraphicsContext
      Parameters:
      x - the X position of the upper left corner of the rectangle.
      y - the Y position of the upper left corner of the rectangle.
      w - the width of the rectangle.
      h - the height of the rectangle.
    • fillArc

      public void fillArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)
      Description copied from interface: GraphicsContext
      Fills an arc using the current fill paint. A null ArcType or non positive width or height will cause the render command to be ignored.

      This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table.

      Specified by:
      fillArc in interface GraphicsContext
      Parameters:
      x - the X coordinate of the arc.
      y - the Y coordinate of the arc.
      w - the width of the arc.
      h - the height of the arc.
      startAngle - the starting angle of the arc in degrees.
      arcExtent - the angular extent of the arc in degrees.
      closure - closure type (Round, Chord, Open) or null.
    • strokeArc

      public void strokeArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)
      Description copied from interface: GraphicsContext
      Strokes an Arc using the current stroke paint. A null ArcType or non positive width or height will cause the render command to be ignored.

      This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.

      Specified by:
      strokeArc in interface GraphicsContext
      Parameters:
      x - the X coordinate of the arc.
      y - the Y coordinate of the arc.
      w - the width of the arc.
      h - the height of the arc.
      startAngle - the starting angle of the arc in degrees.
      arcExtent - arcExtent the angular extent of the arc in degrees.
      closure - closure type (Round, Chord, Open) or null
    • fillRoundRect

      public void fillRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)
      Description copied from interface: GraphicsContext
      Fills a rounded rectangle using the current fill paint.

      This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table.

      Specified by:
      fillRoundRect in interface GraphicsContext
      Parameters:
      x - the X coordinate of the upper left bound of the oval.
      y - the Y coordinate of the upper left bound of the oval.
      w - the width at the center of the oval.
      h - the height at the center of the oval.
      arcWidth - the arc width of the rectangle corners.
      arcHeight - the arc height of the rectangle corners.
    • strokeRoundRect

      public void strokeRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)
      Description copied from interface: GraphicsContext
      Strokes a rounded rectangle using the current stroke paint.

      This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.

      Specified by:
      strokeRoundRect in interface GraphicsContext
      Parameters:
      x - the X coordinate of the upper left bound of the oval.
      y - the Y coordinate of the upper left bound of the oval.
      w - the width at the center of the oval.
      h - the height at the center of the oval.
      arcWidth - the arc width of the rectangle corners.
      arcHeight - the arc height of the rectangle corners.
    • strokeLine

      public void strokeLine(double x1, double y1, double x2, double y2)
      Description copied from interface: GraphicsContext
      Strokes a line using the current stroke paint.

      This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.

      Specified by:
      strokeLine in interface GraphicsContext
      Parameters:
      x1 - the X coordinate of the starting point of the line.
      y1 - the Y coordinate of the starting point of the line.
      x2 - the X coordinate of the ending point of the line.
      y2 - the Y coordinate of the ending point of the line.
    • fillPolygon

      public void fillPolygon(double[] xPoints, double[] yPoints, int nPoints)
      Description copied from interface: GraphicsContext
      Fills a polygon with the given points using the currently set fill paint. A null value for any of the arrays will be ignored and nothing will be drawn.

      This method will be affected by any of the global common, fill, or Fill Rule attributes as specified in the Rendering Attributes Table.

      Specified by:
      fillPolygon in interface GraphicsContext
      Parameters:
      xPoints - array containing the x coordinates of the polygon's points or null.
      yPoints - array containing the y coordinates of the polygon's points or null.
      nPoints - the number of points that make the polygon.
    • strokePolygon

      public void strokePolygon(double[] xPoints, double[] yPoints, int nPoints)
      Description copied from interface: GraphicsContext
      Strokes a polygon with the given points using the currently set stroke paint. A null value for any of the arrays will be ignored and nothing will be drawn.

      This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.

      Specified by:
      strokePolygon in interface GraphicsContext
      Parameters:
      xPoints - array containing the x coordinates of the polygon's points or null.
      yPoints - array containing the y coordinates of the polygon's points or null.
      nPoints - the number of points that make the polygon.
    • strokePolyline

      public void strokePolyline(double[] xPoints, double[] yPoints, int nPoints)
      Description copied from interface: GraphicsContext
      Strokes a polyline with the given points using the currently set stroke paint attribute. A null value for any of the arrays will be ignored and nothing will be drawn.

      This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.

      Specified by:
      strokePolyline in interface GraphicsContext
      Parameters:
      xPoints - array containing the x coordinates of the polyline's points or null.
      yPoints - array containing the y coordinates of the polyline's points or null.
      nPoints - the number of points that make the polyline.
    • drawImage

      public void drawImage(Image img, double x, double y)
      Description copied from interface: GraphicsContext
      Draws an image at the given x, y position using the width and height of the given image. A null image value or an image still in progress will be ignored.

      This method will be affected by any of the global common attributes as specified in the Rendering Attributes Table.

      Specified by:
      drawImage in interface GraphicsContext
      Parameters:
      img - the image to be drawn or null.
      x - the X coordinate on the destination for the upper left of the image.
      y - the Y coordinate on the destination for the upper left of the image.
    • drawImage

      public void drawImage(Image img, double x, double y, double w, double h)
      Description copied from interface: GraphicsContext
      Draws an image into the given destination rectangle of the canvas. The Image is scaled to fit into the destination rectangle. A null image value or an image still in progress will be ignored.

      This method will be affected by any of the global common attributes as specified in the Rendering Attributes Table.

      Specified by:
      drawImage in interface GraphicsContext
      Parameters:
      img - the image to be drawn or null.
      x - the X coordinate on the destination for the upper left of the image.
      y - the Y coordinate on the destination for the upper left of the image.
      w - the width of the destination rectangle.
      h - the height of the destination rectangle.
    • drawImage

      public void drawImage(Image img, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)
      Description copied from interface: GraphicsContext
      Draws the specified source rectangle of the given image to the given destination rectangle of the Canvas. A null image value or an image still in progress will be ignored.

      This method will be affected by any of the global common attributes as specified in the Rendering Attributes Table.

      Specified by:
      drawImage in interface GraphicsContext
      Parameters:
      img - the image to be drawn or null.
      sx - the source rectangle's X coordinate position.
      sy - the source rectangle's Y coordinate position.
      sw - the source rectangle's width.
      sh - the source rectangle's height.
      dx - the destination rectangle's X coordinate position.
      dy - the destination rectangle's Y coordinate position.
      dw - the destination rectangle's width.
      dh - the destination rectangle's height.
    • getHTMLImageElement

      public static elemental2.dom.HTMLImageElement getHTMLImageElement(Image image)
    • getPixelWriter

      public PixelWriter getPixelWriter()
      Description copied from interface: GraphicsContext
      Returns a PixelWriter object that can be used to modify the pixels of the Canvas associated with this GraphicsContext. All coordinates in the PixelWriter methods on the returned object will be in device space since they refer directly to pixels and no other rendering attributes will be applied when modifying pixels using this object.
      Specified by:
      getPixelWriter in interface GraphicsContext
      Returns:
      the PixelWriter for modifying the pixels of this Canvas
    • setEffect

      public void setEffect(Effect e)
      Description copied from interface: GraphicsContext
      Sets the effect to be applied after the next draw call, or null to disable effects. The current effect is a common attribute used for nearly all rendering operations as specified in the Rendering Attributes Table.
      Specified by:
      setEffect in interface GraphicsContext
      Parameters:
      e - the effect to use, or null to disable effects
    • getEffect

      public Effect getEffect(Effect e)
      Description copied from interface: GraphicsContext
      Gets a copy of the effect to be applied after the next draw call. A null return value means that no effect will be applied after subsequent rendering calls. The current effect is a common attribute used for nearly all rendering operations as specified in the Rendering Attributes Table.
      Specified by:
      getEffect in interface GraphicsContext
      Parameters:
      e - an Effect object that may be used to store the copy of the current effect, if it is of a compatible type
      Returns:
      the current effect used for all rendering calls, or null if there is no current effect
    • applyEffect

      public void applyEffect(Effect e)
      Description copied from interface: GraphicsContext
      Applies the given effect to the entire bounds of the canvas and stores the result back into the same canvas. A null value will be ignored. The effect will be applied without any other rendering attributes and under an Identity coordinate transform. Since the effect is applied to the entire bounds of the canvas, some effects may have a confusing result, such as a Reflection effect that will apply its reflection off of the bottom of the canvas even if only a portion of the canvas has been rendered to and will not be visible unless a negative offset is used to bring the reflection back into view.
      Specified by:
      applyEffect in interface GraphicsContext
      Parameters:
      e - the effect to apply onto the entire destination or null.
    • setImageSmoothing

      public void setImageSmoothing(boolean imageSmoothing)
      Description copied from interface: GraphicsContext
      Sets the image smoothing state. Image smoothing is an Image attribute used to enable or disable image smoothing for drawImage(all forms) as specified in the Rendering Attributes Table.
      If image smoothing is true, images will be scaled using a higher quality filtering when transforming or scaling the source image to fit in the destination rectangle.
      If image smoothing is false, images will be scaled without filtering (or by using a lower quality filtering) when transforming or scaling the source image to fit in the destination rectangle.
      Specified by:
      setImageSmoothing in interface GraphicsContext
      Parameters:
      imageSmoothing - true to enable or false to disable smoothing
    • isImageSmoothing

      public boolean isImageSmoothing()
      Description copied from interface: GraphicsContext
      Gets the current image smoothing state.
      Specified by:
      isImageSmoothing in interface GraphicsContext
      Returns:
      image smoothing state