# core/canvas2d/desktop_canvas (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/canvas2d/desktop_canvas/

2D 그리기 대상의 데스크탑 판. (tiny-skia 로 칠한다, core/canvas2d.rs 머리 주석)

예제: 다른 캔버스의 두 픽셀을 매끄럽게 하지 않고 늘여 그리기

```rust
use vanilla::Canvas2D;

let mut source = Canvas2D::new(2, 1);
source.set_fill_style("#ff0000");
source.fill_rect(0.0, 0.0, 1.0, 1.0);
source.set_fill_style("#0000ff");
source.fill_rect(1.0, 0.0, 1.0, 1.0);

let mut canvas = Canvas2D::new(8, 4);
canvas.set_image_smoothing_enabled(false);
canvas.draw_image_scaled(&source, 0.0, 0.0, 8.0, 4.0);
assert_eq!(canvas.get_image_data(1, 1, 1, 1).data, vec![255, 0, 0, 255]);
assert_eq!(canvas.get_image_data(6, 1, 1, 1).data, vec![0, 0, 255, 255]);
```

## Canvas2D (struct)

2D 그리기 대상. (원본 캔버스와 그 2D 컨텍스트)

예제: 빨간 사각형을 칠하고, 상태를 쌓아 옮긴 자리에 반투명 파랑을 칠하기

```rust
use vanilla::Canvas2D;

let mut canvas = Canvas2D::new(20, 10);
canvas.set_fill_style("#ff0000");
canvas.fill_rect(0.0, 0.0, 10.0, 10.0);
assert_eq!(canvas.get_image_data(5, 5, 1, 1).data, vec![255, 0, 0, 255]);

canvas.save();
canvas.translate(10.0, 0.0);
canvas.set_global_alpha(0.5);
canvas.set_fill_style("#0000ff");
canvas.fill_rect(0.0, 0.0, 10.0, 10.0);
canvas.restore();
assert_eq!(canvas.get_global_alpha(), 1.0);
assert_eq!(canvas.get_image_data(15, 5, 1, 1).data, vec![0, 0, 255, 128]);
```

- `pub fn new(width: u32, height: u32) -> Canvas2D` (constructor, since 0.4.0): 만들기. (원본 document.createElement("canvas") 에 width, height 를 준 것, 투명한 검정)
  - `width` u32: 폭. (픽셀)
  - `height` u32: 높이. (픽셀)
  - returns Canvas2D: 투명한 검정으로 채운 새 캔버스.
- `pub fn get_width(&self) -> u32` (method, since 0.4.0): 폭.
  - returns u32: 폭. (픽셀)
- `pub fn get_height(&self) -> u32` (method, since 0.4.0): 높이.
  - returns u32: 높이. (픽셀)
- `pub fn set_width(&mut self, width: u32)` (method, since 0.4.0): 폭 설정. (원본처럼 그림을 비우고 상태를 처음으로 돌린다, 같은 값이어도)
  - `width` u32: 새 폭. (픽셀)
- `pub fn set_height(&mut self, height: u32)` (method, since 0.4.0): 높이 설정. (원본처럼 그림을 비우고 상태를 처음으로 돌린다, 같은 값이어도)
  - `height` u32: 새 높이. (픽셀)
- `pub fn reset(&mut self)` (method, since 0.4.0): 처음으로 돌리기. (원본 reset: 그림을 비우고 상태와 경로를 처음으로)
- `pub fn save(&mut self)` (method, since 0.4.0): 상태 쌓기. (원본 save)
- `pub fn restore(&mut self)` (method, since 0.4.0): 상태 꺼내기. (원본 restore, 쌓은 것이 없으면 아무것도 하지 않는다)
- `pub fn scale(&mut self, x: f64, y: f64)` (method, since 0.4.0): 늘이기. (원본 scale)
  - `x` f64: 가로 배율.
  - `y` f64: 세로 배율.
- `pub fn rotate(&mut self, angle: f64)` (method, since 0.4.0): 돌리기. (원본 rotate, 라디안. 양수는 화면에서 시계 방향)
  - `angle` f64: 돌릴 각. (라디안, 화면에서 시계 방향이 +)
- `pub fn translate(&mut self, x: f64, y: f64)` (method, since 0.4.0): 옮기기. (원본 translate)
  - `x` f64: 가로 이동. (지금 좌표계 단위, 픽셀)
  - `y` f64: 세로 이동. (지금 좌표계 단위, 픽셀)
- `pub fn transform(&mut self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64)` (method, since 0.4.0): 변환 곱하기. (원본 transform, 유한하지 않은 값이면 무시)
  - `a` f64: 가로 배율. (x 에 곱해 새 x 에 더한다)
  - `b` f64: 세로 기울임. (x 에 곱해 새 y 에 더한다)
  - `c` f64: 가로 기울임. (y 에 곱해 새 x 에 더한다)
  - `d` f64: 세로 배율. (y 에 곱해 새 y 에 더한다)
  - `e` f64: 가로 이동. (지금 좌표계 단위, 픽셀)
  - `f` f64: 세로 이동. (지금 좌표계 단위, 픽셀)
