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 drawImage(ImageData image, double x, double y){
136 //// graphicsEnvironmentImpl.drawImage(image, x, y);
139 //// public void drawImage(ImageData image, double x, double y, double width, double height){
140 //// graphicsEnvironmentImpl.drawImage(image, x, y, width, height);
143 //// public void drawImage(ImageData image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height){
144 //// graphicsEnvironmentImpl.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
147 public void setShadowColor(String color){
148 graphicsEnvironmentImpl.setShadowColor(color);
151 public void setShadowBlur(double blur){
152 graphicsEnvironmentImpl.setShadowBlur(blur);
155 public void setShadowOffsetX(double x){
156 graphicsEnvironmentImpl.setShadowOffsetX(x);
159 public void setShadowOffsetY(double y){
160 graphicsEnvironmentImpl.setShadowOffsetY(y);
163 public String getShadowColor(){
164 return graphicsEnvironmentImpl.getShadowColor();
167 public double getShadowBlur(){
168 return graphicsEnvironmentImpl.getShadowBlur();
171 public double getShadowOffsetX(){
172 return graphicsEnvironmentImpl.getShadowOffsetX();
175 public double getShadowOffsetY(){
176 return graphicsEnvironmentImpl.getShadowOffsetY();
179 public String getLineCap(){
180 return graphicsEnvironmentImpl.getLineCap();
183 public void setLineCap(String style){
184 graphicsEnvironmentImpl.setLineCap(style);
187 public String getLineJoin(){
188 return graphicsEnvironmentImpl.getLineJoin();
191 public void setLineJoin(String style){
192 graphicsEnvironmentImpl.setLineJoin(style);
195 public double getLineWidth(){
196 return graphicsEnvironmentImpl.getLineWidth();
199 public void setLineWidth(double width){
200 graphicsEnvironmentImpl.setLineWidth(width);
203 public double getMiterLimit(){
204 return graphicsEnvironmentImpl.getMiterLimit();
207 public void setMiterLimit(double limit){
208 graphicsEnvironmentImpl.setMiterLimit(limit);
211 public void setFillStyle(Style style){
212 Object nativeFillStyle = graphicsEnvironmentImpl.setFillStyle(style, style.getCached());
213 style.cache(nativeFillStyle);
216 public String getFont(){
217 return graphicsEnvironmentImpl.getFont();
220 public void setFont(String font){
221 graphicsEnvironmentImpl.setFont(font);
224 public void setStrokeStyle(Style style){
225 Object nativeStrokeStyle = graphicsEnvironmentImpl.setStrokeStyle(style, style.getCached());
226 style.cache(nativeStrokeStyle);
229 public String getTextAlign(){
230 return graphicsEnvironmentImpl.getTextAlign();
233 public void setTextAlign(String textAlign){
234 graphicsEnvironmentImpl.setTextAlign(textAlign);
237 public String getTextBaseline(){
238 return graphicsEnvironmentImpl.getTextBaseline();
241 public void setTextBaseline(String textbaseline){
242 graphicsEnvironmentImpl.setTextBaseline(textbaseline);
245 public void fillText(String text, double x, double y){
246 graphicsEnvironmentImpl.fillText(text, x, y);
249 public void fillText(String text, double x, double y, double maxWidth){
250 graphicsEnvironmentImpl.fillText(text, x, y, maxWidth);
253 public Dimension measureText(String text){
254 return graphicsEnvironmentImpl.measureText(text);
257 public void strokeText(String text, double x, double y){
258 graphicsEnvironmentImpl.strokeText(text, x, y);
261 public void strokeText(String text, double x, double y, double maxWidth){
262 graphicsEnvironmentImpl.strokeText(text, x, y, maxWidth);
265 //// public ImageData createImageData(double x, double y){
266 //// return graphicsEnvironmentImpl.createImageData(x, y);
269 //// public ImageData createImageData(ImageData imageData){
270 //// return graphicsEnvironmentImpl.createImageData(imageData);
273 //// public ImageData getImageData(double x, double y, double width, double height){
274 //// return graphicsEnvironmentImpl.getImageData(x, y, width, height);
277 //// public void putImageData(ImageData imageData, double x, double y){
278 //// graphicsEnvironmentImpl.putImageData(imageData, x, y);
281 //// public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight){
282 //// graphicsEnvironmentImpl.putImageData(imageData, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
285 public void setGlobalAlpha(double alpha){
286 graphicsEnvironmentImpl.setGlobalAlpha(alpha);
289 public double getGlobalAlpha(){
290 return graphicsEnvironmentImpl.getGlobalAlpha();
293 public void setGlobalCompositeOperation(String operation){
294 graphicsEnvironmentImpl.setGlobalCompositeOperation(operation);
297 public String getGlobalCompositeOperation(){
298 return graphicsEnvironmentImpl.getGlobalCompositeOperation();
301 public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1){
302 return new LinearGradient(x0, y0, x1, y1);
305 //// public Pattern createPattern(ImageData image, String repeat){
306 //// return new Pattern(image, repeat);
309 public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1){
310 return new RadialGradient(x0, y0, r0, x1, y1, r1);
313 //// public ImageData getImageDataForPath(String path){
314 //// return graphicsEnvironmentImpl.getImageForPath(path);
317 public int getHeight(){
318 return graphicsEnvironmentImpl.getHeight();
321 public int getWidth(){
322 return graphicsEnvironmentImpl.getWidth();
325 public void setHeight(int height){
326 graphicsEnvironmentImpl.setHeight(height);
329 public void setWidth(int width){
330 graphicsEnvironmentImpl.setWidth(width);