1.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/spi/GraphicsEnvironment.java Thu Sep 26 14:26:58 2013 -0700
1.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/spi/GraphicsEnvironment.java Wed Feb 12 09:14:20 2014 +0100
1.3 @@ -1,19 +1,19 @@
1.4 /**
1.5 - * Back 2 Browser Bytecode Translator
1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.7 + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
1.8 + * <jaroslav.tulach@apidesign.org>
1.9 *
1.10 - * This program is free software: you can redistribute it and/or modify
1.11 - * it under the terms of the GNU General Public License as published by
1.12 - * the Free Software Foundation, version 2 of the License.
1.13 + * This program is free software: you can redistribute it and/or modify it under
1.14 + * the terms of the GNU General Public License as published by the Free Software
1.15 + * Foundation, version 2 of the License.
1.16 *
1.17 - * This program is distributed in the hope that it will be useful,
1.18 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.19 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.20 - * GNU General Public License for more details.
1.21 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.22 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.23 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.24 + * details.
1.25 *
1.26 - * You should have received a copy of the GNU General Public License
1.27 - * along with this program. Look for COPYING file in the top folder.
1.28 - * If not, see http://opensource.org/licenses/GPL-2.0.
1.29 + * You should have received a copy of the GNU General Public License along with
1.30 + * this program. Look for COPYING file in the top folder. If not, see
1.31 + * http://opensource.org/licenses/GPL-2.0.
1.32 */
1.33 package net.java.html.canvas.spi;
1.34
1.35 @@ -28,6 +28,16 @@
1.36 */
1.37 public interface GraphicsEnvironment {
1.38
1.39 + /**
1.40 + * Adds path elements to the current path to make an arc.
1.41 + *
1.42 + * @param centerX the center x position of the arc.
1.43 + * @param centerY the center y position of the arc.
1.44 + * @param startAngle the startAngle of the arc
1.45 + * @param radius the radius of the arc.
1.46 + * @param endAngle the endAngle of the arc
1.47 + * @param ccw the direction of the arc (counterclockwise)
1.48 + */
1.49 public void arc(double centerX,
1.50 double centerY,
1.51 double startAngle,
1.52 @@ -35,62 +45,292 @@
1.53 double endAngle,
1.54 boolean ccw);
1.55
1.56 + /**
1.57 + * Adds segments to the current path to make an arc.
1.58 + *
1.59 + * @param x1 the X coordinate of the first point of the arc.
1.60 + * @param y1 the Y coordinate of the first point of the arc.
1.61 + * @param x2 the X coordinate of the second point of the arc.
1.62 + * @param y2 the Y coordinate of the second point of the arc.
1.63 + * @param radius the radius of the arc in the range {0.0-positive infinity}.
1.64 + */
1.65 public void arcTo(double x1,
1.66 double y1,
1.67 double x2,
1.68 double y2,
1.69 - double r);
1.70 + double radius);
1.71
1.72 + /**
1.73 + * Returns true if the the given x,y point is inside the path.
1.74 + *
1.75 + * @param x the X coordinate to use for the check.
1.76 + * @param y the Y coordinate to use for the check.
1.77 + * @return true if the point given is inside the path, false otherwise.
1.78 + */
1.79 public boolean isPointInPath(double x, double y);
1.80
1.81 + /**
1.82 + * Fills the path with the current fill paint.
1.83 + */
1.84 public void fill();
1.85
1.86 + /**
1.87 + * Strokes the path with the current stroke paint.
1.88 + */
1.89 public void stroke();
1.90
1.91 + /**
1.92 + * Starts a Path
1.93 + */
1.94 public void beginPath();
1.95
1.96 + /**
1.97 + * Closes the path.
1.98 + */
1.99 public void closePath();
1.100
1.101 + /**
1.102 + * Clips using the current path
1.103 + */
1.104 public void clip();
1.105
1.106 + /**
1.107 + * Issues a move command for the current path to the given x,y coordinate.
1.108 + *
1.109 + * @param x the X position for the move to command.
1.110 + * @param y the Y position for the move to command.
1.111 + */
1.112 public void moveTo(double x, double y);
1.113
1.114 + /**
1.115 + * Adds segments to the current path to make a line at the given x,y
1.116 + * coordinate.
1.117 + *
1.118 + * @param x the X coordinate of the ending point of the line.
1.119 + * @param y the Y coordinate of the ending point of the line.
1.120 + */
1.121 public void lineTo(double x, double y);
1.122
1.123 + /**
1.124 + * Adds segments to the current path to make a quadratic curve.
1.125 + *
1.126 + * @param cpx the X coordinate of the control point
1.127 + * @param cpy the Y coordinate of the control point
1.128 + * @param x the X coordinate of the end point
1.129 + * @param y the Y coordinate of the end point
1.130 + */
1.131 public void quadraticCurveTo(double cpx, double cpy, double x, double y);
1.132
1.133 + /**
1.134 + * Adds segments to the current path to make a cubic bezier curve.
1.135 + *
1.136 + * @param cp1x the X coordinate of first bezier control point.
1.137 + * @param cp1y the Y coordinate of the first bezier control point.
1.138 + * @param cp2x the X coordinate of the second bezier control point.
1.139 + * @param cp2y the Y coordinate of the second bezier control point.
1.140 + * @param x the X coordinate of the end point.
1.141 + * @param y the Y coordinate of the end point.
1.142 + */
1.143 public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
1.144
1.145 + /**
1.146 + * Fills a rectangle using the current fill paint.
1.147 + *
1.148 + * @param x the X position of the upper left corner of the rectangle.
1.149 + * @param y the Y position of the upper left corner of the rectangle.
1.150 + * @param width the width of the rectangle.
1.151 + * @param height the height of the rectangle.
1.152 + */
1.153 public void fillRect(double x, double y, double width, double height);
1.154
1.155 + /**
1.156 + * Strokes a rectangle using the current stroke paint.
1.157 + *
1.158 + * @param x the X position of the upper left corner of the rectangle.
1.159 + * @param y the Y position of the upper left corner of the rectangle.
1.160 + * @param width the width of the rectangle.
1.161 + * @param height the height of the rectangle.
1.162 + */
1.163 public void strokeRect(double x, double y, double width, double height);
1.164
1.165 + /**
1.166 + * Clears a portion of the canvas with a transparent color value.
1.167 + *
1.168 + * @param x X position of the upper left corner of the rectangle.
1.169 + * @param y Y position of the upper left corner of the rectangle.
1.170 + * @param width width of the rectangle.
1.171 + * @param height height of the rectangle.
1.172 + */
1.173 public void clearRect(double x, double y, double width, double height);
1.174
1.175 + /**
1.176 + * Clears a portion of the canvas with a transparent color value.
1.177 + *
1.178 + * @param x X position of the upper left corner of the rectangle.
1.179 + * @param y Y position of the upper left corner of the rectangle.
1.180 + * @param width width of the rectangle.
1.181 + * @param height height of the rectangle.
1.182 + */
1.183 public void rect(double x, double y, double width, double height);
1.184
1.185 + /**
1.186 + * Saves the following attributes onto a stack.
1.187 + * <ul>
1.188 + * <li>Global Alpha</li>
1.189 + * <li>Global Blend Operation</li>
1.190 + * <li>Transform</li>
1.191 + * <li>Fill Paint</li>
1.192 + * <li>Stroke Paint</li>
1.193 + * <li>Line Width</li>
1.194 + * <li>Line Cap</li>
1.195 + * <li>Line Join</li>
1.196 + * <li>Miter Limit</li>
1.197 + * <li>Number of Clip Paths</li>
1.198 + * <li>Font</li>
1.199 + * <li>Text Align</li>
1.200 + * <li>Text Baseline</li>
1.201 + * <li>Effect</li>
1.202 + * <li>Fill Rule</li>
1.203 + * </ul>
1.204 + * This method does NOT alter the current state in any way. Also, not that
1.205 + * the current path is not saved.
1.206 + */
1.207 public void save();
1.208
1.209 + /**
1.210 + * Pops the state off of the stack, setting the following attributes to
1.211 + * their value at the time when that state was pushed onto the stack. If the
1.212 + * stack is empty then nothing is changed.
1.213 + *
1.214 + * <ul>
1.215 + * <li>Global Alpha</li>
1.216 + * <li>Global Blend Operation</li>
1.217 + * <li>Transform</li>
1.218 + * <li>Fill Paint</li>
1.219 + * <li>Stroke Paint</li>
1.220 + * <li>Line Width</li>
1.221 + * <li>Line Cap</li>
1.222 + * <li>Line Join</li>
1.223 + * <li>Miter Limit</li>
1.224 + * <li>Number of Clip Paths</li>
1.225 + * <li>Font</li>
1.226 + * <li>Text Align</li>
1.227 + * <li>Text Baseline</li>
1.228 + * <li>Effect</li>
1.229 + * <li>Fill Rule</li>
1.230 + * </ul>
1.231 + */
1.232 public void restore();
1.233
1.234 + /**
1.235 + * Rotates the current transform in degrees.
1.236 + *
1.237 + * @param angle value in degrees to rotate the current transform.
1.238 + */
1.239 public void rotate(double angle);
1.240
1.241 + /**
1.242 + * Concatenates the input with the current transform.
1.243 + *
1.244 + * @param a - the X coordinate scaling element of the 3x4 matrix
1.245 + * @param b - the Y coordinate shearing element of the 3x4 matrix
1.246 + * @param c - the X coordinate shearing element of the 3x4 matrix
1.247 + * @param d - the Y coordinate scaling element of the 3x4 matrix
1.248 + * @param e - the X coordinate translation element of the 3x4 matrix
1.249 + * @param f - the Y coordinate translation element of the 3x4 matrix
1.250 + */
1.251 public void transform(double a, double b, double c, double d, double e, double f);
1.252
1.253 + /**
1.254 + * Concatenates the input with the current transform.
1.255 + *
1.256 + * @param a - the X coordinate scaling element of the 3x4 matrix
1.257 + * @param b - the Y coordinate shearing element of the 3x4 matrix
1.258 + * @param c - the X coordinate shearing element of the 3x4 matrix
1.259 + * @param d - the Y coordinate scaling element of the 3x4 matrix
1.260 + * @param e - the X coordinate translation element of the 3x4 matrix
1.261 + * @param f - the Y coordinate translation element of the 3x4 matrix
1.262 + */
1.263 public void setTransform(double a, double b, double c, double d, double e, double f);
1.264
1.265 + /**
1.266 + * Translates the current transform by x, y.
1.267 + *
1.268 + * @param x value to translate along the x axis.
1.269 + * @param y value to translate along the y axis.
1.270 + */
1.271 public void translate(double x, double y);
1.272
1.273 + /**
1.274 + * Scales the current transform by x, y.
1.275 + *
1.276 + * @param x value to scale in the x axis.
1.277 + * @param y value to scale in the y axis.
1.278 + */
1.279 public void scale(double x, double y);
1.280
1.281 + /**
1.282 + * Draws an image at the given x, y position using the width and height of
1.283 + * the given image.
1.284 + *
1.285 + * @param image the image to be drawn.
1.286 + * @param x the X coordinate on the destination for the upper left of the
1.287 + * image.
1.288 + * @param y the Y coordinate on the destination for the upper left of the
1.289 + * image.
1.290 + * @return the native Image for caching.
1.291 + */
1.292 public Object drawImage(Image image, double x, double y, Object nativeImage);
1.293
1.294 + /**
1.295 + * Draws an image into the given destination rectangle of the canvas. The
1.296 + * Image is scaled to fit into the destination rectagnle.
1.297 + *
1.298 + * @param image the image to be drawn.
1.299 + * @param x the X coordinate on the destination for the upper left of the
1.300 + * image.
1.301 + * @param y the Y coordinate on the destination for the upper left of the
1.302 + * image.
1.303 + * @param width the width of the destination rectangle.
1.304 + * @param height the height of the destination rectangle.
1.305 + * @return the native Image for caching.
1.306 + *
1.307 + */
1.308 public Object drawImage(Image image, double x, double y, double width, double height, Object nativeImage);
1.309
1.310 + /**
1.311 + * Draws the current source rectangle of the given image to the given
1.312 + * destination rectangle of the Canvas.
1.313 + *
1.314 + * @param image the image to be drawn.
1.315 + * @param sx the source rectangle's X coordinate position.
1.316 + * @param sy the source rectangle's Y coordinate position.
1.317 + * @param sWidth the source rectangle's width.
1.318 + * @param sHeight the source rectangle's height.
1.319 + * @param x the destination rectangle's X coordinate position.
1.320 + * @param y the destination rectangle's Y coordinate position.
1.321 + * @param width the destination rectangle's width.
1.322 + * @param height the destination rectangle's height.
1.323 + * @return the native Image for caching.
1.324 + */
1.325 public Object drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height, Object nativeImage);
1.326
1.327 + /**
1.328 + * Get the width of this Image
1.329 + *
1.330 + * @param image the image to measure
1.331 + * @param nativeImage the cached native Image or null
1.332 + * @return the width of the image
1.333 + */
1.334 public int getWidth(Image image, Object nativeImage);
1.335
1.336 + /**
1.337 + * Get the height of this Image
1.338 + *
1.339 + * @param image the image to measure
1.340 + * @param nativeImage the cached native Image or null
1.341 + * @return the height of the image
1.342 + */
1.343 public int getHeight(Image image, Object nativeImage);
1.344
1.345 /**
1.346 @@ -304,19 +544,55 @@
1.347 */
1.348 public void setGlobalAlpha(double alpha);
1.349
1.350 + /**
1.351 + * Get the global alpha of the current state.
1.352 + *
1.353 + * @return alpha value in the range {@code 0.0-1.0}.
1.354 + */
1.355 public double getGlobalAlpha();
1.356
1.357 + /**
1.358 + * Sets the global blend mode.
1.359 + *
1.360 + * @param operation the BlendMode that will be set.
1.361 + */
1.362 public void setGlobalCompositeOperation(String operation);
1.363
1.364 + /**
1.365 + * Gets the global blend mode.
1.366 + *
1.367 + * @return the global BlendMode of the current state.
1.368 + */
1.369 public String getGlobalCompositeOperation();
1.370
1.371 + /**
1.372 + * Get the height of this GraphicsContext (which should be the same as the
1.373 + * enclosing canvas height)
1.374 + *
1.375 + * @return the height of this GraphicsContext
1.376 + */
1.377 public int getHeight();
1.378
1.379 + /**
1.380 + * Get the width of this GraphicsContext (which should be the same as the
1.381 + * enclosing canvas height)
1.382 + *
1.383 + * @return the width of this GraphicsContext
1.384 + */
1.385 public int getWidth();
1.386
1.387 // public void setHeight(int height);
1.388 //
1.389 // public void setWidth(int width);
1.390 -
1.391 + /**
1.392 + * Merges two images drawing one on top of the other and returning the
1.393 + * result.
1.394 + *
1.395 + * @param a the lower Image
1.396 + * @param b the upper Image
1.397 + * @param cachedA the native cached Image, if available, or null.
1.398 + * @param cachedB the native cached Image, if available, or null.
1.399 + * @return
1.400 + */
1.401 public Object mergeImages(Image a, Image b, Object cachedA, Object cachedB);
1.402 }