- `pub fn set_transform(&mut self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64)` (method, since 0.4.0): 변환 바꾸기. (원본 setTransform(a, b, c, d, e, f))
  - `a` f64: 가로 배율. (x 에 곱해 새 x 에 더한다)
  - `b` f64: 세로 기울임. (x 에 곱해 새 y 에 더한다)
  - `c` f64: 가로 기울임. (y 에 곱해 새 x 에 더한다)
  - `d` f64: 세로 배율. (y 에 곱해 새 y 에 더한다)
  - `e` f64: 가로 이동. (픽셀)
  - `f` f64: 세로 이동. (픽셀)
- `pub fn set_transform_matrix(&mut self, matrix: CanvasMatrix)` (method, since 0.4.0): 변환 바꾸기. (원본 setTransform(DOMMatrix))
  - `matrix` CanvasMatrix: 새 변환. (유한하지 않은 값이 있으면 무시)
- `pub fn reset_transform(&mut self)` (method, since 0.4.0): 변환 지우기. (원본 resetTransform)
- `pub fn get_transform(&self) -> CanvasMatrix` (method, since 0.4.0): 지금 변환. (원본 getTransform)
  - returns CanvasMatrix: 지금 변환 행렬. (처음 단위 행렬)
- `pub fn set_global_alpha(&mut self, global_alpha: f64)` (method, since 0.4.0): 전체 투명도 설정. (원본 globalAlpha, 0 ~ 1 밖이나 유한하지 않으면 무시)
  - `global_alpha` f64: 전체 투명도. (0 이 투명, 1 이 불투명, 처음 1)
- `pub fn get_global_alpha(&self) -> f64` (method, since 0.4.0): 전체 투명도.
  - returns f64: 전체 투명도. (0 ~ 1, 처음 1)
- `pub fn set_global_composite_operation(&mut self, operation_name: &str)` (method, since 0.4.0): 합치기 설정. (원본 globalCompositeOperation, 모르는 이름은 무시)
  - `operation_name` &str: 원본 globalCompositeOperation 이름. ("multiply" 처럼 소문자와 하이픈, 대소문자를 가린다)
- `pub fn get_global_composite_operation(&self) -> String` (method, since 0.4.0): 합치기.
  - returns String: 원본 globalCompositeOperation 이름. (처음 "source-over")
- `pub fn set_image_smoothing_enabled(&mut self, is_enabled: bool)` (method, since 0.4.0): 그림 매끄럽게 설정. (원본 imageSmoothingEnabled, 끄면 가장 가까운 픽셀)
  - `is_enabled` bool: true 면 매끄럽게, false 면 가장 가까운 픽셀로 그린다. (처음 true)
- `pub fn is_image_smoothing_enabled(&self) -> bool` (method, since 0.4.0): 그림 매끄럽게 하는지.
  - returns bool: 매끄럽게 그리면 true. (처음 true)
- `pub fn set_fill_style(&mut self, style: impl Into<CanvasStyle>)` (method, since 0.4.0): 채울 것 설정. (원본 fillStyle)
  - `style` impl Into<CanvasStyle>: 채울 것. (Color, "#rrggbb" 같은 CSS 색 글, CanvasGradient, CanvasPattern, 처음 검정)
- `pub fn get_fill_style(&self) -> &CanvasStyle` (method, since 0.4.0): 채울 것.
  - returns &CanvasStyle: 채울 것. (처음 검정)
- `pub fn set_stroke_style(&mut self, style: impl Into<CanvasStyle>)` (method, since 0.4.0): 그을 것 설정. (원본 strokeStyle)
  - `style` impl Into<CanvasStyle>: 그을 것. (Color, "#rrggbb" 같은 CSS 색 글, CanvasGradient, CanvasPattern, 처음 검정)
- `pub fn get_stroke_style(&self) -> &CanvasStyle` (method, since 0.4.0): 그을 것.
  - returns &CanvasStyle: 그을 것. (처음 검정)
- `pub fn create_linear_gradient(&self, start_x: f64, start_y: f64, end_x: f64, end_y: f64) -> CanvasGradient` (method, since 0.4.0): 곧은 그라데이션. (원본 createLinearGradient)
  - `start_x` f64: 시작 점 x.
  - `start_y` f64: 시작 점 y.
  - `end_x` f64: 끝 점 x.
  - `end_y` f64: 끝 점 y.
  - returns CanvasGradient: 색 멈춤이 없는 곧은 그라데이션. (좌표는 칠할 때의 변환을 따른다)
