Class NoOpRenderingBackend
java.lang.Object
org.htmlunit.platform.canvas.rendering.NoOpRenderingBackend
- All Implemented Interfaces:
RenderingBackend
The default implementation of
RenderingBackend.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.htmlunit.platform.canvas.rendering.RenderingBackend
RenderingBackend.WindingRule -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate static intprivate static final org.apache.commons.logging.Log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidarc(double x, double y, double radius, double startAngle, double endAngle, boolean anticlockwise) Adds a circular arc to the current sub-path.voidStarts a new path by emptying the list of sub-paths.voidbezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y) Adds a cubic Bézier curve to the current sub-path.voidclearRect(double x, double y, double w, double h) Paints the specified rectangular area.voidclip(RenderingBackend.WindingRule windingRule, Path2D path) Turns the current or given path into the current clipping region.voidAttempts to add a straight line from the current point to the start of the current sub-path.voiddrawImage(ImageData imageData, int sx, int sy, Integer sWidth, Integer sHeight, int dx, int dy, Integer dWidth, Integer dHeight) Draws images onto the context.voidellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean anticlockwise) Creates an elliptical arc centered at (x, y) with the radii radiusX and radiusY.encodeToString(String type) Constructs a base64 encoded string out of the image data.voidfill()Fills the current or given path with the current fillStyle.voidfillRect(int x, int y, int w, int h) Paints the specified rectangular area.voidFills a given text at the given (x, y) position.byte[]getBytes(int width, int height, int sx, int sy) Creates a byte array containing the (4) color values of all pixels.doubleintReturns thelineWidthproperty.voidlineTo(double x, double y) Adds a straight line to the current sub-path by connecting the sub-path's last point to the specified (x, y) coordinates.voidmoveTo(double x, double y) Begins a new sub-path at the point specified by the given (x, y) coordinates.private static intnextId()voidputImageData(byte[] imageDataBytes, int imageDataHeight, int imageDataWidth, int dx, int dy, int dirtyX, int dirtyY, int dirtyWidth, int dirtyHeight) Paints data from the given ImageData object onto the canvas.voidquadraticCurveTo(double cpx, double cpy, double x, double y) Adds a quadratic Bézier curve to the current sub-path.voidrect(double x, double y, double w, double h) Adds a rectangle to the current path.voidrestore()Restores the most recently saved canvas state by popping the top entry in the drawing state stack.voidrotate(double angle) Adds a rotation to the transformation matrix.voidsave()Saves the entire state of the canvas by pushing the current state onto a stack.voidsetFillStyle(String fillStyle) Sets thefillStyleproperty.voidsetGlobalAlpha(double globalAlpha) Specifies the alpha (transparency) value that is applied to shapes and images before they are drawn onto the canvas.voidsetLineWidth(int lineWidth) Sets thelineWidthproperty.voidsetStrokeStyle(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()Strokes (outlines) the current or given path with the current stroke style.voidstrokeRect(int x, int y, int w, int h) Paints the specified rectangular area.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) Adds a translation transformation to the current matrix.
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
ID_GENERATOR_
private static int ID_GENERATOR_ -
id_
private final int id_
-
-
Constructor Details
-
NoOpRenderingBackend
public NoOpRenderingBackend(int imageWidth, int imageHeight) Constructor.- Parameters:
imageWidth- the widthimageHeight- the height
-
-
Method Details
-
nextId
private static int nextId() -
getGlobalAlpha
public double getGlobalAlpha()- Specified by:
getGlobalAlphain interfaceRenderingBackend- Returns:
- the alpha (transparency) value that is applied to shapes and images before they are drawn onto the canvas.
-
setGlobalAlpha
public void setGlobalAlpha(double globalAlpha) Specifies the alpha (transparency) value that is applied to shapes and images before they are drawn onto the canvas.- Specified by:
setGlobalAlphain interfaceRenderingBackend- Parameters:
globalAlpha- the new alpha
-
beginPath
public void beginPath()Starts a new path by emptying the list of sub-paths.- Specified by:
beginPathin interfaceRenderingBackend
-
ellipse
public void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean anticlockwise) Creates an elliptical arc centered at (x, y) with the radii radiusX and radiusY. The path starts at startAngle and ends at endAngle, and travels in the direction given by anticlockwise (defaulting to clockwise).- Specified by:
ellipsein interfaceRenderingBackend- Parameters:
x- the xy- the yradiusX- the radiusXradiusY- the radiusYrotation- the rotationstartAngle- the start angleendAngle- the end angleanticlockwise- is anti-clockwise
-
bezierCurveTo
public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y) Adds a cubic Bézier curve to the current sub-path. It requires three points: the first two are control points and the third one is the end point. The starting point is the latest point in the current path, which can be changed using moveTo() before creating the Bézier curve.- Specified by:
bezierCurveToin interfaceRenderingBackend- Parameters:
cp1x- the cp1xcp1y- the cp1ycp2x- the cp2xcp2y- the cp2yx- the xy- the y
-
arc
public void arc(double x, double y, double radius, double startAngle, double endAngle, boolean anticlockwise) Adds a circular arc to the current sub-path.- Specified by:
arcin interfaceRenderingBackend- Parameters:
x- the xy- the yradius- the radiusstartAngle- the start angleendAngle- the end angleanticlockwise- is anti-clockwise
-
clearRect
public void clearRect(double x, double y, double w, double h) Paints the specified rectangular area.- Specified by:
clearRectin interfaceRenderingBackend- Parameters:
x- the xy- the yw- the widthh- the height
-
drawImage
public void drawImage(ImageData imageData, int sx, int sy, Integer sWidth, Integer sHeight, int dx, int dy, Integer dWidth, Integer dHeight) throws IOException Draws images onto the context.- Specified by:
drawImagein interfaceRenderingBackend- Parameters:
imageData- the reader to read the image from 8the first one)sx- 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- Throws:
IOException- in case o problems
-
encodeToString
Constructs a base64 encoded string out of the image data.- Specified by:
encodeToStringin interfaceRenderingBackend- Parameters:
type- the name of the image format- Returns:
- the base64 encoded string
- Throws:
IOException- in case o problems
-
fill
public void fill()Fills the current or given path with the current fillStyle.- Specified by:
fillin interfaceRenderingBackend
-
fillRect
public void fillRect(int x, int y, int w, int h) Paints the specified rectangular area.- Specified by:
fillRectin interfaceRenderingBackend- Parameters:
x- the xy- the yw- the widthh- the height
-
fillText
Fills a given text at the given (x, y) position.- Specified by:
fillTextin interfaceRenderingBackend- Parameters:
text- the textx- the xy- the y
-
getBytes
public byte[] getBytes(int width, int height, int sx, int sy) Creates a byte array containing the (4) color values of all pixels.- Specified by:
getBytesin interfaceRenderingBackend- Parameters:
width- the widthheight- the heightsx- start point xsy- start point y- Returns:
- the bytes
-
lineTo
public void lineTo(double x, double y) Adds a straight line to the current sub-path by connecting the sub-path's last point to the specified (x, y) coordinates.- Specified by:
lineToin interfaceRenderingBackend- Parameters:
x- the xy- the y
-
moveTo
public void moveTo(double x, double y) Begins a new sub-path at the point specified by the given (x, y) coordinates.- Specified by:
moveToin interfaceRenderingBackend- Parameters:
x- the xy- the y
-
putImageData
public void putImageData(byte[] imageDataBytes, int imageDataHeight, int imageDataWidth, int dx, int dy, int dirtyX, int dirtyY, int dirtyWidth, int dirtyHeight) Paints data from the given ImageData object onto the canvas.- Specified by:
putImageDatain interfaceRenderingBackend- Parameters:
imageDataBytes- an array of pixel valuesimageDataHeight- the height of the imageDataimageDataWidth- the width of the imageDatadx- 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 cpx, double cpy, double x, double y) Adds a quadratic Bézier curve to the current sub-path. It requires two points: the first one is a control point and the second one is the end point. The starting point is the latest point in the current path, which can be changed using moveTo() before creating the quadratic Bézier curve.- Specified by:
quadraticCurveToin interfaceRenderingBackend- Parameters:
cpx- the cpxcpy- the cpyx- the xy- the y
-
rect
public void rect(double x, double y, double w, double h) Adds a rectangle to the current path.- Specified by:
rectin interfaceRenderingBackend- Parameters:
x- the xy- the yw- the widthh- the height
-
setFillStyle
Sets thefillStyleproperty.- Specified by:
setFillStylein interfaceRenderingBackend- Parameters:
fillStyle- thefillStyleproperty
-
setStrokeStyle
Sets thestrokeStyleproperty.- Specified by:
setStrokeStylein interfaceRenderingBackend- Parameters:
strokeStyle- thestrokeStyleproperty
-
getLineWidth
public int getLineWidth()Returns thelineWidthproperty.- Specified by:
getLineWidthin interfaceRenderingBackend- Returns:
- the
lineWidthproperty
-
restore
public void restore()Restores the most recently saved canvas state by popping the top entry in the drawing state stack. If there is no saved state, this method does nothing.- Specified by:
restorein interfaceRenderingBackend
-
rotate
public void rotate(double angle) Adds a rotation to the transformation matrix.- Specified by:
rotatein interfaceRenderingBackend- Parameters:
angle- the angle
-
save
public void save()Saves the entire state of the canvas by pushing the current state onto a stack.- Specified by:
savein interfaceRenderingBackend
-
setLineWidth
public void setLineWidth(int lineWidth) Sets thelineWidthproperty.- Specified by:
setLineWidthin interfaceRenderingBackend- Parameters:
lineWidth- thelineWidthproperty
-
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.- Specified by:
setTransformin interfaceRenderingBackend- 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()Strokes (outlines) the current or given path with the current stroke style.- Specified by:
strokein interfaceRenderingBackend
-
strokeRect
public void strokeRect(int x, int y, int w, int h) Paints the specified rectangular area.- Specified by:
strokeRectin interfaceRenderingBackend- Parameters:
x- the xy- the yw- the widthh- the height
-
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.- Specified by:
transformin interfaceRenderingBackend- 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) Adds a translation transformation to the current matrix.- Specified by:
translatein interfaceRenderingBackend- Parameters:
x- the xy- the y
-
clip
Turns the current or given path into the current clipping region. It replaces any previous clipping region.- Specified by:
clipin interfaceRenderingBackend- Parameters:
windingRule- the RenderingBackend.WindingRuleRenderingBackend.WindingRuleto be usedpath- the path or null if the current path should be used
-
closePath
public void closePath()Attempts to add a straight line from the current point to the start of the current sub-path. If the shape has already been closed or has only one point, this function does nothing.- Specified by:
closePathin interfaceRenderingBackend
-