Class CanvasRenderingContext2D
- java.lang.Object
-
- org.htmlunit.corejs.javascript.ScriptableObject
-
- org.htmlunit.javascript.HtmlUnitScriptable
-
- org.htmlunit.javascript.host.canvas.CanvasRenderingContext2D
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,org.htmlunit.corejs.javascript.ConstProperties,org.htmlunit.corejs.javascript.debug.DebuggableObject,org.htmlunit.corejs.javascript.Scriptable,org.htmlunit.corejs.javascript.SymbolScriptable
public class CanvasRenderingContext2D extends HtmlUnitScriptable
A JavaScript object forCanvasRenderingContext2D.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private HTMLCanvasElementcanvas_private static org.apache.commons.logging.LogLOGprivate RenderingBackendrenderingBackend_
-
Constructor Summary
Constructors Constructor Description CanvasRenderingContext2D()Default constructor.CanvasRenderingContext2D(HTMLCanvasElement canvas)Constructs in association withHTMLCanvasElement.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidarc(double x, double y, double radius, double startAngle, double endAngle, boolean anticlockwise)Draws an arc.voidarcTo(double x1, double y1, double x2, double y2, double radius)Draws an arc.voidbeginPath()Begins the subpaths.voidbezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y)Draws a cubic Bézier curve.voidclearRect(double x, double y, double w, double h)Clears the specified rectangular area.static voidclip(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Creates a new clipping region.voidclosePath()Closes the current subpath.static ImageDatacreateImageData(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Returns theImageDataobject.CanvasGradientcreateLinearGradient(double x0, double y0, double r0, double x1, java.lang.Object y1, java.lang.Object r1)Creates linear gradient.voidcreatePattern()Creates a pattern.CanvasGradientcreateRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1)Creates a gradient.voiddrawImage(java.lang.Object image, int sx, int sy, java.lang.Object sWidth, java.lang.Object sHeight, java.lang.Object dx, java.lang.Object dy, java.lang.Object dWidth, java.lang.Object dHeight)Draws images onto the canvas.voidellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean anticlockwise)Paints the specified ellipse.voidfill()Fills the shape.voidfillRect(int x, int y, int w, int h)Paints the specified rectangular area.voidfillText(java.lang.String text, double x, double y)Fills a given text at the given (x, y) position.HTMLCanvasElementgetCanvas()Returns the associatedHTMLCanvasElement.java.lang.ObjectgetFillStyle()Returns thefillStyleproperty.doublegetGlobalAlpha()Specifies the alpha (transparency) value that is applied to shapes and images before they are drawn onto the canvas..ImageDatagetImageData(int sx, int sy, int sw, int sh)Returns theImageDataobject.voidgetLineDash()Dummy placeholder.voidgetLineData()Dummy placeholder.doublegetLineWidth()Returns thelineWidthproperty.private RenderingBackendgetRenderingBackend()java.lang.ObjectgetStrokeStyle()Returns thestrokeStyleproperty.voidisPointInPath()Dummy placeholder.voidjsConstructor()JavaScript constructor.voidlineTo(double x, double y)Connect the last point to the given point.TextMetricsmeasureText(java.lang.Object text)Calculate TextMetrics for the given text.voidmoveTo(double x, double y)Creates a new subpath.voidputImageData(ImageData imageData, int dx, int dy, java.lang.Object dirtyX, java.lang.Object dirtyY, java.lang.Object dirtyWidth, java.lang.Object dirtyHeight)Paints data from the given ImageData object onto the canvas.voidquadraticCurveTo(double controlPointX, double controlPointY, double endPointX, double endPointY)Draws a quadratic Bézier curve.voidrect(double x, double y, double w, double h)Renders a rectangle.voidrestore()Pops state stack and restore state.voidrotate(double angle)Adds a rotation to the transformation matrix.voidsave()Pushes state on state stack.voidscale(java.lang.Object x, java.lang.Object y)Changes the transformation matrix to apply a scaling transformation with the given characteristics.voidsetFillStyle(java.lang.String fillStyle)Sets thefillStyleproperty.voidsetGlobalAlpha(double globalAlpha)Sets theglobalAlphaproperty.voidsetLineDash()Dummy placeholder.voidsetLineWidth(java.lang.Object lineWidth)Sets thelineWidthproperty.voidsetStrokeStyle(java.lang.String strokeStyle)Sets thestrokeStyleproperty.voidsetTransform(double m11, double m12, double m21, double m22, double dx, double dy)Resets (overrides) the current transformation to the identity matrix, and then invokes a transformation described by the arguments of this method.voidstroke()Calculates the strokes of all the subpaths of the current path.voidstrokeRect(int x, int y, int w, int h)Strokes the specified rectangular area.voidstrokeText()Dummy placeholder.java.lang.StringtoDataURL(java.lang.String type)Returns the Data URL.voidtransform(double m11, double m12, double m21, double m22, double dx, double dy)Multiplies the current transformation with the matrix described by the arguments of this method.voidtranslate(int x, int y)Changes the transformation matrix to apply a translation transformation with the given characteristics.-
Methods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, getWithPreemption, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromise
-
Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
canvas_
private HTMLCanvasElement canvas_
-
renderingBackend_
private RenderingBackend renderingBackend_
-
-
Constructor Detail
-
CanvasRenderingContext2D
public CanvasRenderingContext2D()
Default constructor.
-
CanvasRenderingContext2D
public CanvasRenderingContext2D(HTMLCanvasElement canvas)
Constructs in association withHTMLCanvasElement.- Parameters:
canvas- theHTMLCanvasElement
-
-
Method Detail
-
jsConstructor
public void jsConstructor()
JavaScript constructor.
-
getRenderingBackend
private RenderingBackend getRenderingBackend()
-
getGlobalAlpha
public double getGlobalAlpha()
Specifies the alpha (transparency) value that is applied to shapes and images before they are drawn onto the canvas..- Returns:
- the
globalAlphaproperty
-
setGlobalAlpha
public void setGlobalAlpha(double globalAlpha)
Sets theglobalAlphaproperty.- Parameters:
globalAlpha- theglobalAlphaproperty
-
getFillStyle
public java.lang.Object getFillStyle()
Returns thefillStyleproperty.- Returns:
- the
fillStyleproperty
-
setFillStyle
public void setFillStyle(java.lang.String fillStyle)
Sets thefillStyleproperty.- Parameters:
fillStyle- thefillStyleproperty
-
getStrokeStyle
public java.lang.Object getStrokeStyle()
Returns thestrokeStyleproperty.- Returns:
- the
strokeStyleproperty
-
setStrokeStyle
public void setStrokeStyle(java.lang.String strokeStyle)
Sets thestrokeStyleproperty.- Parameters:
strokeStyle- thestrokeStyleproperty
-
getLineWidth
public double getLineWidth()
Returns thelineWidthproperty.- Returns:
- the
lineWidthproperty
-
setLineWidth
public void setLineWidth(java.lang.Object lineWidth)
Sets thelineWidthproperty.- Parameters:
lineWidth- thelineWidthproperty
-
arc
public void arc(double x, double y, double radius, double startAngle, double endAngle, boolean anticlockwise)Draws an arc.- Parameters:
x- the xy- the yradius- the radiusstartAngle- the start angleendAngle- the end angleanticlockwise- is anti-clockwise
-
arcTo
public void arcTo(double x1, double y1, double x2, double y2, double radius)Draws an arc.- Parameters:
x1- the x1y1- the y1x2- the x2y2- the y2radius- the radius
-
beginPath
public void beginPath()
Begins the subpaths.
-
bezierCurveTo
public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y)Draws a cubic Bézier curve.- Parameters:
cp1x- the cp1xcp1y- the cp1ycp2x- the cp2xcp2y- the cp2yx- the xy- the y
-
clearRect
public void clearRect(double x, double y, double w, double h)Clears the specified rectangular area.- Parameters:
x- the xy- the yw- the widthh- the height
-
clip
public static void clip(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Creates a new clipping region.- Parameters:
context- the JavaScript contextscope- the scopethisObj- the scriptableargs- the arguments passed into the methodfunction- the function
-
closePath
public void closePath()
Closes the current subpath.
-
createImageData
public static ImageData createImageData(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)
Returns theImageDataobject. this may accept a variable number of arguments.- Parameters:
context- the JavaScript contextscope- the scopethisObj- the scriptableargs- the arguments passed into the methodfunction- the function- Returns:
- the
ImageDataobject
-
createLinearGradient
public CanvasGradient createLinearGradient(double x0, double y0, double r0, double x1, java.lang.Object y1, java.lang.Object r1)
Creates linear gradient.- Parameters:
x0- the x0y0- the y0r0- the r0x1- the x1y1- the y1r1- the r1- Returns:
- the new CanvasGradient
-
createPattern
public void createPattern()
Creates a pattern.
-
createRadialGradient
public CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1)
Creates a gradient.- Parameters:
x0- the x axis of the coordinate of the start circley0- the y axis of the coordinate of the start circler0- the radius of the start circlex1- the x axis of the coordinate of the end circley1- the y axis of the coordinate of the end circler1- the radius of the end circle- Returns:
- the new CanvasGradient
-
drawImage
public void drawImage(java.lang.Object image, int sx, int sy, java.lang.Object sWidth, java.lang.Object sHeight, java.lang.Object dx, java.lang.Object dy, java.lang.Object dWidth, java.lang.Object dHeight)Draws images onto the canvas.- Parameters:
image- an element to draw into the contextsx- the X coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination contextsy- the Y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination contextsWidth- the width of the sub-rectangle of the source image to draw into the destination contextsHeight- the height of the sub-rectangle of the source image to draw into the destination contextdx- the X coordinate in the destination canvas at which to place the top-left corner of the source imagedy- the Y coordinate in the destination canvas at which to place the top-left corner of the source imagedWidth- the width to draw the image in the destination canvas. This allows scaling of the drawn imagedHeight- the height to draw the image in the destination canvas. This allows scaling of the drawn image
-
toDataURL
public java.lang.String toDataURL(java.lang.String type)
Returns the Data URL.- Parameters:
type- an optional type- Returns:
- the dataURL
-
ellipse
public void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean anticlockwise)Paints the specified ellipse.- Parameters:
x- the xy- the yradiusX- the radiusXradiusY- the radiusYrotation- the rotationstartAngle- the startAngleendAngle- the endAngleanticlockwise- the anticlockwise
-
fill
public void fill()
Fills the shape.
-
fillRect
public void fillRect(int x, int y, int w, int h)Paints the specified rectangular area.- Parameters:
x- the xy- the yw- the widthh- the height
-
fillText
public void fillText(java.lang.String text, double x, double y)Fills a given text at the given (x, y) position.- Parameters:
text- the textx- the xy- the y
-
getImageData
public ImageData getImageData(int sx, int sy, int sw, int sh)
Returns theImageDataobject.- Parameters:
sx- xsy- ysw- widthsh- height- Returns:
- the
ImageDataobject
-
getLineDash
public void getLineDash()
Dummy placeholder.
-
getLineData
public void getLineData()
Dummy placeholder.
-
isPointInPath
public void isPointInPath()
Dummy placeholder.
-
lineTo
public void lineTo(double x, double y)Connect the last point to the given point.- Parameters:
x- the xy- the y
-
measureText
public TextMetrics measureText(java.lang.Object text)
Calculate TextMetrics for the given text.- Parameters:
text- the text to measure- Returns:
- the text metrics
-
moveTo
public void moveTo(double x, double y)Creates a new subpath.- Parameters:
x- the xy- the y
-
putImageData
public void putImageData(ImageData imageData, int dx, int dy, java.lang.Object dirtyX, java.lang.Object dirtyY, java.lang.Object dirtyWidth, java.lang.Object dirtyHeight)
Paints data from the given ImageData object onto the canvas.- Parameters:
imageData- an ImageData object containing the array of pixel valuesdx- horizontal position (x coordinate) at which to place the image data in the destination canvasdy- vertical position (y coordinate) at which to place the image data in the destination canvasdirtyX- horizontal position (x coordinate) of the top-left corner from which the image data will be extracted. Defaults to 0.dirtyY- vertical position (y coordinate) of the top-left corner from which the image data will be extracted. Defaults to 0.dirtyWidth- width of the rectangle to be painted. Defaults to the width of the image data.dirtyHeight- height of the rectangle to be painted. Defaults to the height of the image data.
-
quadraticCurveTo
public void quadraticCurveTo(double controlPointX, double controlPointY, double endPointX, double endPointY)Draws a quadratic Bézier curve.- Parameters:
controlPointX- the x-coordinate of the control pointcontrolPointY- the y-coordinate of the control pointendPointX- the x-coordinate of the end pointendPointY- the y-coordinate of the end point
-
rect
public void rect(double x, double y, double w, double h)Renders a rectangle.- Parameters:
x- the xy- the yw- the widthh- the height
-
restore
public void restore()
Pops state stack and restore state.
-
rotate
public void rotate(double angle)
Adds a rotation to the transformation matrix.- Parameters:
angle- the angle
-
save
public void save()
Pushes state on state stack.
-
scale
public void scale(java.lang.Object x, java.lang.Object y)Changes the transformation matrix to apply a scaling transformation with the given characteristics.- Parameters:
x- the scale factor in the horizontal directiony- the scale factor in the vertical direction
-
setLineDash
public void setLineDash()
Dummy placeholder.
-
setTransform
public void setTransform(double m11, double m12, double m21, double m22, double dx, double dy)Resets (overrides) the current transformation to the identity matrix, and then invokes a transformation described by the arguments of this method. This lets you scale, rotate, translate (move), and skew the context.- Parameters:
m11- Horizontal scaling. A value of 1 results in no scalingm12- Vertical skewingm21- Horizontal skewingm22- Vertical scaling. A value of 1 results in no scalingdx- Horizontal translation (moving)dy- Vertical translation (moving).
-
stroke
public void stroke()
Calculates the strokes of all the subpaths of the current path.
-
strokeRect
public void strokeRect(int x, int y, int w, int h)Strokes the specified rectangular area.- Parameters:
x- the xy- the yw- the widthh- the height
-
strokeText
public void strokeText()
Dummy placeholder.
-
transform
public void transform(double m11, double m12, double m21, double m22, double dx, double dy)Multiplies the current transformation with the matrix described by the arguments of this method. This lets you scale, rotate, translate (move), and skew the context.- Parameters:
m11- Horizontal scaling. A value of 1 results in no scalingm12- Vertical skewingm21- Horizontal skewingm22- Vertical scaling. A value of 1 results in no scalingdx- Horizontal translation (moving)dy- Vertical translation (moving).
-
translate
public void translate(int x, int y)Changes the transformation matrix to apply a translation transformation with the given characteristics.- Parameters:
x- the translation distance in the horizontal directiony- the translation distance in the vertical direction
-
getCanvas
public HTMLCanvasElement getCanvas()
Returns the associatedHTMLCanvasElement.- Returns:
- the associated
HTMLCanvasElement
-
-