- `pub fn create_radial_gradient(&self, start_x: f64, start_y: f64, start_radius: f64, end_x: f64, end_y: f64, end_radius: f64) -> Option<CanvasGradient>` (method, since 0.4.0): 둥근 그라데이션. (원본 createRadialGradient, 반지름이 음수면 원본의 예외처럼 None)
  - `start_x` f64: 시작 원 가운데 x.
  - `start_y` f64: 시작 원 가운데 y.
  - `start_radius` f64: 시작 원 반지름. (음수면 None)
  - `end_x` f64: 끝 원 가운데 x.
  - `end_y` f64: 끝 원 가운데 y.
  - `end_radius` f64: 끝 원 반지름. (음수면 None)
  - returns Option<CanvasGradient>: 색 멈춤이 없는 둥근 그라데이션. 반지름이 음수면 None.
- `pub fn create_conic_gradient(&self, start_angle: f64, center_x: f64, center_y: f64) -> CanvasGradient` (method, since 0.4.0): 원뿔 그라데이션. (원본 createConicGradient, 시작 각은 오른쪽에서 시계 방향 라디안)
  - `start_angle` f64: 시작 각. (라디안, 0 이 오른쪽, 화면에서 시계 방향이 +)
  - `center_x` f64: 가운데 x.
  - `center_y` f64: 가운데 y.
  - returns CanvasGradient: 색 멈춤이 없는 원뿔 그라데이션.
- `pub fn create_pattern<'a>(&self, source: impl Into<CanvasImageSource<'a>>, repetition: CanvasPatternRepetition) -> Option<CanvasPattern>` (method, since 0.4.0): 패턴. (원본 createPattern, 그림 픽셀을 읽지 못하거나 크기가 0 이면 None)
  - `source` impl Into<CanvasImageSource<'a>>: 패턴 그림. (엔진 Image, `Rc<Image>`, 다른 Canvas2D, 지금 픽셀을 떠 둔다)
  - `repetition` CanvasPatternRepetition: 되풀이.
  - returns Option<CanvasPattern>: 패턴. 그림 폭이나 높이가 0 이거나 픽셀을 읽지 못하면 None.
- `pub fn set_shadow_color(&mut self, color: impl Into<Color>)` (method, since 0.4.0): 그림자 색 설정. (원본 shadowColor)
  - `color` impl Into<Color>: 그림자 색. (Color 나 CSS 색 글, 처음 투명한 검정이라 그림자가 없다)
- `pub fn get_shadow_color(&self) -> Color` (method, since 0.4.0): 그림자 색.
  - returns Color: 그림자 색. (처음 투명한 검정)
- `pub fn set_shadow_blur(&mut self, shadow_blur: f64)` (method, since 0.4.0): 그림자 흐림 설정. (원본 shadowBlur, 음수나 유한하지 않으면 무시)
  - `shadow_blur` f64: 흐림 정도. (0 이 흐리지 않음, 처음 0)
- `pub fn get_shadow_blur(&self) -> f64` (method, since 0.4.0): 그림자 흐림.
  - returns f64: 그림자 흐림. (처음 0)
- `pub fn set_shadow_offset_x(&mut self, offset_x: f64)` (method, since 0.4.0): 그림자 가로 밀림 설정. (원본 shadowOffsetX, 변환을 받지 않는다)
  - `offset_x` f64: 가로 밀림. (캔버스 픽셀, 유한하지 않으면 무시, 처음 0)
- `pub fn get_shadow_offset_x(&self) -> f64` (method, since 0.4.0): 그림자 가로 밀림.
  - returns f64: 그림자 가로 밀림. (처음 0)
- `pub fn set_shadow_offset_y(&mut self, offset_y: f64)` (method, since 0.4.0): 그림자 세로 밀림 설정. (원본 shadowOffsetY, 변환을 받지 않는다)
  - `offset_y` f64: 세로 밀림. (캔버스 픽셀, 유한하지 않으면 무시, 처음 0)
- `pub fn get_shadow_offset_y(&self) -> f64` (method, since 0.4.0): 그림자 세로 밀림.
  - returns f64: 그림자 세로 밀림. (처음 0)
- `pub fn set_line_width(&mut self, line_width: f64)` (method, since 0.4.0): 선 굵기 설정. (원본 lineWidth, 0 이하나 유한하지 않으면 무시)
  - `line_width` f64: 선 굵기. (처음 1)
- `pub fn get_line_width(&self) -> f64` (method, since 0.4.0): 선 굵기.
  - returns f64: 선 굵기. (처음 1)
- `pub fn set_line_cap(&mut self, line_cap: CanvasLineCap)` (method, since 0.4.0): 선 끝 설정. (원본 lineCap)
  - `line_cap` CanvasLineCap: 선 끝. (처음 Butt)
- `pub fn get_line_cap(&self) -> CanvasLineCap` (method, since 0.4.0): 선 끝.
  - returns CanvasLineCap: 선 끝. (처음 Butt)
