Class HtmlGraphicsContext
- All Implemented Interfaces:
GraphicsContext
- Author:
- Bruno Salmon
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
appendSVGPath
(String svgPath) 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
clip()
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
Draws an image at the given x, y position using the width and height of the given image.void
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
fill()
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
Fills the given string of text at position x, y with the current fill paint attribute.void
Fills text and includes a maximum width of the string.Gets theCanvas
that theGraphicsContext
is issuing draw commands to.Gets a copy of the effect to be applied after the next draw call.getFill()
Gets the current fill paint attribute.getFont()
Gets the current Font.double
Gets the current global alpha.Gets the global blend mode.static elemental2.dom.HTMLImageElement
getHTMLImageElement
(Image image) 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 aPixelWriter
object that can be used to modify the pixels of theCanvas
associated with thisGraphicsContext
.Gets the current stroke.Gets the currentTextAlignment
.Gets the current Text Baseline.getTransform
(Affine xform) Copies the current transform into the supplied object, creating a newAffine
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
restore()
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
save()
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
setLineCap
(StrokeLineCap cap) 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
setLineJoin
(StrokeLineJoin join) 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
setTextAlign
(TextAlignment align) Defines horizontal text alignment, relative to the textx
origin.void
setTextBaseline
(VPos baseline) Sets the current Text Baseline.void
setTransform
(double mxx, double myx, double mxy, double myy, double mxt, double myt) Sets the current transform.void
stroke()
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
-
-
Method Details
-
getCanvas
Description copied from interface:GraphicsContext
Gets theCanvas
that theGraphicsContext
is issuing draw commands to. There is only ever oneCanvas
for aGraphicsContext
.- Specified by:
getCanvas
in interfaceGraphicsContext
- 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
- Specified by:
save
in interfaceGraphicsContext
-
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
- Specified by:
restore
in interfaceGraphicsContext
-
translate
public void translate(double x, double y) Description copied from interface:GraphicsContext
Translates the current transform by x, y.- Specified by:
translate
in interfaceGraphicsContext
- 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 interfaceGraphicsContext
- 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 interfaceGraphicsContext
- 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 interfaceGraphicsContext
- Parameters:
mxx
- - the X coordinate scaling element of the 3x4 matrixmyx
- - the Y coordinate shearing element of the 3x4 matrixmxy
- - the X coordinate shearing element of the 3x4 matrixmyy
- - the Y coordinate scaling element of the 3x4 matrixmxt
- - the X coordinate translation element of the 3x4 matrixmyt
- - 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 interfaceGraphicsContext
- Parameters:
mxx
- - the X coordinate scaling element of the 3x4 matrixmyx
- - the Y coordinate shearing element of the 3x4 matrixmxy
- - the X coordinate shearing element of the 3x4 matrixmyy
- - the Y coordinate scaling element of the 3x4 matrixmxt
- - the X coordinate translation element of the 3x4 matrixmyt
- - the Y coordinate translation element of the 3x4 matrix
-
getTransform
Description copied from interface:GraphicsContext
Copies the current transform into the supplied object, creating a newAffine
object if it is null, and returns the object containing the copy.- Specified by:
getTransform
in interfaceGraphicsContext
- 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 is1.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 interfaceGraphicsContext
- 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 is1.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 interfaceGraphicsContext
- Returns:
- the current global alpha.
-
setGlobalBlendMode
Description copied from interface:GraphicsContext
Sets the global blend mode. The default value isSRC_OVER
. Anull
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 interfaceGraphicsContext
- Parameters:
op
- theBlendMode
that will be set or null.
-
getGlobalBlendMode
Description copied from interface:GraphicsContext
Gets the global blend mode. The default value isSRC_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 interfaceGraphicsContext
- Returns:
- the global
BlendMode
of the current state.
-
setFill
Description copied from interface:GraphicsContext
Sets the current fill paint attribute. The default value isBLACK
. The fill paint is a fill attribute used for any of the fill methods as specified in the Rendering Attributes Table. Anull
value will be ignored and the current value will remain unchanged.- Specified by:
setFill
in interfaceGraphicsContext
- Parameters:
p
- ThePaint
to be used as the fillPaint
or null.
-
getFill
Description copied from interface:GraphicsContext
Gets the current fill paint attribute. The default value isBLACK
. 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 interfaceGraphicsContext
- Returns:
- p The
Paint
to be used as the fillPaint
.
-
setStroke
Description copied from interface:GraphicsContext
Sets the current stroke paint attribute. The default value isBLACK
. The stroke paint is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table. Anull
value will be ignored and the current value will remain unchanged.- Specified by:
setStroke
in interfaceGraphicsContext
- Parameters:
p
- The Paint to be used as the stroke Paint or null.
-
getStroke
Description copied from interface:GraphicsContext
Gets the current stroke. The default value isBLACK
. 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 interfaceGraphicsContext
- Returns:
- the
Paint
to be used as the strokePaint
.
-
setLineWidth
public void setLineWidth(double lw) Description copied from interface:GraphicsContext
Sets the current line width. The default value is1.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 interfaceGraphicsContext
- 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 is1.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 interfaceGraphicsContext
- Returns:
- value between 0 and infinity.
-
setLineCap
Description copied from interface:GraphicsContext
Sets the current stroke line cap. The default value isSQUARE
. The line cap is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table. Anull
value will be ignored and the current value will remain unchanged.- Specified by:
setLineCap
in interfaceGraphicsContext
- Parameters:
cap
-StrokeLineCap
with a value of Butt, Round, or Square or null.
-
getLineCap
Description copied from interface:GraphicsContext
Gets the current stroke line cap. The default value isSQUARE
. 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 interfaceGraphicsContext
- Returns:
StrokeLineCap
with a value of Butt, Round, or Square.
-
setLineJoin
Description copied from interface:GraphicsContext
Sets the current stroke line join. The default value isStrokeLineJoin.MITER
. The line join is a stroke attribute used for any of the stroke methods as specified in the Rendering Attributes Table. Anull
value will be ignored and the current value will remain unchanged.- Specified by:
setLineJoin
in interfaceGraphicsContext
- Parameters:
join
-StrokeLineJoin
with a value of Miter, Bevel, or Round or null.
-
getLineJoin
Description copied from interface:GraphicsContext
Gets the current stroke line join. The default value isStrokeLineJoin.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 interfaceGraphicsContext
- 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 is10.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 interfaceGraphicsContext
- 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 is10.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 interfaceGraphicsContext
- 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 isnull
. 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 isnull
or empty or contains all0
elements then dashing will be disabled and the current dash array will be set tonull
. 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 interfaceGraphicsContext
- 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 isnull
. The array may be normalized by the validation tests in theGraphicsContext.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 interfaceGraphicsContext
- 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 is0.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 interfaceGraphicsContext
- 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 is0.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 interfaceGraphicsContext
- Returns:
- the line dash offset in the range
(-inf, +inf)
-
setFont
Description copied from interface:GraphicsContext
Sets the current Font. The default value is specified byFont.getDefault()
. The font is a text attribute used for any of the text methods as specified in the Rendering Attributes Table. Anull
value will be ignored and the current value will remain unchanged.- Specified by:
setFont
in interfaceGraphicsContext
- Parameters:
f
- the Font or null.
-
getFont
Description copied from interface:GraphicsContext
Gets the current Font. The default value is specified byFont.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 interfaceGraphicsContext
- Returns:
- the Font
-
setTextAlign
Description copied from interface:GraphicsContext
Defines horizontal text alignment, relative to the textx
origin. The default value isLEFT
. 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 interfaceGraphicsContext
- Parameters:
align
-TextAlignment
with values of Left, Center, Right or null.
- Left: the left edge of the horizontal bounds will be at
-
getTextAlign
Description copied from interface:GraphicsContext
Gets the currentTextAlignment
. The default value isLEFT
. 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 interfaceGraphicsContext
- Returns:
TextAlignment
with values of Left, Center, Right, or Justify.
-
setTextBaseline
Description copied from interface:GraphicsContext
Sets the current Text Baseline. The default value isBASELINE
. The text baseline is a text attribute used for any of the text methods as specified in the Rendering Attributes Table. Anull
value will be ignored and the current value will remain unchanged.- Specified by:
setTextBaseline
in interfaceGraphicsContext
- Parameters:
baseline
-VPos
with values of Top, Center, Baseline, or Bottom or null.
-
getTextBaseline
Description copied from interface:GraphicsContext
Gets the current Text Baseline. The default value isBASELINE
. 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 interfaceGraphicsContext
- Returns:
VPos
with values of Top, Center, Baseline, or Bottom
-
fillText
Description copied from interface:GraphicsContext
Fills the given string of text at position x, y with the current fill paint attribute. Anull
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 interfaceGraphicsContext
- Parameters:
text
- the string of text or null.x
- position on the x axis.y
- position on the y axis.
-
strokeText
Description copied from interface:GraphicsContext
Draws the given string of text at position x, y with the current stroke paint attribute. Anull
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 interfaceGraphicsContext
- Parameters:
text
- the string of text or null.x
- position on the x axis.y
- position on the y axis.
-
fillText
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. Anull
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 interfaceGraphicsContext
- 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
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. Anull
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 interfaceGraphicsContext
- 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 theGraphicsContext.save()
andGraphicsContext.restore()
operations.- Specified by:
beginPath
in interfaceGraphicsContext
-
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 theGraphicsContext.save()
andGraphicsContext.restore()
operations.- Specified by:
moveTo
in interfaceGraphicsContext
- 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 theGraphicsContext.save()
andGraphicsContext.restore()
operations.- Specified by:
lineTo
in interfaceGraphicsContext
- 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 theGraphicsContext.save()
andGraphicsContext.restore()
operations.- Specified by:
quadraticCurveTo
in interfaceGraphicsContext
- Parameters:
xc
- the X coordinate of the control pointyc
- the Y coordinate of the control pointx1
- the X coordinate of the end pointy1
- 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 theGraphicsContext.save()
andGraphicsContext.restore()
operations.- Specified by:
bezierCurveTo
in interfaceGraphicsContext
- 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 theGraphicsContext.save()
andGraphicsContext.restore()
operations.If
p0
is the current point in the path andp1
is the point specified by(x1, y1)
andp2
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 ofp0->p1->p2
. The path will contain a line segment (if needed) to the tangent point between that circle andp0->p1
followed by circular arc segments to reach the tangent point between the circle andp1->p2
and will end with the current point at that tangent point (not atp2
). 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 interfaceGraphicsContext
- 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 theGraphicsContext.save()
andGraphicsContext.restore()
operations.- Specified by:
arc
in interfaceGraphicsContext
- 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 range0-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 theGraphicsContext.save()
andGraphicsContext.restore()
operations.- Specified by:
rect
in interfaceGraphicsContext
- 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
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. Anull
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 theGraphicsContext.save()
andGraphicsContext.restore()
operations.- Specified by:
appendSVGPath
in interfaceGraphicsContext
- 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 theGraphicsContext.save()
andGraphicsContext.restore()
operations.- Specified by:
closePath
in interfaceGraphicsContext
-
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 interfaceGraphicsContext
-
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 interfaceGraphicsContext
-
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 interfaceGraphicsContext
-
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 interfaceGraphicsContext
- 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 interfaceGraphicsContext
- 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 interfaceGraphicsContext
- 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 interfaceGraphicsContext
- 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. Anull
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 interfaceGraphicsContext
- 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. Anull
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 interfaceGraphicsContext
- 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 interfaceGraphicsContext
- 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 interfaceGraphicsContext
- 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 interfaceGraphicsContext
- 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. Anull
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 interfaceGraphicsContext
- 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. Anull
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 interfaceGraphicsContext
- 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. Anull
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 interfaceGraphicsContext
- 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
Description copied from interface:GraphicsContext
Draws an image at the given x, y position using the width and height of the given image. Anull
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 interfaceGraphicsContext
- 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
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. Anull
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 interfaceGraphicsContext
- 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. Anull
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 interfaceGraphicsContext
- 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
-
getPixelWriter
Description copied from interface:GraphicsContext
Returns aPixelWriter
object that can be used to modify the pixels of theCanvas
associated with thisGraphicsContext
. All coordinates in thePixelWriter
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 interfaceGraphicsContext
- Returns:
- the
PixelWriter
for modifying the pixels of thisCanvas
-
setEffect
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 interfaceGraphicsContext
- Parameters:
e
- the effect to use, or null to disable effects
-
getEffect
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 interfaceGraphicsContext
- Parameters:
e
- anEffect
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
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. Anull
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 interfaceGraphicsContext
- 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 fordrawImage(all forms)
as specified in the Rendering Attributes Table.
If image smoothing istrue
, 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 isfalse
, 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 interfaceGraphicsContext
- Parameters:
imageSmoothing
-true
to enable orfalse
to disable smoothing
-
isImageSmoothing
public boolean isImageSmoothing()Description copied from interface:GraphicsContext
Gets the current image smoothing state.- Specified by:
isImageSmoothing
in interfaceGraphicsContext
- Returns:
- image smoothing state
-