toni@1111
|
1 |
/**
|
toni@1111
|
2 |
* Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
|
toni@1111
|
3 |
* <jaroslav.tulach@apidesign.org>
|
toni@1111
|
4 |
*
|
toni@1111
|
5 |
* This program is free software: you can redistribute it and/or modify it under
|
toni@1111
|
6 |
* the terms of the GNU General Public License as published by the Free Software
|
toni@1111
|
7 |
* Foundation, version 2 of the License.
|
toni@1111
|
8 |
*
|
toni@1111
|
9 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
toni@1111
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
toni@1111
|
11 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
toni@1111
|
12 |
* details.
|
toni@1111
|
13 |
*
|
toni@1111
|
14 |
* You should have received a copy of the GNU General Public License along with
|
toni@1111
|
15 |
* this program. Look for COPYING file in the top folder. If not, see
|
toni@1111
|
16 |
* http://opensource.org/licenses/GPL-2.0.
|
toni@521
|
17 |
*/
|
toni@1135
|
18 |
package org.apidesign.bck2brwsr.htmlpage;
|
toni@521
|
19 |
|
toni@1134
|
20 |
import java.util.HashMap;
|
toni@1134
|
21 |
import java.util.Set;
|
toni@1138
|
22 |
import net.java.html.canvas.Dimension;
|
toni@1145
|
23 |
import net.java.html.canvas.Image;
|
toni@1145
|
24 |
import net.java.html.canvas.ImageData;
|
toni@1134
|
25 |
import net.java.html.canvas.Style;
|
toni@1151
|
26 |
import net.java.html.canvas.Style.Color;
|
toni@1151
|
27 |
import net.java.html.canvas.Style.LinearGradient;
|
toni@1151
|
28 |
import net.java.html.canvas.Style.Pattern;
|
toni@1151
|
29 |
import net.java.html.canvas.Style.RadialGradient;
|
toni@1138
|
30 |
import net.java.html.canvas.spi.GraphicsEnvironment;
|
toni@521
|
31 |
import org.apidesign.bck2brwsr.core.JavaScriptBody;
|
toni@1135
|
32 |
import org.apidesign.bck2brwsr.htmlpage.api.Canvas;
|
toni@521
|
33 |
|
toni@521
|
34 |
/**
|
toni@521
|
35 |
*
|
toni@1112
|
36 |
* @author Anton Epple <toni.epple@eppleton.de>
|
toni@521
|
37 |
*/
|
toni@1134
|
38 |
public class HTML5GraphicsEnvironment implements GraphicsEnvironment {
|
toni@521
|
39 |
|
toni@1112
|
40 |
Object context;
|
toni@1134
|
41 |
Canvas canvas;
|
toni@1142
|
42 |
|
toni@1142
|
43 |
public HTML5GraphicsEnvironment(Object contextImpl, Canvas canvas) {
|
toni@1112
|
44 |
this.context = contextImpl;
|
toni@1134
|
45 |
this.canvas = canvas;
|
toni@1112
|
46 |
}
|
toni@1112
|
47 |
|
toni@1112
|
48 |
@JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
|
toni@1112
|
49 |
body = "this._context().arc(centerx,centery, radius, startangle, endangle,ccw);")
|
toni@1112
|
50 |
@Override
|
toni@1112
|
51 |
public native void arc(double centerX,
|
toni@1111
|
52 |
double centerY,
|
toni@1111
|
53 |
double startAngle,
|
toni@1111
|
54 |
double radius,
|
toni@1111
|
55 |
double endAngle,
|
toni@1111
|
56 |
boolean ccw);
|
toni@521
|
57 |
|
toni@1112
|
58 |
@JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
|
toni@1112
|
59 |
body = "this._context().arcTo(x1,y1,x2,y2,r);")
|
toni@1112
|
60 |
@Override
|
toni@1112
|
61 |
public native void arcTo(double x1,
|
toni@1111
|
62 |
double y1,
|
toni@1111
|
63 |
double x2,
|
toni@1111
|
64 |
double y2,
|
toni@1111
|
65 |
double r);
|
toni@521
|
66 |
|
toni@1112
|
67 |
@JavaScriptBody(args = {"x", "y"},
|
toni@1112
|
68 |
body = "return this._context().isPointInPath(x,y);")
|
toni@1112
|
69 |
@Override
|
toni@1112
|
70 |
public native boolean isPointInPath(double x, double y);
|
toni@521
|
71 |
|
toni@1112
|
72 |
@JavaScriptBody(args = {}, body = "this._context().fill();")
|
toni@1112
|
73 |
@Override
|
toni@1112
|
74 |
public native void fill();
|
toni@521
|
75 |
|
toni@1112
|
76 |
@JavaScriptBody(args = {}, body = "this._context().stroke();")
|
toni@1112
|
77 |
@Override
|
toni@1112
|
78 |
public native void stroke();
|
toni@1109
|
79 |
|
toni@1112
|
80 |
@JavaScriptBody(args = {}, body = "this._context().beginPath();")
|
toni@1112
|
81 |
@Override
|
toni@1112
|
82 |
public native void beginPath();
|
toni@1109
|
83 |
|
toni@1112
|
84 |
@JavaScriptBody(args = {}, body = "this._context().closePath();")
|
toni@1112
|
85 |
@Override
|
toni@1112
|
86 |
public native void closePath();
|
toni@521
|
87 |
|
toni@1112
|
88 |
@JavaScriptBody(args = {}, body = "this._context().clip();")
|
toni@1112
|
89 |
@Override
|
toni@1112
|
90 |
public native void clip();
|
toni@1109
|
91 |
|
toni@1112
|
92 |
@JavaScriptBody(args = {"x", "y"}, body = "this._context().moveTo(x,y);")
|
toni@1112
|
93 |
@Override
|
toni@1112
|
94 |
public native void moveTo(double x, double y);
|
toni@1109
|
95 |
|
toni@1112
|
96 |
@JavaScriptBody(args = {"x", "y"}, body = "this._context().lineTo(x,y);")
|
toni@1112
|
97 |
@Override
|
toni@1112
|
98 |
public native void lineTo(double x, double y);
|
toni@1109
|
99 |
|
toni@1112
|
100 |
@JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this._context().quadraticCurveTo(cpx,cpy,x,y);")
|
toni@1112
|
101 |
@Override
|
toni@1112
|
102 |
public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
|
toni@1109
|
103 |
|
toni@1112
|
104 |
@JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
|
toni@1112
|
105 |
body = "this._context().bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
|
toni@1112
|
106 |
@Override
|
toni@1112
|
107 |
public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
|
toni@1109
|
108 |
|
toni@1112
|
109 |
@JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().fillRect(x,y,width,height);")
|
toni@1112
|
110 |
@Override
|
toni@1112
|
111 |
public native void fillRect(double x, double y, double width, double height);
|
toni@1109
|
112 |
|
toni@1112
|
113 |
@JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().strokeRect(x,y,width,height);")
|
toni@1112
|
114 |
@Override
|
toni@1112
|
115 |
public native void strokeRect(double x, double y, double width, double height);
|
toni@1109
|
116 |
|
toni@1112
|
117 |
@JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().clearRect(x,y,width,height);")
|
toni@1112
|
118 |
@Override
|
toni@1112
|
119 |
public native void clearRect(double x, double y, double width, double height);
|
toni@1109
|
120 |
|
toni@1145
|
121 |
@JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rect(x,y,width,height);")
|
toni@1112
|
122 |
@Override
|
toni@1112
|
123 |
public native void rect(double x, double y, double width, double height);
|
toni@1109
|
124 |
|
toni@1112
|
125 |
@JavaScriptBody(args = {}, body = "this._context().save();")
|
toni@1112
|
126 |
@Override
|
toni@1112
|
127 |
public native void save();
|
toni@1109
|
128 |
|
toni@1112
|
129 |
@JavaScriptBody(args = {}, body = "this._context().restore();")
|
toni@1112
|
130 |
@Override
|
toni@1112
|
131 |
public native void restore();
|
toni@1109
|
132 |
|
toni@1112
|
133 |
@JavaScriptBody(args = {"angle"}, body = "this._context().rotate(angle);")
|
toni@1112
|
134 |
@Override
|
toni@1112
|
135 |
public native void rotate(double angle);
|
toni@1109
|
136 |
|
toni@1112
|
137 |
@JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().transform(a,b,c,d,e,f);")
|
toni@1112
|
138 |
@Override
|
toni@1112
|
139 |
public native void transform(double a, double b, double c, double d, double e, double f);
|
toni@1109
|
140 |
|
toni@1112
|
141 |
@JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().setTransform(a,b,c,d,e,f);")
|
toni@1112
|
142 |
@Override
|
toni@1112
|
143 |
public native void setTransform(double a, double b, double c, double d, double e, double f);
|
toni@1109
|
144 |
|
toni@1112
|
145 |
@JavaScriptBody(args = {"x", "y"}, body = "this._context().translate(x,y);")
|
toni@1112
|
146 |
@Override
|
toni@1112
|
147 |
public native void translate(double x, double y);
|
toni@1109
|
148 |
|
toni@1112
|
149 |
@JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
|
toni@1112
|
150 |
@Override
|
toni@1112
|
151 |
public native void scale(double x, double y);
|
toni@1109
|
152 |
|
toni@1145
|
153 |
@Override
|
toni@1145
|
154 |
public Object drawImage(Image image, double x, double y, Object nativeImage) {
|
toni@1145
|
155 |
if (nativeImage == null) {
|
toni@1145
|
156 |
nativeImage = createImage(image.getSrc());
|
toni@1145
|
157 |
}
|
toni@1145
|
158 |
return drawImageImpl(context, nativeImage, x, y);
|
toni@1145
|
159 |
}
|
toni@1145
|
160 |
|
toni@1145
|
161 |
@Override
|
toni@1145
|
162 |
public Object drawImage(Image image, double x, double y, double width, double height, Object nativeImage) {
|
toni@1145
|
163 |
if (nativeImage == null) {
|
toni@1145
|
164 |
nativeImage = createImage(image.getSrc());
|
toni@1145
|
165 |
}
|
toni@1145
|
166 |
return drawImageImpl(context, nativeImage, x, y, width, height);
|
toni@1145
|
167 |
}
|
toni@1145
|
168 |
|
toni@1145
|
169 |
@Override
|
toni@1145
|
170 |
public Object drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height, Object nativeImage) {
|
toni@1145
|
171 |
if (nativeImage == null) {
|
toni@1145
|
172 |
nativeImage = createImage(image.getSrc());
|
toni@1145
|
173 |
}
|
toni@1145
|
174 |
return drawImageImpl(context, nativeImage, sx, sy, sWidth, sHeight, x, y, width, height);
|
toni@1145
|
175 |
}
|
toni@1145
|
176 |
|
toni@1145
|
177 |
@JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height); return img;")
|
toni@1145
|
178 |
private native static Object drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
|
toni@1145
|
179 |
|
toni@1145
|
180 |
@JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); return img;")
|
toni@1145
|
181 |
private native static Object drawImageImpl(Object ctx, Object img, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
|
toni@1145
|
182 |
|
toni@1145
|
183 |
@JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y); return img;")
|
toni@1145
|
184 |
private native static Object drawImageImpl(Object ctx, Object img, double x, double y);
|
toni@1145
|
185 |
|
toni@1142
|
186 |
public Object setFillStyle(Style style, Object nativeStyle) {
|
toni@1142
|
187 |
if (nativeStyle == null) {
|
toni@1142
|
188 |
nativeStyle = createNativeStyle(style);
|
toni@1142
|
189 |
}
|
toni@1142
|
190 |
setFillStyleImpl(context, nativeStyle);
|
toni@1142
|
191 |
return nativeStyle;
|
toni@1112
|
192 |
}
|
toni@1109
|
193 |
|
toni@1142
|
194 |
private Object createNativeStyle(Style style) {
|
toni@1134
|
195 |
if (style instanceof RadialGradient) {
|
toni@1134
|
196 |
RadialGradientWrapper gradient = createRadialGradientWrapper(
|
toni@1134
|
197 |
((RadialGradient) style).getX0(),
|
toni@1134
|
198 |
((RadialGradient) style).getY0(),
|
toni@1134
|
199 |
((RadialGradient) style).getR0(),
|
toni@1134
|
200 |
((RadialGradient) style).getX1(),
|
toni@1134
|
201 |
((RadialGradient) style).getY1(),
|
toni@1134
|
202 |
((RadialGradient) style).getR1());
|
toni@1134
|
203 |
HashMap<Double, String> stops = ((LinearGradient) style).getStops();
|
toni@1134
|
204 |
Set<Double> keySet = stops.keySet();
|
toni@1134
|
205 |
for (Double double1 : keySet) {
|
toni@1134
|
206 |
addColorStopImpl(style, double1, stops.get(double1));
|
toni@1134
|
207 |
}
|
toni@1134
|
208 |
return gradient;
|
toni@1134
|
209 |
|
toni@1134
|
210 |
|
toni@1134
|
211 |
} else if (style instanceof LinearGradient) {
|
toni@1134
|
212 |
LinearGradientWrapper gradient = createLinearGradientWrapper(
|
toni@1134
|
213 |
((LinearGradient) style).getX0(),
|
toni@1134
|
214 |
((LinearGradient) style).getY0(),
|
toni@1134
|
215 |
((LinearGradient) style).getX1(),
|
toni@1134
|
216 |
((LinearGradient) style).getY1());
|
toni@1134
|
217 |
HashMap<Double, String> stops = ((LinearGradient) style).getStops();
|
toni@1134
|
218 |
Set<Double> keySet = stops.keySet();
|
toni@1134
|
219 |
for (Double double1 : keySet) {
|
toni@1134
|
220 |
addColorStopImpl(style, double1, stops.get(double1));
|
toni@1134
|
221 |
}
|
toni@1134
|
222 |
return gradient;
|
toni@1142
|
223 |
} else if (style instanceof Pattern) {
|
toni@1149
|
224 |
return createPatternWrapper(((Pattern) style).getImageResource(), ((Pattern) style).getRepeat());
|
toni@1149
|
225 |
} else if (style instanceof Color) {
|
toni@1149
|
226 |
return ((Color) style)
|
toni@1149
|
227 |
.getAsString();
|
toni@1134
|
228 |
}
|
toni@1134
|
229 |
return null;
|
toni@1112
|
230 |
}
|
toni@1109
|
231 |
|
toni@1134
|
232 |
@JavaScriptBody(args = {"gradient", "position", "color"}, body =
|
toni@1134
|
233 |
"gradient.addColorStop(position,color)")
|
toni@1134
|
234 |
private static native void addColorStopImpl(Object gradient, double position, String color);
|
toni@1109
|
235 |
|
toni@1112
|
236 |
@JavaScriptBody(args = {"context", "obj"}, body = "context.fillStyle=obj;")
|
toni@1112
|
237 |
private native void setFillStyleImpl(Object context, Object obj);
|
toni@1109
|
238 |
|
toni@1112
|
239 |
@JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style.valueOf();")
|
toni@1112
|
240 |
public native void setStrokeStyle(String style);
|
toni@1109
|
241 |
|
toni@1112
|
242 |
@Override
|
toni@1142
|
243 |
public Object setStrokeStyle(Style style, Object nativeStyle) {
|
toni@1145
|
244 |
if (nativeStyle == null) {
|
toni@1142
|
245 |
nativeStyle = createNativeStyle(style);
|
toni@1142
|
246 |
}
|
toni@1142
|
247 |
setStrokeStyleImpl(context, nativeStyle);
|
toni@1142
|
248 |
return nativeStyle;
|
toni@1112
|
249 |
}
|
toni@1109
|
250 |
|
toni@1112
|
251 |
@JavaScriptBody(args = {"context", "obj"}, body = "context.strokeStyle=obj;")
|
toni@1112
|
252 |
private native void setStrokeStyleImpl(Object context, Object obj);
|
toni@1109
|
253 |
|
toni@1112
|
254 |
@JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color.valueOf();")
|
toni@1112
|
255 |
@Override
|
toni@1112
|
256 |
public native void setShadowColor(String color);
|
toni@1109
|
257 |
|
toni@1112
|
258 |
@JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
|
toni@1112
|
259 |
@Override
|
toni@1112
|
260 |
public native void setShadowBlur(double blur);
|
toni@1109
|
261 |
|
toni@1112
|
262 |
@JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
|
toni@1112
|
263 |
@Override
|
toni@1112
|
264 |
public native void setShadowOffsetX(double x);
|
toni@1109
|
265 |
|
toni@1112
|
266 |
@JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
|
toni@1112
|
267 |
@Override
|
toni@1112
|
268 |
public native void setShadowOffsetY(double y);
|
toni@1109
|
269 |
|
toni@1112
|
270 |
@JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
|
toni@1112
|
271 |
public native String getStrokeStyle();
|
toni@1109
|
272 |
|
toni@1112
|
273 |
@JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
|
toni@1112
|
274 |
@Override
|
toni@1112
|
275 |
public native String getShadowColor();
|
toni@1109
|
276 |
|
toni@1112
|
277 |
@JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
|
toni@1112
|
278 |
@Override
|
toni@1112
|
279 |
public native double getShadowBlur();
|
toni@1109
|
280 |
|
toni@1112
|
281 |
@JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
|
toni@1112
|
282 |
@Override
|
toni@1112
|
283 |
public native double getShadowOffsetX();
|
toni@1109
|
284 |
|
toni@1112
|
285 |
@JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
|
toni@1112
|
286 |
@Override
|
toni@1112
|
287 |
public native double getShadowOffsetY();
|
toni@1109
|
288 |
|
toni@1112
|
289 |
@JavaScriptBody(args = {}, body = "return this._context().lineCap;")
|
toni@1112
|
290 |
@Override
|
toni@1112
|
291 |
public native String getLineCap();
|
toni@1109
|
292 |
|
toni@1112
|
293 |
@JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style.valueOf();")
|
toni@1112
|
294 |
@Override
|
toni@1112
|
295 |
public native void setLineCap(String style);
|
toni@521
|
296 |
|
toni@1112
|
297 |
@JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
|
toni@1112
|
298 |
@Override
|
toni@1112
|
299 |
public native String getLineJoin();
|
toni@521
|
300 |
|
toni@1112
|
301 |
@JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style.valueOf();")
|
toni@1112
|
302 |
@Override
|
toni@1112
|
303 |
public native void setLineJoin(String style);
|
toni@521
|
304 |
|
toni@1112
|
305 |
@JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
|
toni@1112
|
306 |
@Override
|
toni@1112
|
307 |
public native double getLineWidth();
|
toni@521
|
308 |
|
toni@1112
|
309 |
@JavaScriptBody(args = {"width"}, body = "this._context().lineWidth=width;")
|
toni@1112
|
310 |
@Override
|
toni@1112
|
311 |
public native void setLineWidth(double width);
|
toni@521
|
312 |
|
toni@1112
|
313 |
@JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
|
toni@1112
|
314 |
@Override
|
toni@1112
|
315 |
public native double getMiterLimit();
|
toni@521
|
316 |
|
toni@1112
|
317 |
@JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
|
toni@1112
|
318 |
@Override
|
toni@1112
|
319 |
public native void setMiterLimit(double limit);
|
toni@1111
|
320 |
|
toni@1112
|
321 |
@JavaScriptBody(args = {}, body = "return this._context().font;")
|
toni@1112
|
322 |
@Override
|
toni@1112
|
323 |
public native String getFont();
|
toni@1111
|
324 |
|
toni@1112
|
325 |
@JavaScriptBody(args = {"font"}, body = "this._context().font=font.valueOf();")
|
toni@1112
|
326 |
@Override
|
toni@1112
|
327 |
public native void setFont(String font);
|
toni@1111
|
328 |
|
toni@1112
|
329 |
@JavaScriptBody(args = {}, body = "return this._context().textAlign;")
|
toni@1112
|
330 |
@Override
|
toni@1112
|
331 |
public native String getTextAlign();
|
toni@1111
|
332 |
|
toni@1112
|
333 |
@JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign.valueOf();")
|
toni@1112
|
334 |
@Override
|
toni@1112
|
335 |
public native void setTextAlign(String textAlign);
|
toni@1111
|
336 |
|
toni@1112
|
337 |
@JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
|
toni@1112
|
338 |
@Override
|
toni@1112
|
339 |
public native String getTextBaseline();
|
toni@1111
|
340 |
|
toni@1112
|
341 |
@JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline.valueOf();")
|
toni@1112
|
342 |
@Override
|
toni@1112
|
343 |
public native void setTextBaseline(String textbaseline);
|
toni@1111
|
344 |
|
toni@1112
|
345 |
@JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
|
toni@1138
|
346 |
// @JavaScriptBody(args = {"text", "x", "y"}, body = "console.log(text);")
|
toni@1112
|
347 |
@Override
|
toni@1112
|
348 |
public native void fillText(String text, double x, double y);
|
toni@1111
|
349 |
|
toni@1112
|
350 |
@JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
|
toni@1112
|
351 |
@Override
|
toni@1112
|
352 |
public void fillText(String text, double x, double y, double maxWidth) {
|
toni@1112
|
353 |
}
|
toni@1111
|
354 |
|
toni@1112
|
355 |
@Override
|
toni@1134
|
356 |
public Dimension measureText(String text) {
|
toni@1138
|
357 |
measureTextImpl(text);
|
toni@1142
|
358 |
return new Dimension(1, 1);
|
toni@1112
|
359 |
}
|
toni@1111
|
360 |
|
toni@1112
|
361 |
@JavaScriptBody(args = {"text"},
|
toni@1112
|
362 |
body = "return this._context().measureText(text);")
|
toni@1112
|
363 |
private native Object measureTextImpl(String text);
|
toni@1111
|
364 |
|
toni@1112
|
365 |
@JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
|
toni@1112
|
366 |
@Override
|
toni@1112
|
367 |
public native void strokeText(String text, double x, double y);
|
toni@1111
|
368 |
|
toni@1112
|
369 |
@JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
|
toni@1112
|
370 |
@Override
|
toni@1112
|
371 |
public native void strokeText(String text, double x, double y, double maxWidth);
|
toni@1111
|
372 |
|
toni@1145
|
373 |
@Override
|
toni@1145
|
374 |
public ImageData createPixelMap(double x, double y) {
|
toni@1145
|
375 |
return new ImageDataWrapper(createPixelMapImpl(x, y));
|
toni@1145
|
376 |
}
|
toni@1145
|
377 |
|
toni@1145
|
378 |
@JavaScriptBody(args = {"x", "y"},
|
toni@1145
|
379 |
body = "return this._context().createImageData(x,y);")
|
toni@1145
|
380 |
private native Object createPixelMapImpl(double x, double y);
|
toni@1145
|
381 |
|
toni@1145
|
382 |
@Override
|
toni@1145
|
383 |
public ImageData createPixelMap(ImageData imageData) {
|
toni@1145
|
384 |
return new ImageDataWrapper(createPixelMapImpl(imageData.getWidth(), imageData.getHeight()));
|
toni@1145
|
385 |
}
|
toni@1145
|
386 |
|
toni@1145
|
387 |
@Override
|
toni@1145
|
388 |
public ImageData getPixelMap(double x, double y, double width, double height) {
|
toni@1145
|
389 |
return new ImageDataWrapper(getPixelMapImpl(x, y, width, height));
|
toni@1145
|
390 |
}
|
toni@1145
|
391 |
|
toni@1145
|
392 |
@JavaScriptBody(args = {"x", "y", "width", "height"},
|
toni@1145
|
393 |
body = "return this._context().getImageData(x,y,width,height);")
|
toni@1145
|
394 |
private native Object getPixelMapImpl(double x, double y, double width, double height);
|
toni@1145
|
395 |
|
toni@1145
|
396 |
@Override
|
toni@1145
|
397 |
public void putPixelMap(ImageData imageData, double x, double y) {
|
toni@1145
|
398 |
putPixelMapImpl(((ImageDataWrapper) imageData).object(), x, y);
|
toni@1145
|
399 |
}
|
toni@1145
|
400 |
|
toni@1145
|
401 |
@JavaScriptBody(args = {"imageData", "x", "y"},
|
toni@1145
|
402 |
body = "this._context().putImageData(imageData,x,y);")
|
toni@1145
|
403 |
private native void putPixelMapImpl(Object imageData, double x, double y);
|
toni@1145
|
404 |
|
toni@1145
|
405 |
@Override
|
toni@1145
|
406 |
public void putPixelMap(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
|
toni@1145
|
407 |
putPixelMapImpl(((ImageDataWrapper) imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
|
toni@1145
|
408 |
}
|
toni@1145
|
409 |
|
toni@1112
|
410 |
@JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
|
toni@1112
|
411 |
body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
|
toni@1145
|
412 |
private native void putPixelMapImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
|
toni@1112
|
413 |
|
toni@1112
|
414 |
@JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
|
toni@1112
|
415 |
@Override
|
toni@1112
|
416 |
public native void setGlobalAlpha(double alpha);
|
toni@1112
|
417 |
|
toni@1112
|
418 |
@JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
|
toni@1112
|
419 |
@Override
|
toni@1112
|
420 |
public native double getGlobalAlpha();
|
toni@1112
|
421 |
|
toni@1112
|
422 |
@JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation.valueOf();")
|
toni@1112
|
423 |
@Override
|
toni@1112
|
424 |
public native void setGlobalCompositeOperation(String operation);
|
toni@1112
|
425 |
|
toni@1112
|
426 |
@JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
|
toni@1112
|
427 |
@Override
|
toni@1112
|
428 |
public native String getGlobalCompositeOperation();
|
toni@1112
|
429 |
|
toni@1134
|
430 |
public LinearGradientWrapper createLinearGradientWrapper(double x0, double y0, double x1, double y1) {
|
toni@1134
|
431 |
return new LinearGradientWrapper(createLinearGradientImpl(context, x0, y0, x1, y1));
|
toni@1112
|
432 |
}
|
toni@1112
|
433 |
|
toni@1112
|
434 |
@JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
|
toni@1112
|
435 |
private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
|
toni@1112
|
436 |
|
toni@1145
|
437 |
public PatternWrapper createPatternWrapper(Image image, String repeat) {
|
toni@1145
|
438 |
return new PatternWrapper(createPatternImpl(context, image, repeat));
|
toni@1145
|
439 |
}
|
toni@1145
|
440 |
|
toni@1145
|
441 |
@JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
|
toni@1145
|
442 |
private static native Object createPatternImpl(Object context, Image image, String repeat);
|
toni@1145
|
443 |
|
toni@1134
|
444 |
public RadialGradientWrapper createRadialGradientWrapper(double x0, double y0, double r0, double x1, double y1, double r1) {
|
toni@1134
|
445 |
return new RadialGradientWrapper(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
|
toni@1112
|
446 |
}
|
toni@1112
|
447 |
|
toni@1112
|
448 |
@JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
|
toni@1112
|
449 |
private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);
|
toni@1121
|
450 |
|
toni@1145
|
451 |
@JavaScriptBody(args = {"path"}, body = "var b = new Image(); b.src=path; return b;")
|
toni@1145
|
452 |
public native Image getImageForPath(String path);
|
toni@1145
|
453 |
|
toni@1121
|
454 |
@Override
|
toni@1134
|
455 |
public int getHeight() {
|
toni@1142
|
456 |
return canvas.getHeight();
|
toni@1121
|
457 |
}
|
toni@1134
|
458 |
|
toni@1134
|
459 |
@Override
|
toni@1134
|
460 |
public int getWidth() {
|
toni@1142
|
461 |
return canvas.getWidth();
|
toni@1134
|
462 |
}
|
toni@1134
|
463 |
|
toni@1134
|
464 |
@Override
|
toni@1134
|
465 |
public void setHeight(int height) {
|
toni@1142
|
466 |
canvas.setHeight(height);
|
toni@1134
|
467 |
}
|
toni@1134
|
468 |
|
toni@1134
|
469 |
@Override
|
toni@1134
|
470 |
public void setWidth(int width) {
|
toni@1142
|
471 |
canvas.setWidth(width);
|
toni@1134
|
472 |
}
|
toni@1145
|
473 |
|
toni@1145
|
474 |
@JavaScriptBody(args = {"src"}, body = "var image = new Image(); image.src = src; return image;")
|
toni@1145
|
475 |
private static native Object createImage(String src);
|
toni@521
|
476 |
}
|