- `pub fn set_line_join(&mut self, line_join: CanvasLineJoin)` (method, since 0.4.0): 선 이음 설정. (원본 lineJoin)
  - `line_join` CanvasLineJoin: 선 이음. (처음 Miter)
- `pub fn get_line_join(&self) -> CanvasLineJoin` (method, since 0.4.0): 선 이음.
  - returns CanvasLineJoin: 선 이음. (처음 Miter)
- `pub fn set_miter_limit(&mut self, miter_limit: f64)` (method, since 0.4.0): 뾰족 이음 한계 설정. (원본 miterLimit, 0 이하나 유한하지 않으면 무시)
  - `miter_limit` f64: 뾰족 이음 한계. (이음 길이와 선 굵기의 비, 처음 10)
- `pub fn get_miter_limit(&self) -> f64` (method, since 0.4.0): 뾰족 이음 한계.
  - returns f64: 뾰족 이음 한계. (처음 10)
- `pub fn set_line_dash(&mut self, dash_list: &[f64])` (method, since 0.4.0): 점선 설정. (원본 setLineDash, 음수나 유한하지 않은 값이 있으면 무시, 홀수 개면 두 번 잇는다)
  - `dash_list` &[f64]: 그을 길이와 빈 길이를 번갈아 둔 목록. (빈 목록이면 곧은 선)
- `pub fn get_line_dash(&self) -> Vec<f64>` (method, since 0.4.0): 점선. (원본 getLineDash)
  - returns Vec<f64>: 점선 목록. (홀수 개로 넣었으면 두 번 이은 것, 처음 빈 목록)
- `pub fn set_line_dash_offset(&mut self, line_dash_offset: f64)` (method, since 0.4.0): 점선 시작 밀림 설정. (원본 lineDashOffset)
  - `line_dash_offset` f64: 점선을 시작할 자리. (유한하지 않으면 무시, 처음 0)
- `pub fn get_line_dash_offset(&self) -> f64` (method, since 0.4.0): 점선 시작 밀림.
  - returns f64: 점선 시작 밀림. (처음 0)
- `pub fn set_font(&mut self, font: &str)` (method, since 0.4.0): 글꼴 설정. (원본 font, CSS font 줄임 꼴. 크롬처럼 틀린 글은 무시하고, 엔진 글자 캐시가 읽는다)
  - 크기는 이때 픽셀로 센다. 상대 크기(em, %, larger 같은)는 문서에 붙이지 않은 캔버스처럼 10px sans-serif 에 댄다.
  - CSS 전역 낱말(inherit 같은), 줄높이만 있는 글, 크기나 이름이 없는 글은 틀린 글이다. 시스템 글꼴 낱말(caption 같은)은 받는다.
  - `font` &str: 글꼴. (CSS font 줄임 꼴, "bold 16px sans-serif" 같은 것, 처음 "10px sans-serif")

  예제: 받은 글꼴은 크롬이 직렬화한 꼴로 읽히고, 틀린 글은 앞 값을 남긴다

  ```rust
  use vanilla::Canvas2D;
  
  let mut canvas = Canvas2D::new(8, 8);
  canvas.set_font("BOLD 12pt 'Noto Sans', SANS-SERIF");
  assert_eq!(canvas.get_font(), "bold 16px \"Noto Sans\", sans-serif");
  canvas.set_font("italic 2em/1.5 serif");
  assert_eq!(canvas.get_font(), "italic 20px serif");
  canvas.set_font("inherit");
  assert_eq!(canvas.get_font(), "italic 20px serif");
  ```

- `pub fn get_font(&self) -> String` (method, since 0.4.0): 글꼴.
  - returns String: 글꼴. (크롬 font 게터의 직렬화: "italic ", "bold " 나 굵기 수, "small-caps ", 크기 px, 이름 목록. 처음 "10px sans-serif")
- `pub fn set_text_align(&mut self, text_align: CanvasTextAlign)` (method, since 0.4.0): 글 가로 정렬 설정. (원본 textAlign)
  - `text_align` CanvasTextAlign: 글 가로 정렬. (처음 Start)
- `pub fn get_text_align(&self) -> CanvasTextAlign` (method, since 0.4.0): 글 가로 정렬.
  - returns CanvasTextAlign: 글 가로 정렬. (처음 Start)
- `pub fn set_text_baseline(&mut self, text_baseline: CanvasTextBaseline)` (method, since 0.4.0): 글 기준선 설정. (원본 textBaseline)
  - `text_baseline` CanvasTextBaseline: 글 기준선. (처음 Alphabetic)
- `pub fn get_text_baseline(&self) -> CanvasTextBaseline` (method, since 0.4.0): 글 기준선.
  - returns CanvasTextBaseline: 글 기준선. (처음 Alphabetic)
