toni@1129: /** toni@1447: * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach toni@1447: * toni@1129: * toni@1447: * This program is free software: you can redistribute it and/or modify it under toni@1447: * the terms of the GNU General Public License as published by the Free Software toni@1447: * Foundation, version 2 of the License. toni@1129: * toni@1447: * This program is distributed in the hope that it will be useful, but WITHOUT toni@1447: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS toni@1447: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more toni@1447: * details. toni@1129: * toni@1447: * You should have received a copy of the GNU General Public License along with toni@1447: * this program. Look for COPYING file in the top folder. If not, see toni@1447: * http://opensource.org/licenses/GPL-2.0. toni@1128: */ toni@1136: package net.java.html.canvas.spi; toni@1128: toni@1137: import net.java.html.canvas.Dimension; toni@1144: import net.java.html.canvas.Image; toni@1450: import net.java.html.canvas.ImageData; toni@1136: import net.java.html.canvas.Style; toni@1128: toni@1128: /** toni@1136: * Provider API for Canvas. Implement this to add support for your platform. toni@1141: * toni@1128: * @author antonepple toni@1128: */ toni@1128: public interface GraphicsEnvironment { toni@1129: toni@1447: /** toni@1447: * Adds path elements to the current path to make an arc. toni@1447: * toni@1447: * @param centerX the center x position of the arc. toni@1447: * @param centerY the center y position of the arc. toni@1447: * @param startAngle the startAngle of the arc toni@1447: * @param radius the radius of the arc. toni@1447: * @param endAngle the endAngle of the arc toni@1447: * @param ccw the direction of the arc (counterclockwise) toni@1447: */ toni@1128: public void arc(double centerX, toni@1128: double centerY, toni@1128: double startAngle, toni@1128: double radius, toni@1128: double endAngle, toni@1128: boolean ccw); toni@1128: toni@1447: /** toni@1447: * Adds segments to the current path to make an arc. toni@1447: * toni@1447: * @param x1 the X coordinate of the first point of the arc. toni@1447: * @param y1 the Y coordinate of the first point of the arc. toni@1447: * @param x2 the X coordinate of the second point of the arc. toni@1447: * @param y2 the Y coordinate of the second point of the arc. toni@1447: * @param radius the radius of the arc in the range {0.0-positive infinity}. toni@1447: */ toni@1128: public void arcTo(double x1, toni@1128: double y1, toni@1128: double x2, toni@1128: double y2, toni@1447: double radius); toni@1128: toni@1447: /** toni@1447: * Returns true if the the given x,y point is inside the path. toni@1447: * toni@1447: * @param x the X coordinate to use for the check. toni@1447: * @param y the Y coordinate to use for the check. toni@1447: * @return true if the point given is inside the path, false otherwise. toni@1447: */ toni@1128: public boolean isPointInPath(double x, double y); toni@1128: toni@1447: /** toni@1447: * Fills the path with the current fill paint. toni@1447: */ toni@1128: public void fill(); toni@1128: toni@1447: /** toni@1447: * Strokes the path with the current stroke paint. toni@1447: */ toni@1128: public void stroke(); toni@1128: toni@1447: /** toni@1447: * Starts a Path toni@1447: */ toni@1128: public void beginPath(); toni@1128: toni@1447: /** toni@1447: * Closes the path. toni@1447: */ toni@1128: public void closePath(); toni@1128: toni@1447: /** toni@1447: * Clips using the current path toni@1447: */ toni@1128: public void clip(); toni@1128: toni@1447: /** toni@1447: * Issues a move command for the current path to the given x,y coordinate. toni@1447: * toni@1447: * @param x the X position for the move to command. toni@1447: * @param y the Y position for the move to command. toni@1447: */ toni@1128: public void moveTo(double x, double y); toni@1128: toni@1447: /** toni@1447: * Adds segments to the current path to make a line at the given x,y toni@1447: * coordinate. toni@1447: * toni@1447: * @param x the X coordinate of the ending point of the line. toni@1447: * @param y the Y coordinate of the ending point of the line. toni@1447: */ toni@1128: public void lineTo(double x, double y); toni@1128: toni@1447: /** toni@1447: * Adds segments to the current path to make a quadratic curve. toni@1447: * toni@1447: * @param cpx the X coordinate of the control point toni@1447: * @param cpy the Y coordinate of the control point toni@1447: * @param x the X coordinate of the end point toni@1447: * @param y the Y coordinate of the end point toni@1447: */ toni@1128: public void quadraticCurveTo(double cpx, double cpy, double x, double y); toni@1128: toni@1447: /** toni@1447: * Adds segments to the current path to make a cubic bezier curve. toni@1447: * toni@1447: * @param cp1x the X coordinate of first bezier control point. toni@1447: * @param cp1y the Y coordinate of the first bezier control point. toni@1447: * @param cp2x the X coordinate of the second bezier control point. toni@1447: * @param cp2y the Y coordinate of the second bezier control point. toni@1447: * @param x the X coordinate of the end point. toni@1447: * @param y the Y coordinate of the end point. toni@1447: */ toni@1128: public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y); toni@1128: toni@1447: /** toni@1447: * Fills a rectangle using the current fill paint. toni@1447: * toni@1447: * @param x the X position of the upper left corner of the rectangle. toni@1447: * @param y the Y position of the upper left corner of the rectangle. toni@1447: * @param width the width of the rectangle. toni@1447: * @param height the height of the rectangle. toni@1447: */ toni@1128: public void fillRect(double x, double y, double width, double height); toni@1128: toni@1447: /** toni@1447: * Strokes a rectangle using the current stroke paint. toni@1447: * toni@1447: * @param x the X position of the upper left corner of the rectangle. toni@1447: * @param y the Y position of the upper left corner of the rectangle. toni@1447: * @param width the width of the rectangle. toni@1447: * @param height the height of the rectangle. toni@1447: */ toni@1128: public void strokeRect(double x, double y, double width, double height); toni@1128: toni@1447: /** toni@1447: * Clears a portion of the canvas with a transparent color value. toni@1447: * toni@1447: * @param x X position of the upper left corner of the rectangle. toni@1447: * @param y Y position of the upper left corner of the rectangle. toni@1447: * @param width width of the rectangle. toni@1447: * @param height height of the rectangle. toni@1447: */ toni@1128: public void clearRect(double x, double y, double width, double height); toni@1128: toni@1447: /** toni@1447: * Clears a portion of the canvas with a transparent color value. toni@1447: * toni@1447: * @param x X position of the upper left corner of the rectangle. toni@1447: * @param y Y position of the upper left corner of the rectangle. toni@1447: * @param width width of the rectangle. toni@1447: * @param height height of the rectangle. toni@1447: */ toni@1128: public void rect(double x, double y, double width, double height); toni@1128: toni@1447: /** toni@1447: * Saves the following attributes onto a stack. toni@1447: * toni@1447: * This method does NOT alter the current state in any way. Also, not that toni@1447: * the current path is not saved. toni@1447: */ toni@1128: public void save(); toni@1128: toni@1447: /** toni@1447: * Pops the state off of the stack, setting the following attributes to toni@1447: * their value at the time when that state was pushed onto the stack. If the toni@1447: * stack is empty then nothing is changed. toni@1447: * toni@1447: * toni@1447: */ toni@1128: public void restore(); toni@1128: toni@1447: /** toni@1447: * Rotates the current transform in degrees. toni@1447: * toni@1447: * @param angle value in degrees to rotate the current transform. toni@1447: */ toni@1128: public void rotate(double angle); toni@1128: toni@1447: /** toni@1447: * Concatenates the input with the current transform. toni@1447: * toni@1447: * @param a - the X coordinate scaling element of the 3x4 matrix toni@1447: * @param b - the Y coordinate shearing element of the 3x4 matrix toni@1447: * @param c - the X coordinate shearing element of the 3x4 matrix toni@1447: * @param d - the Y coordinate scaling element of the 3x4 matrix toni@1447: * @param e - the X coordinate translation element of the 3x4 matrix toni@1447: * @param f - the Y coordinate translation element of the 3x4 matrix toni@1447: */ toni@1128: public void transform(double a, double b, double c, double d, double e, double f); toni@1128: toni@1447: /** toni@1447: * Concatenates the input with the current transform. toni@1447: * toni@1447: * @param a - the X coordinate scaling element of the 3x4 matrix toni@1447: * @param b - the Y coordinate shearing element of the 3x4 matrix toni@1447: * @param c - the X coordinate shearing element of the 3x4 matrix toni@1447: * @param d - the Y coordinate scaling element of the 3x4 matrix toni@1447: * @param e - the X coordinate translation element of the 3x4 matrix toni@1447: * @param f - the Y coordinate translation element of the 3x4 matrix toni@1447: */ toni@1128: public void setTransform(double a, double b, double c, double d, double e, double f); toni@1128: toni@1447: /** toni@1447: * Translates the current transform by x, y. toni@1447: * toni@1447: * @param x value to translate along the x axis. toni@1447: * @param y value to translate along the y axis. toni@1447: */ toni@1128: public void translate(double x, double y); toni@1128: toni@1447: /** toni@1447: * Scales the current transform by x, y. toni@1447: * toni@1447: * @param x value to scale in the x axis. toni@1447: * @param y value to scale in the y axis. toni@1447: */ toni@1128: public void scale(double x, double y); toni@1128: toni@1447: /** toni@1447: * Draws an image at the given x, y position using the width and height of toni@1447: * the given image. toni@1447: * toni@1447: * @param image the image to be drawn. toni@1447: * @param x the X coordinate on the destination for the upper left of the toni@1447: * image. toni@1447: * @param y the Y coordinate on the destination for the upper left of the toni@1447: * image. toni@1447: * @return the native Image for caching. toni@1447: */ toni@1302: public Object drawImage(Image image, double x, double y, Object nativeImage); toni@1144: toni@1447: /** toni@1447: * Draws an image into the given destination rectangle of the canvas. The toni@1447: * Image is scaled to fit into the destination rectagnle. toni@1447: * toni@1447: * @param image the image to be drawn. toni@1447: * @param x the X coordinate on the destination for the upper left of the toni@1447: * image. toni@1447: * @param y the Y coordinate on the destination for the upper left of the toni@1447: * image. toni@1447: * @param width the width of the destination rectangle. toni@1447: * @param height the height of the destination rectangle. toni@1447: * @return the native Image for caching. toni@1447: * toni@1447: */ toni@1144: public Object drawImage(Image image, double x, double y, double width, double height, Object nativeImage); toni@1144: toni@1447: /** toni@1447: * Draws the current source rectangle of the given image to the given toni@1447: * destination rectangle of the Canvas. toni@1447: * toni@1447: * @param image the image to be drawn. toni@1447: * @param sx the source rectangle's X coordinate position. toni@1447: * @param sy the source rectangle's Y coordinate position. toni@1447: * @param sWidth the source rectangle's width. toni@1447: * @param sHeight the source rectangle's height. toni@1447: * @param x the destination rectangle's X coordinate position. toni@1447: * @param y the destination rectangle's Y coordinate position. toni@1447: * @param width the destination rectangle's width. toni@1447: * @param height the destination rectangle's height. toni@1447: * @return the native Image for caching. toni@1447: */ toni@1144: public Object drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height, Object nativeImage); toni@1144: toni@1447: /** toni@1447: * Get the width of this Image toni@1447: * toni@1447: * @param image the image to measure toni@1447: * @param nativeImage the cached native Image or null toni@1447: * @return the width of the image toni@1447: */ toni@1263: public int getWidth(Image image, Object nativeImage); toni@1302: toni@1447: /** toni@1447: * Get the height of this Image toni@1447: * toni@1447: * @param image the image to measure toni@1447: * @param nativeImage the cached native Image or null toni@1447: * @return the height of the image toni@1447: */ toni@1263: public int getHeight(Image image, Object nativeImage); toni@1302: toni@1141: /** toni@1141: * When implementing you can return an Object of your choice to enable toni@1141: * caching. Returning null means no caching. When caching is enabled, and toni@1141: * the cache hasn't been invalidated, the Object you returned will be passed toni@1141: * as a parameter. toni@1141: * toni@1141: * @param style The style object you should use to create your native style toni@1141: * @param nativeStyle your native object if cached, null otherwise toni@1141: * @return return native Object for caching toni@1141: * toni@1141: */ toni@1141: public Object setFillStyle(Style style, Object nativeStyle); toni@1128: toni@1141: /** toni@1141: * When implementing you can return an Object of your choice to enable toni@1141: * caching. Returning null means no caching. When caching is enabled, and toni@1141: * the cache hasn't been invalidated, the Object you returned will be passed toni@1141: * as a parameter. toni@1141: * toni@1141: * @param style The style object you should use to create your native style toni@1141: * @param nativeStyle your native object if cached, null otherwise toni@1141: * @return return native Object for caching toni@1141: * toni@1141: */ toni@1141: public Object setStrokeStyle(Style style, Object nativeStyle); toni@1128: toni@1302: // public void setShadowColor(String color); toni@1302: // toni@1302: // public void setShadowBlur(double blur); toni@1302: // toni@1302: // public void setShadowOffsetX(double x); toni@1302: // toni@1302: // public void setShadowOffsetY(double y); toni@1302: // toni@1302: // public String getShadowColor(); toni@1302: // toni@1302: // public double getShadowBlur(); toni@1302: // toni@1302: // public double getShadowOffsetX(); toni@1302: // toni@1302: // public double getShadowOffsetY(); toni@1302: /** toni@1302: * Gets the current stroke line cap. toni@1302: * toni@1302: * @return {@code StrokeLineCap} with a value of Butt, Round, or Square. toni@1302: */ toni@1128: public String getLineCap(); toni@1128: toni@1302: /** toni@1302: * Sets the current stroke line cap. toni@1302: * toni@1302: * @param style a value of Butt, Round, or Square. toni@1302: */ toni@1128: public void setLineCap(String style); toni@1128: toni@1302: /** toni@1302: * Gets the current stroke line join. toni@1302: * toni@1302: * @return a value of Miter, Bevel, or Round. toni@1302: */ toni@1128: public String getLineJoin(); toni@1128: toni@1302: /** toni@1302: * Sets the current stroke line join. toni@1302: * toni@1302: * @param style with a value of Miter, Bevel, or Round. toni@1302: */ toni@1128: public void setLineJoin(String style); toni@1128: toni@1302: /** toni@1302: * Gets the current line width. toni@1302: * toni@1302: * @return value between 0 and infinity. toni@1302: */ toni@1128: public double getLineWidth(); toni@1128: toni@1302: /** toni@1302: * Sets the current line width. toni@1302: * toni@1302: * @param width value in the range {0-positive infinity}, with any other toni@1302: * value being ignored and leaving the value unchanged. toni@1302: */ toni@1128: public void setLineWidth(double width); toni@1128: toni@1302: /** toni@1302: * Gets the current miter limit. v toni@1302: * toni@1302: * @return the miter limit value in the range {@code 0.0-positive infinity} toni@1302: */ toni@1128: public double getMiterLimit(); toni@1128: toni@1302: /** toni@1302: * Sets the current miter limit. toni@1302: * toni@1302: * @param limit miter limit value between 0 and positive infinity with any toni@1302: * other value being ignored and leaving the value unchanged. toni@1302: */ toni@1128: public void setMiterLimit(double limit); toni@1128: toni@1302: /** toni@1302: * Gets the current Font. toni@1302: * toni@1302: * @return the Font toni@1302: */ toni@1128: public String getFont(); toni@1128: toni@1302: /** toni@1302: * Sets the current Font. toni@1302: * toni@1302: */ toni@1128: public void setFont(String font); toni@1128: toni@1302: /** toni@1302: * Gets the current {@code TextAlignment}. toni@1302: * toni@1302: * @return TextAlignment with values of Left, Center, Right, or Justify. toni@1302: */ toni@1128: public String getTextAlign(); toni@1128: toni@1302: /** toni@1302: * Defines horizontal text alignment, relative to the text origin. toni@1302: * toni@1302: * @param textAlign with values of Left, Center, Right. toni@1302: */ toni@1128: public void setTextAlign(String textAlign); toni@1128: toni@1302: /** toni@1302: * Sets the current Text Baseline. toni@1302: * toni@1302: * @param baseline with values of Top, Center, Baseline, or Bottom toni@1302: */ toni@1128: public String getTextBaseline(); toni@1128: toni@1302: /** toni@1302: * Sets the current Text Baseline. toni@1302: * toni@1302: * @param baseline with values of Top, Center, Baseline, or Bottom toni@1302: */ toni@1302: public void setTextBaseline(String baseline); toni@1128: toni@1302: /** toni@1302: * Fills the given string of text at position x, y (0,0 at top left) with toni@1302: * the current fill paint attribute. toni@1302: * toni@1302: * @param text the string of text. toni@1302: * @param x position on the x axis. toni@1302: * @param y position on the y axis. toni@1302: */ toni@1128: public void fillText(String text, double x, double y); toni@1128: toni@1302: /** toni@1302: * Fills text and includes a maximum width of the string. toni@1302: * toni@1302: * If the width of the text extends past max width, then it will be sized to toni@1302: * fit. toni@1302: * toni@1302: * @param text the string of text. toni@1302: * @param x position on the x axis. toni@1302: * @param y position on the y axis. toni@1302: * @param maxWidth maximum width the text string can have. toni@1302: */ toni@1128: public void fillText(String text, double x, double y, double maxWidth); toni@1128: toni@1302: /** toni@1302: * The Dimension of this text using the current Font settings toni@1302: * toni@1302: * @param text toni@1302: * @return the Dimension of this text using the current Font settings toni@1302: */ toni@1128: public Dimension measureText(String text); toni@1128: toni@1302: /** toni@1302: * draws the given string of text at position x, y (0,0 at top left) with toni@1302: * the current stroke paint attribute. toni@1302: * toni@1302: * @param text the string of text. toni@1302: * @param x position on the x axis. toni@1302: * @param y position on the y axis. toni@1302: */ toni@1128: public void strokeText(String text, double x, double y); toni@1128: toni@1302: /** toni@1302: * Draws text with stroke paint and includes a maximum width of the string. toni@1302: * toni@1302: * If the width of the text extends past max width, then it will be sized to toni@1302: * fit. toni@1302: * toni@1302: * @param text the string of text. toni@1302: * @param x position on the x axis. toni@1302: * @param y position on the y axis. toni@1302: * @param maxWidth maximum width the text string can have. toni@1302: */ toni@1128: public void strokeText(String text, double x, double y, double maxWidth); toni@1128: toni@1450: /** toni@1450: * Get a pixel array that you can manipulate, e.g. apply effects / transparency toni@1450: * @param x width toni@1450: * @param y height toni@1450: * @return a PixelMap toni@1450: */ toni@1450: public ImageData createPixelMap(double x, double y); toni@1450: toni@1450: /** toni@1450: * Create a new ImageData object with the same dimensions as the toni@1450: * object specified by imageData (this does not copy the image data) toni@1450: * @param imageData toni@1450: * @return toni@1450: */ toni@1450: public ImageData createPixelMap(ImageData imageData); toni@1450: toni@1450: /** toni@1450: * Get the pixels for a region of your GraphicsContext toni@1450: * @param x start x coordinate toni@1450: * @param y start y coordinate toni@1450: * @param width width toni@1450: * @param height height toni@1450: * @return toni@1450: */ toni@1450: public ImageData getPixelMap(double x, double y, double width, double height); toni@1450: toni@1450: /** toni@1450: * Render an ImageData Object at the specified position toni@1450: * @param imageData the Pixel array toni@1450: * @param x start x coordinate toni@1450: * @param y start y coordinate toni@1450: */ toni@1450: public void putPixelMap(ImageData imageData, double x, double y); toni@1450: toni@1450: /** toni@1450: * Render an ImageData Object at the specified position toni@1450: * @param imageData the Pixel array to draw toni@1450: * @param x start x coordinate toni@1450: * @param y start y coordinate toni@1450: * @param dirtyx The horizontal (x) value, in pixels, where to place the image on the canvas toni@1450: * @param dirtyy The vertical (y) value, in pixels, where to place the image on the canvas toni@1450: * @param dirtywidth The width to use to draw the image on the canvas toni@1450: * @param dirtyheight The height to use to draw the image on the canvas toni@1450: */ toni@1450: public void putPixelMap(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight); toni@1302: /** toni@1302: * Sets the global alpha of the current state. toni@1302: * toni@1302: * @param alpha value in the range {@code 0.0-1.0}. The value is clamped if toni@1302: * it is out of range. toni@1302: */ toni@1128: public void setGlobalAlpha(double alpha); toni@1128: toni@1447: /** toni@1447: * Get the global alpha of the current state. toni@1447: * toni@1447: * @return alpha value in the range {@code 0.0-1.0}. toni@1447: */ toni@1128: public double getGlobalAlpha(); toni@1128: toni@1447: /** toni@1447: * Sets the global blend mode. toni@1447: * toni@1447: * @param operation the BlendMode that will be set. toni@1447: */ toni@1128: public void setGlobalCompositeOperation(String operation); toni@1128: toni@1447: /** toni@1447: * Gets the global blend mode. toni@1447: * toni@1447: * @return the global BlendMode of the current state. toni@1447: */ toni@1128: public String getGlobalCompositeOperation(); toni@1302: toni@1447: /** toni@1447: * Get the height of this GraphicsContext (which should be the same as the toni@1447: * enclosing canvas height) toni@1447: * toni@1447: * @return the height of this GraphicsContext toni@1447: */ toni@1128: public int getHeight(); toni@1128: toni@1447: /** toni@1447: * Get the width of this GraphicsContext (which should be the same as the toni@1447: * enclosing canvas height) toni@1447: * toni@1447: * @return the width of this GraphicsContext toni@1447: */ toni@1128: public int getWidth(); toni@1128: toni@1302: // public void setHeight(int height); toni@1302: // toni@1302: // public void setWidth(int width); toni@1447: /** toni@1447: * Merges two images drawing one on top of the other and returning the toni@1447: * result. toni@1447: * toni@1447: * @param a the lower Image toni@1447: * @param b the upper Image toni@1447: * @param cachedA the native cached Image, if available, or null. toni@1447: * @param cachedB the native cached Image, if available, or null. toni@1447: * @return toni@1447: */ toni@1263: public Object mergeImages(Image a, Image b, Object cachedA, Object cachedB); toni@1128: }