(Y05) Reintroduced the methods for using ImageData, since they?re already implemented and I have a very good usecase:
It?s useful for the tricks we need on mobile for fast application launch: Take a snapshot of the UI at application shutdown and display it on application start.
2 * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
3 * <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program. Look for COPYING file in the top folder. If not, see
16 * http://opensource.org/licenses/GPL-2.0.
18 package net.java.html.canvas.spi;
20 import net.java.html.canvas.Dimension;
21 import net.java.html.canvas.Image;
22 import net.java.html.canvas.ImageData;
23 import net.java.html.canvas.Style;
26 * Provider API for Canvas. Implement this to add support for your platform.
30 public interface GraphicsEnvironment {
33 * Adds path elements to the current path to make an arc.
35 * @param centerX the center x position of the arc.
36 * @param centerY the center y position of the arc.
37 * @param startAngle the startAngle of the arc
38 * @param radius the radius of the arc.
39 * @param endAngle the endAngle of the arc
40 * @param ccw the direction of the arc (counterclockwise)
42 public void arc(double centerX,
50 * Adds segments to the current path to make an arc.
52 * @param x1 the X coordinate of the first point of the arc.
53 * @param y1 the Y coordinate of the first point of the arc.
54 * @param x2 the X coordinate of the second point of the arc.
55 * @param y2 the Y coordinate of the second point of the arc.
56 * @param radius the radius of the arc in the range {0.0-positive infinity}.
58 public void arcTo(double x1,
65 * Returns true if the the given x,y point is inside the path.
67 * @param x the X coordinate to use for the check.
68 * @param y the Y coordinate to use for the check.
69 * @return true if the point given is inside the path, false otherwise.
71 public boolean isPointInPath(double x, double y);
74 * Fills the path with the current fill paint.
79 * Strokes the path with the current stroke paint.
86 public void beginPath();
91 public void closePath();
94 * Clips using the current path
99 * Issues a move command for the current path to the given x,y coordinate.
101 * @param x the X position for the move to command.
102 * @param y the Y position for the move to command.
104 public void moveTo(double x, double y);
107 * Adds segments to the current path to make a line at the given x,y
110 * @param x the X coordinate of the ending point of the line.
111 * @param y the Y coordinate of the ending point of the line.
113 public void lineTo(double x, double y);
116 * Adds segments to the current path to make a quadratic curve.
118 * @param cpx the X coordinate of the control point
119 * @param cpy the Y coordinate of the control point
120 * @param x the X coordinate of the end point
121 * @param y the Y coordinate of the end point
123 public void quadraticCurveTo(double cpx, double cpy, double x, double y);
126 * Adds segments to the current path to make a cubic bezier curve.
128 * @param cp1x the X coordinate of first bezier control point.
129 * @param cp1y the Y coordinate of the first bezier control point.
130 * @param cp2x the X coordinate of the second bezier control point.
131 * @param cp2y the Y coordinate of the second bezier control point.
132 * @param x the X coordinate of the end point.
133 * @param y the Y coordinate of the end point.
135 public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
138 * Fills a rectangle using the current fill paint.
140 * @param x the X position of the upper left corner of the rectangle.
141 * @param y the Y position of the upper left corner of the rectangle.
142 * @param width the width of the rectangle.
143 * @param height the height of the rectangle.
145 public void fillRect(double x, double y, double width, double height);
148 * Strokes a rectangle using the current stroke paint.
150 * @param x the X position of the upper left corner of the rectangle.
151 * @param y the Y position of the upper left corner of the rectangle.
152 * @param width the width of the rectangle.
153 * @param height the height of the rectangle.
155 public void strokeRect(double x, double y, double width, double height);
158 * Clears a portion of the canvas with a transparent color value.
160 * @param x X position of the upper left corner of the rectangle.
161 * @param y Y position of the upper left corner of the rectangle.
162 * @param width width of the rectangle.
163 * @param height height of the rectangle.
165 public void clearRect(double x, double y, double width, double height);
168 * Clears a portion of the canvas with a transparent color value.
170 * @param x X position of the upper left corner of the rectangle.
171 * @param y Y position of the upper left corner of the rectangle.
172 * @param width width of the rectangle.
173 * @param height height of the rectangle.
175 public void rect(double x, double y, double width, double height);
178 * Saves the following attributes onto a stack.
180 * <li>Global Alpha</li>
181 * <li>Global Blend Operation</li>
183 * <li>Fill Paint</li>
184 * <li>Stroke Paint</li>
185 * <li>Line Width</li>
188 * <li>Miter Limit</li>
189 * <li>Number of Clip Paths</li>
191 * <li>Text Align</li>
192 * <li>Text Baseline</li>
196 * This method does NOT alter the current state in any way. Also, not that
197 * the current path is not saved.
202 * Pops the state off of the stack, setting the following attributes to
203 * their value at the time when that state was pushed onto the stack. If the
204 * stack is empty then nothing is changed.
207 * <li>Global Alpha</li>
208 * <li>Global Blend Operation</li>
210 * <li>Fill Paint</li>
211 * <li>Stroke Paint</li>
212 * <li>Line Width</li>
215 * <li>Miter Limit</li>
216 * <li>Number of Clip Paths</li>
218 * <li>Text Align</li>
219 * <li>Text Baseline</li>
224 public void restore();
227 * Rotates the current transform in degrees.
229 * @param angle value in degrees to rotate the current transform.
231 public void rotate(double angle);
234 * Concatenates the input with the current transform.
236 * @param a - the X coordinate scaling element of the 3x4 matrix
237 * @param b - the Y coordinate shearing element of the 3x4 matrix
238 * @param c - the X coordinate shearing element of the 3x4 matrix
239 * @param d - the Y coordinate scaling element of the 3x4 matrix
240 * @param e - the X coordinate translation element of the 3x4 matrix
241 * @param f - the Y coordinate translation element of the 3x4 matrix
243 public void transform(double a, double b, double c, double d, double e, double f);
246 * Concatenates the input with the current transform.
248 * @param a - the X coordinate scaling element of the 3x4 matrix
249 * @param b - the Y coordinate shearing element of the 3x4 matrix
250 * @param c - the X coordinate shearing element of the 3x4 matrix
251 * @param d - the Y coordinate scaling element of the 3x4 matrix
252 * @param e - the X coordinate translation element of the 3x4 matrix
253 * @param f - the Y coordinate translation element of the 3x4 matrix
255 public void setTransform(double a, double b, double c, double d, double e, double f);
258 * Translates the current transform by x, y.
260 * @param x value to translate along the x axis.
261 * @param y value to translate along the y axis.
263 public void translate(double x, double y);
266 * Scales the current transform by x, y.
268 * @param x value to scale in the x axis.
269 * @param y value to scale in the y axis.
271 public void scale(double x, double y);
274 * Draws an image at the given x, y position using the width and height of
277 * @param image the image to be drawn.
278 * @param x the X coordinate on the destination for the upper left of the
280 * @param y the Y coordinate on the destination for the upper left of the
282 * @return the native Image for caching.
284 public Object drawImage(Image image, double x, double y, Object nativeImage);
287 * Draws an image into the given destination rectangle of the canvas. The
288 * Image is scaled to fit into the destination rectagnle.
290 * @param image the image to be drawn.
291 * @param x the X coordinate on the destination for the upper left of the
293 * @param y the Y coordinate on the destination for the upper left of the
295 * @param width the width of the destination rectangle.
296 * @param height the height of the destination rectangle.
297 * @return the native Image for caching.
300 public Object drawImage(Image image, double x, double y, double width, double height, Object nativeImage);
303 * Draws the current source rectangle of the given image to the given
304 * destination rectangle of the Canvas.
306 * @param image the image to be drawn.
307 * @param sx the source rectangle's X coordinate position.
308 * @param sy the source rectangle's Y coordinate position.
309 * @param sWidth the source rectangle's width.
310 * @param sHeight the source rectangle's height.
311 * @param x the destination rectangle's X coordinate position.
312 * @param y the destination rectangle's Y coordinate position.
313 * @param width the destination rectangle's width.
314 * @param height the destination rectangle's height.
315 * @return the native Image for caching.
317 public Object drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height, Object nativeImage);
320 * Get the width of this Image
322 * @param image the image to measure
323 * @param nativeImage the cached native Image or null
324 * @return the width of the image
326 public int getWidth(Image image, Object nativeImage);
329 * Get the height of this Image
331 * @param image the image to measure
332 * @param nativeImage the cached native Image or null
333 * @return the height of the image
335 public int getHeight(Image image, Object nativeImage);
338 * When implementing you can return an Object of your choice to enable
339 * caching. Returning null means no caching. When caching is enabled, and
340 * the cache hasn't been invalidated, the Object you returned will be passed
343 * @param style The style object you should use to create your native style
344 * @param nativeStyle your native object if cached, null otherwise
345 * @return return native Object for caching
348 public Object setFillStyle(Style style, Object nativeStyle);
351 * When implementing you can return an Object of your choice to enable
352 * caching. Returning null means no caching. When caching is enabled, and
353 * the cache hasn't been invalidated, the Object you returned will be passed
356 * @param style The style object you should use to create your native style
357 * @param nativeStyle your native object if cached, null otherwise
358 * @return return native Object for caching
361 public Object setStrokeStyle(Style style, Object nativeStyle);
363 // public void setShadowColor(String color);
365 // public void setShadowBlur(double blur);
367 // public void setShadowOffsetX(double x);
369 // public void setShadowOffsetY(double y);
371 // public String getShadowColor();
373 // public double getShadowBlur();
375 // public double getShadowOffsetX();
377 // public double getShadowOffsetY();
379 * Gets the current stroke line cap.
381 * @return {@code StrokeLineCap} with a value of Butt, Round, or Square.
383 public String getLineCap();
386 * Sets the current stroke line cap.
388 * @param style a value of Butt, Round, or Square.
390 public void setLineCap(String style);
393 * Gets the current stroke line join.
395 * @return a value of Miter, Bevel, or Round.
397 public String getLineJoin();
400 * Sets the current stroke line join.
402 * @param style with a value of Miter, Bevel, or Round.
404 public void setLineJoin(String style);
407 * Gets the current line width.
409 * @return value between 0 and infinity.
411 public double getLineWidth();
414 * Sets the current line width.
416 * @param width value in the range {0-positive infinity}, with any other
417 * value being ignored and leaving the value unchanged.
419 public void setLineWidth(double width);
422 * Gets the current miter limit. v
424 * @return the miter limit value in the range {@code 0.0-positive infinity}
426 public double getMiterLimit();
429 * Sets the current miter limit.
431 * @param limit miter limit value between 0 and positive infinity with any
432 * other value being ignored and leaving the value unchanged.
434 public void setMiterLimit(double limit);
437 * Gets the current Font.
441 public String getFont();
444 * Sets the current Font.
447 public void setFont(String font);
450 * Gets the current {@code TextAlignment}.
452 * @return TextAlignment with values of Left, Center, Right, or Justify.
454 public String getTextAlign();
457 * Defines horizontal text alignment, relative to the text origin.
459 * @param textAlign with values of Left, Center, Right.
461 public void setTextAlign(String textAlign);
464 * Sets the current Text Baseline.
466 * @param baseline with values of Top, Center, Baseline, or Bottom
468 public String getTextBaseline();
471 * Sets the current Text Baseline.
473 * @param baseline with values of Top, Center, Baseline, or Bottom
475 public void setTextBaseline(String baseline);
478 * Fills the given string of text at position x, y (0,0 at top left) with
479 * the current fill paint attribute.
481 * @param text the string of text.
482 * @param x position on the x axis.
483 * @param y position on the y axis.
485 public void fillText(String text, double x, double y);
488 * Fills text and includes a maximum width of the string.
490 * If the width of the text extends past max width, then it will be sized to
493 * @param text the string of text.
494 * @param x position on the x axis.
495 * @param y position on the y axis.
496 * @param maxWidth maximum width the text string can have.
498 public void fillText(String text, double x, double y, double maxWidth);
501 * The Dimension of this text using the current Font settings
504 * @return the Dimension of this text using the current Font settings
506 public Dimension measureText(String text);
509 * draws the given string of text at position x, y (0,0 at top left) with
510 * the current stroke paint attribute.
512 * @param text the string of text.
513 * @param x position on the x axis.
514 * @param y position on the y axis.
516 public void strokeText(String text, double x, double y);
519 * Draws text with stroke paint and includes a maximum width of the string.
521 * If the width of the text extends past max width, then it will be sized to
524 * @param text the string of text.
525 * @param x position on the x axis.
526 * @param y position on the y axis.
527 * @param maxWidth maximum width the text string can have.
529 public void strokeText(String text, double x, double y, double maxWidth);
532 * Get a pixel array that you can manipulate, e.g. apply effects / transparency
537 public ImageData createPixelMap(double x, double y);
540 * Create a new ImageData object with the same dimensions as the
541 * object specified by imageData (this does not copy the image data)
545 public ImageData createPixelMap(ImageData imageData);
548 * Get the pixels for a region of your GraphicsContext
549 * @param x start x coordinate
550 * @param y start y coordinate
552 * @param height height
555 public ImageData getPixelMap(double x, double y, double width, double height);
558 * Render an ImageData Object at the specified position
559 * @param imageData the Pixel array
560 * @param x start x coordinate
561 * @param y start y coordinate
563 public void putPixelMap(ImageData imageData, double x, double y);
566 * Render an ImageData Object at the specified position
567 * @param imageData the Pixel array to draw
568 * @param x start x coordinate
569 * @param y start y coordinate
570 * @param dirtyx The horizontal (x) value, in pixels, where to place the image on the canvas
571 * @param dirtyy The vertical (y) value, in pixels, where to place the image on the canvas
572 * @param dirtywidth The width to use to draw the image on the canvas
573 * @param dirtyheight The height to use to draw the image on the canvas
575 public void putPixelMap(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
577 * Sets the global alpha of the current state.
579 * @param alpha value in the range {@code 0.0-1.0}. The value is clamped if
580 * it is out of range.
582 public void setGlobalAlpha(double alpha);
585 * Get the global alpha of the current state.
587 * @return alpha value in the range {@code 0.0-1.0}.
589 public double getGlobalAlpha();
592 * Sets the global blend mode.
594 * @param operation the BlendMode that will be set.
596 public void setGlobalCompositeOperation(String operation);
599 * Gets the global blend mode.
601 * @return the global BlendMode of the current state.
603 public String getGlobalCompositeOperation();
606 * Get the height of this GraphicsContext (which should be the same as the
607 * enclosing canvas height)
609 * @return the height of this GraphicsContext
611 public int getHeight();
614 * Get the width of this GraphicsContext (which should be the same as the
615 * enclosing canvas height)
617 * @return the width of this GraphicsContext
619 public int getWidth();
621 // public void setHeight(int height);
623 // public void setWidth(int width);
625 * Merges two images drawing one on top of the other and returning the
628 * @param a the lower Image
629 * @param b the upper Image
630 * @param cachedA the native cached Image, if available, or null.
631 * @param cachedB the native cached Image, if available, or null.
634 public Object mergeImages(Image a, Image b, Object cachedA, Object cachedB);