- `pub fn clear_rect(&mut self, x: f64, y: f64, width: f64, height: f64)` (method, since 0.4.0): 사각형 지우기. (원본 clearRect: 그 자리를 투명한 검정으로, 자르기는 따르고 그림자, 투명도, 합치기는 받지 않는다)
  - `x` f64: 왼쪽 위 x.
  - `y` f64: 왼쪽 위 y.
  - `width` f64: 폭. (음수면 x 에서 왼쪽으로)
  - `height` f64: 높이. (음수면 y 에서 위로)
- `pub fn fill_rect(&mut self, x: f64, y: f64, width: f64, height: f64)` (method, since 0.4.0): 사각형 채우기. (원본 fillRect, 지금 경로를 바꾸지 않는다)
  - `x` f64: 왼쪽 위 x.
  - `y` f64: 왼쪽 위 y.
  - `width` f64: 폭. (음수면 x 에서 왼쪽으로)
  - `height` f64: 높이. (음수면 y 에서 위로)
- `pub fn stroke_rect(&mut self, x: f64, y: f64, width: f64, height: f64)` (method, since 0.4.0): 사각형 긋기. (원본 strokeRect)
  - `x` f64: 왼쪽 위 x.
  - `y` f64: 왼쪽 위 y.
  - `width` f64: 폭. (음수면 x 에서 왼쪽으로)
  - `height` f64: 높이. (음수면 y 에서 위로)
- `pub fn begin_path(&mut self)` (method, since 0.4.0): 경로 비우기. (원본 beginPath)
- `pub fn close_path(&mut self)` (method, since 0.4.0): 조각 닫기. (원본 closePath)
- `pub fn move_to(&mut self, x: f64, y: f64)` (method, since 0.4.0): 새 조각. (원본 moveTo)
  - `x` f64: 새 조각의 시작 점 x.
  - `y` f64: 새 조각의 시작 점 y.
- `pub fn line_to(&mut self, x: f64, y: f64)` (method, since 0.4.0): 곧은 선. (원본 lineTo, 조각이 없으면 그 점에서 조각을 시작한다)
  - `x` f64: 끝 점 x.
  - `y` f64: 끝 점 y.
- `pub fn quadratic_curve_to(&mut self, control_x: f64, control_y: f64, x: f64, y: f64)` (method, since 0.4.0): 2 차 곡선. (원본 quadraticCurveTo)
  - `control_x` f64: 조정점 x.
  - `control_y` f64: 조정점 y.
  - `x` f64: 끝 점 x.
  - `y` f64: 끝 점 y.
- `pub fn bezier_curve_to(&mut self, first_control_x: f64, first_control_y: f64, second_control_x: f64, second_control_y: f64, x: f64, y: f64)` (method, since 0.4.0): 3 차 곡선. (원본 bezierCurveTo)
  - `first_control_x` f64: 첫 조정점 x.
  - `first_control_y` f64: 첫 조정점 y.
  - `second_control_x` f64: 둘째 조정점 x.
  - `second_control_y` f64: 둘째 조정점 y.
  - `x` f64: 끝 점 x.
  - `y` f64: 끝 점 y.
- `pub fn arc(&mut self, x: f64, y: f64, radius: f64, start_angle: f64, end_angle: f64, is_counterclockwise: bool) -> bool` (method, since 0.4.0): 원호. (원본 arc, 반지름이 음수면 원본의 예외처럼 아무것도 하지 않고 false)
  - `x` f64: 가운데 x.
  - `y` f64: 가운데 y.
  - `radius` f64: 반지름. (음수면 false)
  - `start_angle` f64: 시작 각. (라디안, 0 이 오른쪽, 화면에서 시계 방향이 +)
  - `end_angle` f64: 끝 각. (라디안)
  - `is_counterclockwise` bool: true 면 반시계 방향으로 돈다.
  - returns bool: 반지름이 음수면 false(원본의 예외 자리), 그 밖에는 true. (유한하지 않은 값이 있으면 원본처럼 아무것도 더하지 않고 true)
- `pub fn arc_to(&mut self, first_x: f64, first_y: f64, second_x: f64, second_y: f64, radius: f64) -> bool` (method, since 0.4.0): 두 접선 사이 원호. (원본 arcTo, 반지름이 음수면 false)
  - `first_x` f64: 두 접선이 만나는 점 x. (지금 점에서 이 점까지가 첫 접선)
  - `first_y` f64: 두 접선이 만나는 점 y.
  - `second_x` f64: 둘째 접선이 지나는 점 x. (만나는 점에서 이 점까지가 둘째 접선)
  - `second_y` f64: 둘째 접선이 지나는 점 y.
  - `radius` f64: 반지름. (음수면 false)
  - returns bool: 반지름이 음수면 false(원본의 예외 자리), 그 밖에는 true. (유한하지 않은 값이 있으면 원본처럼 아무것도 더하지 않고 true)
