reflexo_vec2canvas/
device.rs

1use web_sys::{CanvasWindingRule, ImageBitmap, ImageData, OffscreenCanvas, Path2d};
2
3pub trait CanvasDevice {
4    #[doc = "The `restore()` method."]
5    #[doc = ""]
6    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore)"]
7    fn restore(&self);
8    #[doc = "The `save()` method."]
9    #[doc = ""]
10    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save)"]
11    fn save(&self);
12
13    #[doc = "The `setTransform()` method."]
14    #[doc = ""]
15    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform)"]
16    fn set_transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64);
17    #[doc = "Setter for the `fillStyle` field of this object."]
18    #[doc = ""]
19    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle)"]
20    fn set_fill_style_str(&self, value: &str);
21
22    #[doc = "The `fillRect()` method."]
23    #[doc = ""]
24    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillRect)"]
25    fn fill_rect(&self, x: f64, y: f64, w: f64, h: f64);
26
27    #[doc = "The `putImageData()` method."]
28    #[doc = ""]
29    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/putImageData)"]
30    fn put_image_data(&self, imagedata: &ImageData, dx: f64, dy: f64);
31    #[doc = "Getter for the `globalCompositeOperation` field of this object."]
32    #[doc = ""]
33    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation)"]
34    fn global_composite_operation(&self) -> String;
35    #[doc = "Setter for the `globalCompositeOperation` field of this object."]
36    #[doc = ""]
37    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation)"]
38    fn set_global_composite_operation(&self, value: &str);
39    #[doc = "The `drawImage()` method."]
40    #[doc = ""]
41    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage)"]
42    fn draw_image_with_offscreen_canvas(&self, image: &OffscreenCanvas, dx: f64, dy: f64);
43
44    #[doc = "The `clip()` method."]
45    #[doc = ""]
46    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip)"]
47    fn clip_with_path_2d(&self, path: &Path2d);
48    #[doc = "Setter for the `strokeStyle` field of this object."]
49    #[doc = ""]
50    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle)"]
51    fn set_stroke_style_str(&self, value: &str);
52    #[doc = "The `stroke()` method."]
53    #[doc = ""]
54    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/stroke)"]
55    fn stroke_with_path(&self, path: &Path2d);
56    #[doc = "The `drawImage()` method."]
57    #[doc = ""]
58    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage)"]
59    fn draw_image_with_image_bitmap_and_dw_and_dh(
60        &self,
61        image: &ImageBitmap,
62        dx: f64,
63        dy: f64,
64        dw: f64,
65        dh: f64,
66    );
67    #[doc = "The `drawImage()` method."]
68    #[doc = ""]
69    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvasRenderingContext2D/drawImage)"]
70    fn draw_image_with_offscreen_canvas_and_dw_and_dh(
71        &self,
72        image: &OffscreenCanvas,
73        dx: f64,
74        dy: f64,
75        dw: f64,
76        dh: f64,
77    );
78
79    #[doc = "Setter for the `lineWidth` field of this object."]
80    #[doc = ""]
81    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth)"]
82    fn set_line_width(&self, value: f64);
83    #[doc = "Setter for the `lineCap` field of this object."]
84    #[doc = ""]
85    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineCap)"]
86    fn set_line_cap(&self, value: &str);
87    #[doc = "Setter for the `lineJoin` field of this object."]
88    #[doc = ""]
89    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin)"]
90    fn set_line_join(&self, value: &str);
91    #[doc = "Setter for the `miterLimit` field of this object."]
92    #[doc = ""]
93    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/miterLimit)"]
94    fn set_miter_limit(&self, value: f64);
95    #[doc = "Setter for the `lineDashOffset` field of this object."]
96    #[doc = ""]
97    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset)"]
98    fn set_line_dash_offset(&self, value: f64);
99    #[doc = "The `setLineDash()` method."]
100    #[doc = ""]
101    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash)"]
102    fn set_line_dash(&self, segments: &::wasm_bindgen::JsValue);
103    #[doc = "The `fill()` method."]
104    #[doc = ""]
105    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fill)"]
106    fn fill_with_path_2d(&self, path: &Path2d);
107    #[doc = "The `fill()` method."]
108    #[doc = ""]
109    #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvasRenderingContext2D/fill)"]
110    fn fill_with_path_2d_and_winding(&self, path: &Path2d, winding: CanvasWindingRule);
111}
112
113impl CanvasDevice for web_sys::CanvasRenderingContext2d {
114    fn set_transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
115        // .map_err(map_err("CanvasRenderTask.SetTransform"))
116        self.set_transform(a, b, c, d, e, f).unwrap();
117    }
118
119    fn put_image_data(&self, imagedata: &ImageData, dx: f64, dy: f64) {
120        self.put_image_data(imagedata, dx, dy).unwrap();
121    }
122
123    fn global_composite_operation(&self) -> String {
124        self.global_composite_operation().unwrap()
125    }
126
127    fn set_global_composite_operation(&self, value: &str) {
128        self.set_global_composite_operation(value).unwrap();
129    }
130
131    fn set_fill_style_str(&self, value: &str) {
132        self.set_fill_style_str(value);
133    }
134
135    fn fill_rect(&self, x: f64, y: f64, w: f64, h: f64) {
136        self.fill_rect(x, y, w, h);
137    }
138
139    fn draw_image_with_offscreen_canvas(&self, image: &OffscreenCanvas, dx: f64, dy: f64) {
140        self.draw_image_with_offscreen_canvas(image, dx, dy)
141            .unwrap();
142    }
143
144    fn clip_with_path_2d(&self, path: &Path2d) {
145        self.clip_with_path_2d(path);
146    }
147
148    fn set_stroke_style_str(&self, value: &str) {
149        self.set_stroke_style_str(value);
150    }
151
152    fn stroke_with_path(&self, path: &Path2d) {
153        self.stroke_with_path(path);
154    }
155
156    fn draw_image_with_image_bitmap_and_dw_and_dh(
157        &self,
158        image: &ImageBitmap,
159        dx: f64,
160        dy: f64,
161        dw: f64,
162        dh: f64,
163    ) {
164        self.draw_image_with_image_bitmap_and_dw_and_dh(image, dx, dy, dw, dh)
165            .unwrap();
166    }
167
168    fn draw_image_with_offscreen_canvas_and_dw_and_dh(
169        &self,
170        image: &OffscreenCanvas,
171        dx: f64,
172        dy: f64,
173        dw: f64,
174        dh: f64,
175    ) {
176        self.draw_image_with_offscreen_canvas_and_dw_and_dh(image, dx, dy, dw, dh)
177            .unwrap();
178    }
179
180    fn set_line_width(&self, value: f64) {
181        self.set_line_width(value);
182    }
183
184    fn set_line_cap(&self, value: &str) {
185        self.set_line_cap(value);
186    }
187
188    fn set_line_join(&self, value: &str) {
189        self.set_line_join(value);
190    }
191
192    fn set_miter_limit(&self, value: f64) {
193        self.set_miter_limit(value);
194    }
195
196    fn set_line_dash_offset(&self, value: f64) {
197        self.set_line_dash_offset(value);
198    }
199
200    fn restore(&self) {
201        self.restore();
202    }
203
204    fn save(&self) {
205        self.save();
206    }
207
208    fn set_line_dash(&self, segments: &::wasm_bindgen::JsValue) {
209        self.set_line_dash(segments).unwrap();
210    }
211
212    fn fill_with_path_2d(&self, path: &Path2d) {
213        self.fill_with_path_2d(path);
214    }
215
216    fn fill_with_path_2d_and_winding(&self, path: &Path2d, winding: CanvasWindingRule) {
217        self.fill_with_path_2d_and_winding(path, winding);
218    }
219}
220
221impl CanvasDevice for web_sys::OffscreenCanvasRenderingContext2d {
222    fn set_transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
223        self.set_transform(a, b, c, d, e, f).unwrap();
224    }
225
226    fn put_image_data(&self, imagedata: &ImageData, dx: f64, dy: f64) {
227        self.put_image_data(imagedata, dx, dy).unwrap();
228    }
229
230    fn global_composite_operation(&self) -> String {
231        self.global_composite_operation().unwrap()
232    }
233
234    fn set_global_composite_operation(&self, value: &str) {
235        self.set_global_composite_operation(value).unwrap();
236    }
237
238    fn set_fill_style_str(&self, value: &str) {
239        self.set_fill_style_str(value);
240    }
241
242    fn fill_rect(&self, x: f64, y: f64, w: f64, h: f64) {
243        self.fill_rect(x, y, w, h);
244    }
245
246    fn draw_image_with_offscreen_canvas(&self, image: &OffscreenCanvas, dx: f64, dy: f64) {
247        self.draw_image_with_offscreen_canvas(image, dx, dy)
248            .unwrap();
249    }
250
251    fn clip_with_path_2d(&self, path: &Path2d) {
252        self.clip_with_path_2d(path);
253    }
254
255    fn set_stroke_style_str(&self, value: &str) {
256        self.set_stroke_style_str(value);
257    }
258
259    fn stroke_with_path(&self, path: &Path2d) {
260        self.stroke_with_path(path);
261    }
262
263    fn draw_image_with_image_bitmap_and_dw_and_dh(
264        &self,
265        image: &ImageBitmap,
266        dx: f64,
267        dy: f64,
268        dw: f64,
269        dh: f64,
270    ) {
271        self.draw_image_with_image_bitmap_and_dw_and_dh(image, dx, dy, dw, dh)
272            .unwrap();
273    }
274
275    fn draw_image_with_offscreen_canvas_and_dw_and_dh(
276        &self,
277        image: &OffscreenCanvas,
278        dx: f64,
279        dy: f64,
280        dw: f64,
281        dh: f64,
282    ) {
283        self.draw_image_with_offscreen_canvas_and_dw_and_dh(image, dx, dy, dw, dh)
284            .unwrap();
285    }
286
287    fn set_line_width(&self, value: f64) {
288        self.set_line_width(value);
289    }
290
291    fn set_line_cap(&self, value: &str) {
292        self.set_line_cap(value);
293    }
294
295    fn set_line_join(&self, value: &str) {
296        self.set_line_join(value);
297    }
298
299    fn set_miter_limit(&self, value: f64) {
300        self.set_miter_limit(value);
301    }
302
303    fn set_line_dash_offset(&self, value: f64) {
304        self.set_line_dash_offset(value);
305    }
306
307    fn restore(&self) {
308        self.restore();
309    }
310
311    fn save(&self) {
312        self.save();
313    }
314
315    fn set_line_dash(&self, segments: &::wasm_bindgen::JsValue) {
316        self.set_line_dash(segments).unwrap();
317    }
318
319    fn fill_with_path_2d(&self, path: &Path2d) {
320        self.fill_with_path_2d(path);
321    }
322
323    fn fill_with_path_2d_and_winding(&self, path: &Path2d, winding: CanvasWindingRule) {
324        self.fill_with_path_2d_and_winding(path, winding);
325    }
326}