Readded Image and ImageData to have the complete API again. No need to use Data in API anymore. Added caching to Image. Image are not required to be added to the page anymore, but are created in javaScript instead.
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;
20 import net.java.html.canvas.spi.GraphicsEnvironment;
26 public final class GraphicsContext {
28 GraphicsEnvironment graphicsEnvironmentImpl;
30 public GraphicsContext(GraphicsEnvironment graphicsEnvironment) {
31 this.graphicsEnvironmentImpl = graphicsEnvironment;
34 public void arc(double centerX,
40 graphicsEnvironmentImpl.arc(centerX, centerY, startAngle, radius, endAngle, ccw);
43 public void arcTo(double x1,
48 graphicsEnvironmentImpl.arcTo(x1, y1, x2, y2, r);
51 public boolean isPointInPath(double x, double y) {
52 return graphicsEnvironmentImpl.isPointInPath(x, y);
56 graphicsEnvironmentImpl.fill();
59 public void stroke() {
60 graphicsEnvironmentImpl.stroke();
63 public void beginPath() {
64 graphicsEnvironmentImpl.beginPath();
67 public void closePath(){
68 graphicsEnvironmentImpl.closePath();
72 graphicsEnvironmentImpl.clip();
75 public void moveTo(double x, double y){
76 graphicsEnvironmentImpl.moveTo(x, y);
79 public void lineTo(double x, double y){
80 graphicsEnvironmentImpl.lineTo(x, y);
83 public void quadraticCurveTo(double cpx, double cpy, double x, double y){
84 graphicsEnvironmentImpl.quadraticCurveTo(cpx, cpy, x, y);
87 public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y){
88 graphicsEnvironmentImpl.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
91 public void fillRect(double x, double y, double width, double height){
92 graphicsEnvironmentImpl.fillRect(x, y, width, height);
95 public void strokeRect(double x, double y, double width, double height){
96 graphicsEnvironmentImpl.strokeRect(x, y, width, height);
99 public void clearRect(double x, double y, double width, double height){
100 graphicsEnvironmentImpl.clearRect(x, y, width, height);
103 public void rect(double x, double y, double width, double height){
104 graphicsEnvironmentImpl.rect(x, y, width, height);
108 graphicsEnvironmentImpl.save();
111 public void restore(){
112 graphicsEnvironmentImpl.restore();
115 public void rotate(double angle){
116 graphicsEnvironmentImpl.rotate(angle);
119 public void transform(double a, double b, double c, double d, double e, double f){
120 graphicsEnvironmentImpl.transform(a, b, c, d, e, f);
123 public void setTransform(double a, double b, double c, double d, double e, double f){
124 graphicsEnvironmentImpl.setTransform(a, b, c, d, e, f);
127 public void translate(double x, double y){
128 graphicsEnvironmentImpl.translate(x, y);
131 public void scale(double x, double y){
132 graphicsEnvironmentImpl.scale(x, y);
135 public void paintImage(Image image, double x, double y){
136 Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, image.getCached());
137 image.cache(nativeImage);
140 public void paintImage(Image image, double x, double y, double width, double height){
141 Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, width, height, image.getCached());
142 image.cache(nativeImage);
145 public void paintImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height){
146 Object nativeImage = graphicsEnvironmentImpl.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height, image.getCached());
147 image.cache(nativeImage);
150 public void setShadowColor(String color){
151 graphicsEnvironmentImpl.setShadowColor(color);
154 public void setShadowBlur(double blur){
155 graphicsEnvironmentImpl.setShadowBlur(blur);
158 public void setShadowOffsetX(double x){
159 graphicsEnvironmentImpl.setShadowOffsetX(x);
162 public void setShadowOffsetY(double y){
163 graphicsEnvironmentImpl.setShadowOffsetY(y);
166 public String getShadowColor(){
167 return graphicsEnvironmentImpl.getShadowColor();
170 public double getShadowBlur(){
171 return graphicsEnvironmentImpl.getShadowBlur();
174 public double getShadowOffsetX(){
175 return graphicsEnvironmentImpl.getShadowOffsetX();
178 public double getShadowOffsetY(){
179 return graphicsEnvironmentImpl.getShadowOffsetY();
182 public String getLineCap(){
183 return graphicsEnvironmentImpl.getLineCap();
186 public void setLineCap(String style){
187 graphicsEnvironmentImpl.setLineCap(style);
190 public String getLineJoin(){
191 return graphicsEnvironmentImpl.getLineJoin();
194 public void setLineJoin(String style){
195 graphicsEnvironmentImpl.setLineJoin(style);
198 public double getLineWidth(){
199 return graphicsEnvironmentImpl.getLineWidth();
202 public void setLineWidth(double width){
203 graphicsEnvironmentImpl.setLineWidth(width);
206 public double getMiterLimit(){
207 return graphicsEnvironmentImpl.getMiterLimit();
210 public void setMiterLimit(double limit){
211 graphicsEnvironmentImpl.setMiterLimit(limit);
214 public void setFillStyle(Style style){
215 Object nativeFillStyle = graphicsEnvironmentImpl.setFillStyle(style, style.getCached());
216 style.cache(nativeFillStyle);
219 public String getFont(){
220 return graphicsEnvironmentImpl.getFont();
223 public void setFont(String font){
224 graphicsEnvironmentImpl.setFont(font);
227 public void setStrokeStyle(Style style){
228 Object nativeStrokeStyle = graphicsEnvironmentImpl.setStrokeStyle(style, style.getCached());
229 style.cache(nativeStrokeStyle);
232 public String getTextAlign(){
233 return graphicsEnvironmentImpl.getTextAlign();
236 public void setTextAlign(String textAlign){
237 graphicsEnvironmentImpl.setTextAlign(textAlign);
240 public String getTextBaseline(){
241 return graphicsEnvironmentImpl.getTextBaseline();
244 public void setTextBaseline(String textbaseline){
245 graphicsEnvironmentImpl.setTextBaseline(textbaseline);
248 public void fillText(String text, double x, double y){
249 graphicsEnvironmentImpl.fillText(text, x, y);
252 public void fillText(String text, double x, double y, double maxWidth){
253 graphicsEnvironmentImpl.fillText(text, x, y, maxWidth);
256 public Dimension measureText(String text){
257 return graphicsEnvironmentImpl.measureText(text);
260 public void strokeText(String text, double x, double y){
261 graphicsEnvironmentImpl.strokeText(text, x, y);
264 public void strokeText(String text, double x, double y, double maxWidth){
265 graphicsEnvironmentImpl.strokeText(text, x, y, maxWidth);
268 public ImageData createPixelMap(double x, double y){
269 return graphicsEnvironmentImpl.createPixelMap(x, y);
272 public ImageData createPixelMap(ImageData pixelMap){
273 return graphicsEnvironmentImpl.createPixelMap(pixelMap);
276 public ImageData getSnapshot(double x, double y, double width, double height){
277 return graphicsEnvironmentImpl.getPixelMap(x, y, width, height);
280 public void paintPixelMap(ImageData pixelMap, double x, double y){
281 graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y);
284 public void paintPixelMap(ImageData pixelMap, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight){
285 graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
288 public void setGlobalAlpha(double alpha){
289 graphicsEnvironmentImpl.setGlobalAlpha(alpha);
292 public double getGlobalAlpha(){
293 return graphicsEnvironmentImpl.getGlobalAlpha();
296 public void setGlobalCompositeOperation(String operation){
297 graphicsEnvironmentImpl.setGlobalCompositeOperation(operation);
300 public String getGlobalCompositeOperation(){
301 return graphicsEnvironmentImpl.getGlobalCompositeOperation();
304 public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1){
305 return new LinearGradient(x0, y0, x1, y1);
308 public Pattern createPattern(Image image, String repeat){
309 return new Pattern(image, repeat);
312 public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1){
313 return new RadialGradient(x0, y0, r0, x1, y1, r1);
316 public Image getImageForPath(String path){
317 return graphicsEnvironmentImpl.getImageForPath(path);
320 public int getHeight(){
321 return graphicsEnvironmentImpl.getHeight();
324 public int getWidth(){
325 return graphicsEnvironmentImpl.getWidth();
328 public void setHeight(int height){
329 graphicsEnvironmentImpl.setHeight(height);
332 public void setWidth(int width){
333 graphicsEnvironmentImpl.setWidth(width);