- `pub fn ellipse(&mut self, x: f64, y: f64, radius_x: f64, radius_y: f64, rotation: f64, start_angle: f64, end_angle: f64, is_counterclockwise: bool) -> bool` (method, since 0.4.0): 타원호. (원본 ellipse, 반지름이 음수면 false)
  - `x` f64: 가운데 x.
  - `y` f64: 가운데 y.
  - `radius_x` f64: 가로 반지름. (돌리기 전, 음수면 false)
  - `radius_y` f64: 세로 반지름. (돌리기 전, 음수면 false)
  - `rotation` f64: 타원을 돌리는 각. (라디안, 화면에서 시계 방향이 +)
  - `start_angle` f64: 시작 각. (라디안, 타원 좌표계에서 0 이 오른쪽)
  - `end_angle` f64: 끝 각. (라디안)
  - `is_counterclockwise` bool: true 면 반시계 방향으로 돈다.
  - returns bool: 반지름이 음수면 false(원본의 예외 자리), 그 밖에는 true. (유한하지 않은 값이 있으면 원본처럼 아무것도 더하지 않고 true)
- `pub fn rect(&mut self, x: f64, y: f64, width: f64, height: f64)` (method, since 0.4.0): 사각형 조각. (원본 rect, 닫힌 조각을 더하고 (x, y) 에서 새 조각)
  - `x` f64: 왼쪽 위 x.
  - `y` f64: 왼쪽 위 y.
  - `width` f64: 폭. (음수면 x 에서 왼쪽으로)
  - `height` f64: 높이. (음수면 y 에서 위로)
- `pub fn round_rect<R: Into<CanvasRadius> + Copy>(&mut self, x: f32, y: f32, width: f32, height: f32, radius_list: &[R]) -> bool` (method, since 0.4.0): 둥근 사각형 조각. (원본 roundRect, 반지름은 수(f32)나 타원 모서리((x, y), CanvasRadius::Elliptical))
  - `x` f32: 왼쪽 위 x.
  - `y` f32: 왼쪽 위 y.
  - `width` f32: 폭. (음수면 x 에서 왼쪽으로)
  - `height` f32: 높이. (음수면 y 에서 위로)
  - `radius_list` &[R]: 모서리 반지름 1 ~ 4 개. (원본처럼 1 개는 네 모서리, 2 개는 왼위와 오른아래 / 오른위와 왼아래, 3 개는 왼위 / 오른위와 왼아래 / 오른아래, 4 개는 왼위, 오른위, 오른아래, 왼아래)
  - returns bool: 반지름이 1 ~ 4 개가 아니거나 음수 반지름이 있으면 false(원본의 예외 자리), 그 밖에는 true.
- `pub fn fill(&mut self, fill_rule: CanvasFillRule)` (method, since 0.4.0): 지금 경로 채우기. (원본 fill(fillRule))
  - `fill_rule` CanvasFillRule: 채우기 규칙.
- `pub fn fill_path(&mut self, path: &Path2D, fill_rule: CanvasFillRule)` (method, since 0.4.0): 경로 채우기. (원본 fill(path, fillRule), 경로는 지금 변환으로 옮겨 칠한다)
  - `path` &Path2D: 채울 경로.
  - `fill_rule` CanvasFillRule: 채우기 규칙.
- `pub fn stroke(&mut self)` (method, since 0.4.0): 지금 경로 긋기. (원본 stroke(), 선 굵기는 지금 변환을 받는다)
- `pub fn stroke_path(&mut self, path: &Path2D)` (method, since 0.4.0): 경로 긋기. (원본 stroke(path))
  - `path` &Path2D: 그을 경로. (지금 변환으로 옮겨 긋는다)
- `pub fn clip(&mut self, fill_rule: CanvasFillRule)` (method, since 0.4.0): 지금 경로로 자르기. (원본 clip(fillRule), 이미 자른 영역과 겹친 곳만 남는다)
  - `fill_rule` CanvasFillRule: 채우기 규칙.
- `pub fn clip_path(&mut self, path: &Path2D, fill_rule: CanvasFillRule)` (method, since 0.4.0): 경로로 자르기. (원본 clip(path, fillRule))
  - `path` &Path2D: 자를 경로. (지금 변환으로 옮겨 자른다)
  - `fill_rule` CanvasFillRule: 채우기 규칙.
- `pub fn is_point_in_path(&self, x: f64, y: f64, fill_rule: CanvasFillRule) -> bool` (method, since 0.4.0): 점이 지금 경로 안에 있는지. (원본 isPointInPath(x, y, fillRule), 점은 변환을 받지 않는 캔버스 좌표)
  - `x` f64: 점 x. (변환을 받지 않는 캔버스 좌표)
  - `y` f64: 점 y. (변환을 받지 않는 캔버스 좌표)
  - `fill_rule` CanvasFillRule: 채우기 규칙.
  - returns bool: 점이 안에 있으면 true.
- `pub fn is_point_in_path2d(&self, path: &Path2D, x: f64, y: f64, fill_rule: CanvasFillRule) -> bool` (method, since 0.4.0): 점이 경로 안에 있는지. (원본 isPointInPath(path, x, y, fillRule), 경로는 지금 변환으로 옮겨 본다)
  - `path` &Path2D: 볼 경로.
  - `x` f64: 점 x. (변환을 받지 않는 캔버스 좌표)
  - `y` f64: 점 y. (변환을 받지 않는 캔버스 좌표)
  - `fill_rule` CanvasFillRule: 채우기 규칙.
  - returns bool: 점이 안에 있으면 true.
- `pub fn measure_text(&self, text: &str) -> TextMetrics` (method, since 0.4.0): 글 재기. (원본 measureText, 엔진 글자 캐시로 잰다. 글꼴이 하나도 없으면 0)
  - `text` &str: 잴 글.
  - returns TextMetrics: 잰 값. (폭, 글꼴의 위아래 높이, 실제로 칠하는 상자)
- `pub fn fill_text(&mut self, text: &str, x: f64, y: f64, maximum_width: Option<f64>)` (method, since 0.4.0): 글 채우기. (원본 fillText(text, x, y, maxWidth), 글이 maxWidth 보다 넓으면 가로로 좁힌다)
  - `text` &str: 칠할 글.
  - `x` f64: 기준 점 x. (글 가로 정렬이 정하는 자리)
  - `y` f64: 기준 점 y. (글 기준선이 정하는 자리)
  - `maximum_width` Option<f64>: 가장 넓은 폭. (None 이면 좁히지 않는다)
- `pub fn stroke_text(&mut self, text: &str, x: f64, y: f64, maximum_width: Option<f64>)` (method, since 0.4.0): 글 긋기. (원본 strokeText, 선은 lineWidth 굵기로 윤곽선 가운데에 긋는다)
  - `text` &str: 그을 글.
  - `x` f64: 기준 점 x. (글 가로 정렬이 정하는 자리)
  - `y` f64: 기준 점 y. (글 기준선이 정하는 자리)
  - `maximum_width` Option<f64>: 가장 넓은 폭. (None 이면 좁히지 않는다)
- `pub fn draw_image<'a>(&mut self, source: impl Into<CanvasImageSource<'a>>, destination_x: f64, destination_y: f64)` (method, since 0.4.0): 그림 그리기. (원본 drawImage(image, dx, dy))
  - `source` impl Into<CanvasImageSource<'a>>: 그릴 그림. (엔진 Image, `Rc<Image>`, 다른 Canvas2D)
  - `destination_x` f64: 그릴 자리 왼쪽 x.
  - `destination_y` f64: 그릴 자리 위 y.
- `pub fn draw_image_scaled<'a>(&mut self, source: impl Into<CanvasImageSource<'a>>, destination_x: f64, destination_y: f64, destination_width: f64, destination_height: f64)` (method, since 0.4.0): 그림 늘여 그리기. (원본 drawImage(image, dx, dy, dw, dh))
  - `source` impl Into<CanvasImageSource<'a>>: 그릴 그림. (엔진 Image, `Rc<Image>`, 다른 Canvas2D)
  - `destination_x` f64: 그릴 자리 왼쪽 x.
  - `destination_y` f64: 그릴 자리 위 y.
  - `destination_width` f64: 그릴 폭. (음수면 destination_x 에서 왼쪽으로)
  - `destination_height` f64: 그릴 높이. (음수면 destination_y 에서 위로)
- `pub fn draw_image_region<'a>(&mut self, source: impl Into<CanvasImageSource<'a>>, source_x: f64, source_y: f64, source_width: f64, source_height: f64, destination_x: f64, destination_y: f64, destination_width: f64, destination_height: f64)` (method, since 0.4.0): 그림 일부 그리기. (원본 drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh), 음수 폭과 높이는 원본처럼 뒤집어 맞춘다)
  - `source` impl Into<CanvasImageSource<'a>>: 그릴 그림. (엔진 Image, `Rc<Image>`, 다른 Canvas2D)
  - `source_x` f64: 떼어 올 영역 왼쪽. (그림 픽셀)
  - `source_y` f64: 떼어 올 영역 위. (그림 픽셀)
  - `source_width` f64: 떼어 올 영역 폭. (그림 픽셀, 음수면 source_x 에서 왼쪽으로)
  - `source_height` f64: 떼어 올 영역 높이. (그림 픽셀, 음수면 source_y 에서 위로)
  - `destination_x` f64: 그릴 자리 왼쪽 x.
  - `destination_y` f64: 그릴 자리 위 y.
  - `destination_width` f64: 그릴 폭. (음수면 destination_x 에서 왼쪽으로)
  - `destination_height` f64: 그릴 높이. (음수면 destination_y 에서 위로)
- `pub fn create_image_data(&self, width: u32, height: u32) -> ImageData` (method, since 0.4.0): 빈 픽셀 묶음. (원본 createImageData)
  - `width` u32: 폭. (픽셀)
  - `height` u32: 높이. (픽셀)
  - returns ImageData: 모든 바이트가 0 인 픽셀 묶음.
- `pub fn get_image_data(&self, source_x: i32, source_y: i32, width: u32, height: u32) -> ImageData` (method, since 0.4.0): 픽셀 읽기. (원본 getImageData, 프리멀티플라이하지 않은 RGBA. 캔버스 밖은 투명한 검정)
  - `source_x` i32: 읽을 영역 왼쪽. (캔버스 픽셀, 변환을 받지 않는다)
  - `source_y` i32: 읽을 영역 위. (캔버스 픽셀, 변환을 받지 않는다)
  - `width` u32: 읽을 폭. (픽셀)
  - `height` u32: 읽을 높이. (픽셀)
  - returns ImageData: 프리멀티플라이하지 않은 RGBA 픽셀 묶음. (캔버스 밖은 투명한 검정)
- `pub fn put_image_data(&mut self, image_data: &ImageData, destination_x: i32, destination_y: i32)` (method, since 0.4.0): 픽셀 쓰기. (원본 putImageData: 자르기, 투명도, 합치기, 그림자 없이 그대로 바꾼다)
  - 곧은 RGBA 를 크롬처럼 (색 x 알파 + 127) / 255 로 프리멀티플라이해 담는다.
  - 폭이나 높이가 0 이거나 i32 를 넘거나, data 가 폭 x 높이 x 4 바이트가 아니면 쓰지 않는다. (원본 new ImageData 가 받지 않는 픽셀 묶음)
  - `image_data` &ImageData: 쓸 픽셀 묶음. (프리멀티플라이하지 않은 RGBA)
  - `destination_x` i32: 쓸 자리 왼쪽. (캔버스 픽셀, 변환을 받지 않는다)
  - `destination_y` i32: 쓸 자리 위. (캔버스 픽셀, 변환을 받지 않는다)
- `pub fn put_image_data_region(&mut self, image_data: &ImageData, destination_x: i32, destination_y: i32, dirty_x: i32, dirty_y: i32, dirty_width: i32, dirty_height: i32)` (method, since 0.4.0): 픽셀 묶음의 한 사각형만 쓰기. (원본 putImageData 의 dirtyX, dirtyY, dirtyWidth, dirtyHeight 꼴, 크롬 base_rendering_context_2d.cc 의 셈)
  - 폭 x 높이가 i32 를 넘으면 쓰지 않는다. 음수 폭과 높이는 시작을 그만큼 옮겨 뒤집고(시작이 음수였으면 0), 픽셀 묶음과 캔버스 밖은 자른다.
  - `image_data` &ImageData: 쓸 픽셀 묶음. (프리멀티플라이하지 않은 RGBA)
  - `destination_x` i32: 픽셀 묶음 왼쪽이 놓일 자리. (캔버스 픽셀, 변환을 받지 않는다)
  - `destination_y` i32: 픽셀 묶음 위가 놓일 자리. (캔버스 픽셀, 변환을 받지 않는다)
  - `dirty_x` i32: 쓸 사각형 왼쪽. (픽셀 묶음 픽셀)
  - `dirty_y` i32: 쓸 사각형 위. (픽셀 묶음 픽셀)
  - `dirty_width` i32: 쓸 사각형 폭. (음수면 왼쪽으로)
  - `dirty_height` i32: 쓸 사각형 높이. (음수면 위로)

  예제: 2 x 2 픽셀 묶음의 오른쪽 아래 한 픽셀만 쓰기

  ```rust
  use vanilla::{Canvas2D, ImageData};
  
  let mut image_data = ImageData::new(2, 2);
  image_data.data.copy_from_slice(&[255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255]);
  
  let mut canvas = Canvas2D::new(4, 4);
  canvas.put_image_data_region(&image_data, 1, 1, 2, 2, -1, -1);
  assert_eq!(canvas.get_image_data(2, 2, 1, 1).data, vec![255, 255, 255, 255]);
  assert_eq!(canvas.get_image_data(1, 1, 1, 1).data, vec![0, 0, 0, 0]);
  ```

- `pub fn to_image(&self) -> Rc<Image>` (method, since 0.4.0): 엔진 그림으로. (Graphic, UIImageView 에 쓴다. 그 뒤로 그리지 않았으면 같은 Image)
  - returns Rc<Image>: 이 캔버스 픽셀의 엔진 그림. (그 뒤로 그리지 않았으면 같은 Rc)
