core/canvas2d/desktop_canvas
2D 그리기 대상의 데스크탑 판. (tiny-skia 로 칠한다, core/canvas2d.rs 머리 주석)
Desktop version of the 2D drawing target. (paints with tiny-skia, header comment of core/canvas2d.rs)
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]);Canvas2Dstruct
2D 그리기 대상. (원본 캔버스와 그 2D 컨텍스트)
2D drawing target. (the original canvas and its 2D context)
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]);만들기. (원본 document.createElement("canvas") 에 width, height 를 준 것, 투명한 검정)
Creates. (the original document.createElement("canvas") given width and height, transparent black)
- widthu32
- 폭. (픽셀)Width. (pixels)
- heightu32
- 높이. (픽셀)Height. (pixels)
반환ReturnsCanvas2D 투명한 검정으로 채운 새 캔버스.A new canvas filled with transparent black.
폭 설정. (원본처럼 그림을 비우고 상태를 처음으로 돌린다, 같은 값이어도)
Sets the width. (clears the drawing and resets the state like the original, even for the same value)
- widthu32
- 새 폭. (픽셀)New width. (pixels)
높이 설정. (원본처럼 그림을 비우고 상태를 처음으로 돌린다, 같은 값이어도)
Sets the height. (clears the drawing and resets the state like the original, even for the same value)
- heightu32
- 새 높이. (픽셀)New height. (pixels)
처음으로 돌리기. (원본 reset: 그림을 비우고 상태와 경로를 처음으로)
Resets. (the original reset: clears the drawing and resets the state and path)
상태 쌓기. (원본 save)
Pushes the state. (the original save)
상태 꺼내기. (원본 restore, 쌓은 것이 없으면 아무것도 하지 않는다)
Pops the state. (the original restore, does nothing if nothing is pushed)
늘이기. (원본 scale)
Scales. (the original scale)
- xf64
- 가로 배율.Horizontal scale.
- yf64
- 세로 배율.Vertical scale.
돌리기. (원본 rotate, 라디안. 양수는 화면에서 시계 방향)
Rotates. (the original rotate, radians. Positive is clockwise on screen)
- anglef64
- 돌릴 각. (라디안, 화면에서 시계 방향이 +)Angle to rotate. (radians, clockwise on screen is +)
옮기기. (원본 translate)
Translates. (the original translate)
- xf64
- 가로 이동. (지금 좌표계 단위, 픽셀)Horizontal translation. (in current coordinate system units, pixels)
- yf64
- 세로 이동. (지금 좌표계 단위, 픽셀)Vertical translation. (in current coordinate system units, pixels)
변환 곱하기. (원본 transform, 유한하지 않은 값이면 무시)
Multiplies the transform. (the original transform, ignored for non-finite values)
- af64
- 가로 배율. (x 에 곱해 새 x 에 더한다)Horizontal scale. (multiplied by x and added to the new x)
- bf64
- 세로 기울임. (x 에 곱해 새 y 에 더한다)Vertical skew. (multiplied by x and added to the new y)
- cf64
- 가로 기울임. (y 에 곱해 새 x 에 더한다)Horizontal skew. (multiplied by y and added to the new x)
- df64
- 세로 배율. (y 에 곱해 새 y 에 더한다)Vertical scale. (multiplied by y and added to the new y)
- ef64
- 가로 이동. (지금 좌표계 단위, 픽셀)Horizontal translation. (in current coordinate system units, pixels)
- ff64
- 세로 이동. (지금 좌표계 단위, 픽셀)Vertical translation. (in current coordinate system units, pixels)
변환 바꾸기. (원본 setTransform(a, b, c, d, e, f))
Replaces the transform. (the original setTransform(a, b, c, d, e, f))
- af64
- 가로 배율. (x 에 곱해 새 x 에 더한다)Horizontal scale. (multiplied by x and added to the new x)
- bf64
- 세로 기울임. (x 에 곱해 새 y 에 더한다)Vertical skew. (multiplied by x and added to the new y)
- cf64
- 가로 기울임. (y 에 곱해 새 x 에 더한다)Horizontal skew. (multiplied by y and added to the new x)
- df64
- 세로 배율. (y 에 곱해 새 y 에 더한다)Vertical scale. (multiplied by y and added to the new y)
- ef64
- 가로 이동. (픽셀)Horizontal translation. (pixels)
- ff64
- 세로 이동. (픽셀)Vertical translation. (pixels)
변환 바꾸기. (원본 setTransform(DOMMatrix))
Replaces the transform. (the original setTransform(DOMMatrix))
- matrixCanvasMatrix
- 새 변환. (유한하지 않은 값이 있으면 무시)New transform. (ignored if any value is non-finite)
변환 지우기. (원본 resetTransform)
Clears the transform. (the original resetTransform)
지금 변환. (원본 getTransform)
Current transform. (the original getTransform)
반환ReturnsCanvasMatrix 지금 변환 행렬. (처음 단위 행렬)Current transform matrix. (initially the identity matrix)
전체 투명도 설정. (원본 globalAlpha, 0 ~ 1 밖이나 유한하지 않으면 무시)
Sets the global alpha. (the original globalAlpha, ignored if outside 0 ~ 1 or non-finite)
- global_alphaf64
- 전체 투명도. (0 이 투명, 1 이 불투명, 처음 1)Global alpha. (0 is transparent, 1 is opaque, initially 1)
전체 투명도.
Global alpha.
반환Returnsf64 전체 투명도. (0 ~ 1, 처음 1)Global alpha. (0 ~ 1, initially 1)
합치기 설정. (원본 globalCompositeOperation, 모르는 이름은 무시)
Sets compositing. (the original globalCompositeOperation, unknown names are ignored)
- operation_name&str
- 원본 globalCompositeOperation 이름. ("multiply" 처럼 소문자와 하이픈, 대소문자를 가린다)The original globalCompositeOperation name. (lowercase and hyphens like "multiply", case-sensitive)
합치기.
Compositing.
반환ReturnsString 원본 globalCompositeOperation 이름. (처음 "source-over")Original globalCompositeOperation name. (initially "source-over")
그림 매끄럽게 설정. (원본 imageSmoothingEnabled, 끄면 가장 가까운 픽셀)
Sets image smoothing. (the original imageSmoothingEnabled, nearest pixel when off)
- is_enabledbool
- true 면 매끄럽게, false 면 가장 가까운 픽셀로 그린다. (처음 true)true to draw smoothly, false to draw with the nearest pixel. (initially true)
그림 매끄럽게 하는지.
Whether images are smoothed.
반환Returnsbool 매끄럽게 그리면 true. (처음 true)true if drawn smoothly. (initially true)
채울 것 설정. (원본 fillStyle)
Sets the fill paint. (the original fillStyle)
- styleimpl Into<CanvasStyle>
- 채울 것. (Color, "#rrggbb" 같은 CSS 색 글, CanvasGradient, CanvasPattern, 처음 검정)Fill paint. (Color, CSS color text like "#rrggbb", CanvasGradient, CanvasPattern, initially black)
채울 것.
Fill paint.
반환Returns&CanvasStyle 채울 것. (처음 검정)Fill paint. (initially black)
그을 것 설정. (원본 strokeStyle)
Sets the stroke paint. (the original strokeStyle)
- styleimpl Into<CanvasStyle>
- 그을 것. (Color, "#rrggbb" 같은 CSS 색 글, CanvasGradient, CanvasPattern, 처음 검정)Stroke paint. (Color, CSS color text like "#rrggbb", CanvasGradient, CanvasPattern, initially black)
그을 것.
Stroke paint.
반환Returns&CanvasStyle 그을 것. (처음 검정)Stroke paint. (initially black)
pub fn create_linear_gradient(&self, start_x: f64, start_y: f64, end_x: f64, end_y: f64) -> CanvasGradient#곧은 그라데이션. (원본 createLinearGradient)
Linear gradient. (the original createLinearGradient)
- start_xf64
- 시작 점 x.Start point x.
- start_yf64
- 시작 점 y.Start point y.
- end_xf64
- 끝 점 x.End point x.
- end_yf64
- 끝 점 y.End point y.
반환ReturnsCanvasGradient 색 멈춤이 없는 곧은 그라데이션. (좌표는 칠할 때의 변환을 따른다)A linear gradient with no color stops. (the coordinates follow the transform at paint time)
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>#둥근 그라데이션. (원본 createRadialGradient, 반지름이 음수면 원본의 예외처럼 None)
Radial gradient. (the original createRadialGradient, None if a radius is negative, like the original's exception)
- start_xf64
- 시작 원 가운데 x.Start circle center x.
- start_yf64
- 시작 원 가운데 y.Start circle center y.
- start_radiusf64
- 시작 원 반지름. (음수면 None)Start circle radius. (None if negative)
- end_xf64
- 끝 원 가운데 x.End circle center x.
- end_yf64
- 끝 원 가운데 y.End circle center y.
- end_radiusf64
- 끝 원 반지름. (음수면 None)End circle radius. (None if negative)
반환ReturnsOption<CanvasGradient> 색 멈춤이 없는 둥근 그라데이션. 반지름이 음수면 None.A radial gradient with no color stops. None if a radius is negative.
pub fn create_conic_gradient(&self, start_angle: f64, center_x: f64, center_y: f64) -> CanvasGradient#원뿔 그라데이션. (원본 createConicGradient, 시작 각은 오른쪽에서 시계 방향 라디안)
Conic gradient. (the original createConicGradient, the start angle is in radians clockwise from the right)
- start_anglef64
- 시작 각. (라디안, 0 이 오른쪽, 화면에서 시계 방향이 +)Start angle. (radians, 0 is to the right, clockwise on screen is +)
- center_xf64
- 가운데 x.Center x.
- center_yf64
- 가운데 y.Center y.
반환ReturnsCanvasGradient 색 멈춤이 없는 원뿔 그라데이션.A conic gradient with no color stops.
pub fn create_pattern<'a>(&self, source: impl Into<CanvasImageSource<'a>>, repetition: CanvasPatternRepetition) -> Option<CanvasPattern>#패턴. (원본 createPattern, 그림 픽셀을 읽지 못하거나 크기가 0 이면 None)
Pattern. (the original createPattern, None if the image pixels cannot be read or the size is 0)
- sourceimpl Into<CanvasImageSource<'a>>
- 패턴 그림. (엔진 Image,
Rc<Image>, 다른 Canvas2D, 지금 픽셀을 떠 둔다)Pattern image. (engine Image,Rc<Image>, another Canvas2D, its current pixels are copied) - repetitionCanvasPatternRepetition
- 되풀이.Repetition.
반환ReturnsOption<CanvasPattern> 패턴. 그림 폭이나 높이가 0 이거나 픽셀을 읽지 못하면 None.The pattern. None if the image width or height is 0 or its pixels cannot be read.
그림자 색 설정. (원본 shadowColor)
Sets the shadow color. (the original shadowColor)
- colorimpl Into<Color>
- 그림자 색. (Color 나 CSS 색 글, 처음 투명한 검정이라 그림자가 없다)Shadow color. (Color or CSS color text, initially transparent black so there is no shadow)
그림자 색.
Shadow color.
반환ReturnsColor 그림자 색. (처음 투명한 검정)Shadow color. (initially transparent black)
그림자 흐림 설정. (원본 shadowBlur, 음수나 유한하지 않으면 무시)
Sets the shadow blur. (the original shadowBlur, ignored if negative or non-finite)
- shadow_blurf64
- 흐림 정도. (0 이 흐리지 않음, 처음 0)Blur amount. (0 means no blur, initially 0)
그림자 흐림.
Shadow blur.
반환Returnsf64 그림자 흐림. (처음 0)Shadow blur. (initially 0)
그림자 가로 밀림 설정. (원본 shadowOffsetX, 변환을 받지 않는다)
Sets the shadow horizontal offset. (the original shadowOffsetX, not affected by the transform)
- offset_xf64
- 가로 밀림. (캔버스 픽셀, 유한하지 않으면 무시, 처음 0)Horizontal offset. (canvas pixels, ignored if non-finite, initially 0)
그림자 가로 밀림.
Shadow horizontal offset.
반환Returnsf64 그림자 가로 밀림. (처음 0)Shadow horizontal offset. (initially 0)
그림자 세로 밀림 설정. (원본 shadowOffsetY, 변환을 받지 않는다)
Sets the shadow vertical offset. (the original shadowOffsetY, not affected by the transform)
- offset_yf64
- 세로 밀림. (캔버스 픽셀, 유한하지 않으면 무시, 처음 0)Vertical offset. (canvas pixels, ignored if non-finite, initially 0)
그림자 세로 밀림.
Shadow vertical offset.
반환Returnsf64 그림자 세로 밀림. (처음 0)Shadow vertical offset. (initially 0)
선 굵기 설정. (원본 lineWidth, 0 이하나 유한하지 않으면 무시)
Sets the line width. (the original lineWidth, ignored if 0 or less or non-finite)
- line_widthf64
- 선 굵기. (처음 1)Line width. (initially 1)
선 굵기.
Line width.
반환Returnsf64 선 굵기. (처음 1)Line width. (initially 1)
선 끝 설정. (원본 lineCap)
Sets the line cap. (the original lineCap)
- line_capCanvasLineCap
- 선 끝. (처음 Butt)Line cap. (initially Butt)
선 끝.
Line cap.
반환ReturnsCanvasLineCap 선 끝. (처음 Butt)Line cap. (initially Butt)
선 이음 설정. (원본 lineJoin)
Sets the line join. (the original lineJoin)
- line_joinCanvasLineJoin
- 선 이음. (처음 Miter)Line join. (initially Miter)
선 이음.
Line join.
반환ReturnsCanvasLineJoin 선 이음. (처음 Miter)Line join. (initially Miter)
뾰족 이음 한계 설정. (원본 miterLimit, 0 이하나 유한하지 않으면 무시)
Sets the miter limit. (the original miterLimit, ignored if 0 or less or non-finite)
- miter_limitf64
- 뾰족 이음 한계. (이음 길이와 선 굵기의 비, 처음 10)Miter limit. (ratio of the miter length to the line width, initially 10)
뾰족 이음 한계.
Miter limit.
반환Returnsf64 뾰족 이음 한계. (처음 10)Miter limit. (initially 10)
점선 설정. (원본 setLineDash, 음수나 유한하지 않은 값이 있으면 무시, 홀수 개면 두 번 잇는다)
Sets the line dash. (the original setLineDash, ignored if any value is negative or non-finite, doubled if the count is odd)
- dash_list&[f64]
- 그을 길이와 빈 길이를 번갈아 둔 목록. (빈 목록이면 곧은 선)List alternating dash lengths and gap lengths. (a solid line if empty)
점선. (원본 getLineDash)
Line dash. (the original getLineDash)
반환ReturnsVec<f64> 점선 목록. (홀수 개로 넣었으면 두 번 이은 것, 처음 빈 목록)Dash list. (doubled if an odd count was given, initially empty)
점선 시작 밀림 설정. (원본 lineDashOffset)
Sets the line dash offset. (the original lineDashOffset)
- line_dash_offsetf64
- 점선을 시작할 자리. (유한하지 않으면 무시, 처음 0)Where the dashes start. (ignored if non-finite, initially 0)
점선 시작 밀림.
Line dash offset.
반환Returnsf64 점선 시작 밀림. (처음 0)Line dash offset. (initially 0)
글꼴 설정. (원본 font, CSS font 줄임 꼴. 크롬처럼 틀린 글은 무시하고, 엔진 글자 캐시가 읽는다)
- 크기는 이때 픽셀로 센다. 상대 크기(em, %, larger 같은)는 문서에 붙이지 않은 캔버스처럼 10px sans-serif 에 댄다.
- CSS 전역 낱말(inherit 같은), 줄높이만 있는 글, 크기나 이름이 없는 글은 틀린 글이다. 시스템 글꼴 낱말(caption 같은)은 받는다.
Sets the font. (the original font, CSS font shorthand. Invalid strings are ignored like Chrome; read by the engine glyph cache)
- The size is resolved to pixels at this point. Relative sizes (em, %, larger and the like) are relative to 10px sans-serif, like a canvas not attached to the document.
- CSS-wide keywords (inherit and the like), a line height alone, and strings without a size or a family are invalid. System font keywords (caption and the like) are accepted.
- font&str
- 글꼴. (CSS font 줄임 꼴, "bold 16px sans-serif" 같은 것, 처음 "10px sans-serif")Font. (CSS font shorthand like "bold 16px sans-serif", initially "10px sans-serif")
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");글꼴.
Font.
반환ReturnsString 글꼴. (크롬 font 게터의 직렬화: "italic ", "bold " 나 굵기 수, "small-caps ", 크기 px, 이름 목록. 처음 "10px sans-serif")Font. (serialized like Chrome's font getter: "italic ", "bold " or the weight number, "small-caps ", the size in px, the family list. Initially "10px sans-serif")
글 가로 정렬 설정. (원본 textAlign)
Sets the horizontal text alignment. (the original textAlign)
- text_alignCanvasTextAlign
- 글 가로 정렬. (처음 Start)Horizontal text alignment. (initially Start)
글 가로 정렬.
Horizontal text alignment.
반환ReturnsCanvasTextAlign 글 가로 정렬. (처음 Start)Horizontal text alignment. (initially Start)
글 기준선 설정. (원본 textBaseline)
Sets the text baseline. (the original textBaseline)
- text_baselineCanvasTextBaseline
- 글 기준선. (처음 Alphabetic)Text baseline. (initially Alphabetic)
글 기준선.
Text baseline.
반환ReturnsCanvasTextBaseline 글 기준선. (처음 Alphabetic)Text baseline. (initially Alphabetic)
사각형 지우기. (원본 clearRect: 그 자리를 투명한 검정으로, 자르기는 따르고 그림자, 투명도, 합치기는 받지 않는다)
Clears a rectangle. (the original clearRect: makes the area transparent black, follows the clip but ignores shadow, alpha and compositing)
- xf64
- 왼쪽 위 x.Top-left x.
- yf64
- 왼쪽 위 y.Top-left y.
- widthf64
- 폭. (음수면 x 에서 왼쪽으로)Width. (leftward from x if negative)
- heightf64
- 높이. (음수면 y 에서 위로)Height. (upward from y if negative)
사각형 채우기. (원본 fillRect, 지금 경로를 바꾸지 않는다)
Fills a rectangle. (the original fillRect, does not change the current path)
- xf64
- 왼쪽 위 x.Top-left x.
- yf64
- 왼쪽 위 y.Top-left y.
- widthf64
- 폭. (음수면 x 에서 왼쪽으로)Width. (leftward from x if negative)
- heightf64
- 높이. (음수면 y 에서 위로)Height. (upward from y if negative)
사각형 긋기. (원본 strokeRect)
Strokes a rectangle. (the original strokeRect)
- xf64
- 왼쪽 위 x.Top-left x.
- yf64
- 왼쪽 위 y.Top-left y.
- widthf64
- 폭. (음수면 x 에서 왼쪽으로)Width. (leftward from x if negative)
- heightf64
- 높이. (음수면 y 에서 위로)Height. (upward from y if negative)
경로 비우기. (원본 beginPath)
Clears the path. (the original beginPath)
조각 닫기. (원본 closePath)
Closes the subpath. (the original closePath)
새 조각. (원본 moveTo)
New subpath. (the original moveTo)
- xf64
- 새 조각의 시작 점 x.Start point x of the new subpath.
- yf64
- 새 조각의 시작 점 y.Start point y of the new subpath.
곧은 선. (원본 lineTo, 조각이 없으면 그 점에서 조각을 시작한다)
Straight line. (the original lineTo, starts a subpath at that point if there is none)
- xf64
- 끝 점 x.End point x.
- yf64
- 끝 점 y.End point y.
2 차 곡선. (원본 quadraticCurveTo)
Quadratic curve. (the original quadraticCurveTo)
- control_xf64
- 조정점 x.Control point x.
- control_yf64
- 조정점 y.Control point y.
- xf64
- 끝 점 x.End point x.
- yf64
- 끝 점 y.End point 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)#3 차 곡선. (원본 bezierCurveTo)
Cubic curve. (the original bezierCurveTo)
- first_control_xf64
- 첫 조정점 x.First control point x.
- first_control_yf64
- 첫 조정점 y.First control point y.
- second_control_xf64
- 둘째 조정점 x.Second control point x.
- second_control_yf64
- 둘째 조정점 y.Second control point y.
- xf64
- 끝 점 x.End point x.
- yf64
- 끝 점 y.End point y.
pub fn arc(&mut self, x: f64, y: f64, radius: f64, start_angle: f64, end_angle: f64, is_counterclockwise: bool) -> bool#원호. (원본 arc, 반지름이 음수면 원본의 예외처럼 아무것도 하지 않고 false)
Arc. (the original arc, does nothing and returns false if the radius is negative, like the original's exception)
- xf64
- 가운데 x.Center x.
- yf64
- 가운데 y.Center y.
- radiusf64
- 반지름. (음수면 false)Radius. (false if negative)
- start_anglef64
- 시작 각. (라디안, 0 이 오른쪽, 화면에서 시계 방향이 +)Start angle. (radians, 0 is to the right, clockwise on screen is +)
- end_anglef64
- 끝 각. (라디안)End angle. (radians)
- is_counterclockwisebool
- true 면 반시계 방향으로 돈다.true to go counterclockwise.
반환Returnsbool 반지름이 음수면 false(원본의 예외 자리), 그 밖에는 true. (유한하지 않은 값이 있으면 원본처럼 아무것도 더하지 않고 true)false if the radius is negative (where the original throws), otherwise true. (if any value is non-finite, adds nothing and returns true like the original)
pub fn arc_to(&mut self, first_x: f64, first_y: f64, second_x: f64, second_y: f64, radius: f64) -> bool#두 접선 사이 원호. (원본 arcTo, 반지름이 음수면 false)
Arc between two tangents. (the original arcTo, false if the radius is negative)
- first_xf64
- 두 접선이 만나는 점 x. (지금 점에서 이 점까지가 첫 접선)x of the point where the two tangents meet. (the first tangent runs from the current point to this point)
- first_yf64
- 두 접선이 만나는 점 y.y of the point where the two tangents meet.
- second_xf64
- 둘째 접선이 지나는 점 x. (만나는 점에서 이 점까지가 둘째 접선)x of a point the second tangent passes through. (the second tangent runs from the meeting point to this point)
- second_yf64
- 둘째 접선이 지나는 점 y.y of a point the second tangent passes through.
- radiusf64
- 반지름. (음수면 false)Radius. (false if negative)
반환Returnsbool 반지름이 음수면 false(원본의 예외 자리), 그 밖에는 true. (유한하지 않은 값이 있으면 원본처럼 아무것도 더하지 않고 true)false if the radius is negative (where the original throws), otherwise true. (if any value is non-finite, adds nothing and returns true like the original)
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#타원호. (원본 ellipse, 반지름이 음수면 false)
Elliptical arc. (the original ellipse, false if a radius is negative)
- xf64
- 가운데 x.Center x.
- yf64
- 가운데 y.Center y.
- radius_xf64
- 가로 반지름. (돌리기 전, 음수면 false)Horizontal radius. (before rotation, false if negative)
- radius_yf64
- 세로 반지름. (돌리기 전, 음수면 false)Vertical radius. (before rotation, false if negative)
- rotationf64
- 타원을 돌리는 각. (라디안, 화면에서 시계 방향이 +)Angle to rotate the ellipse. (radians, clockwise on screen is +)
- start_anglef64
- 시작 각. (라디안, 타원 좌표계에서 0 이 오른쪽)Start angle. (radians, 0 is to the right in the ellipse coordinate system)
- end_anglef64
- 끝 각. (라디안)End angle. (radians)
- is_counterclockwisebool
- true 면 반시계 방향으로 돈다.true to go counterclockwise.
반환Returnsbool 반지름이 음수면 false(원본의 예외 자리), 그 밖에는 true. (유한하지 않은 값이 있으면 원본처럼 아무것도 더하지 않고 true)false if the radius is negative (where the original throws), otherwise true. (if any value is non-finite, adds nothing and returns true like the original)
사각형 조각. (원본 rect, 닫힌 조각을 더하고 (x, y) 에서 새 조각)
Rectangle subpath. (the original rect, adds a closed subpath and starts a new subpath at (x, y))
- xf64
- 왼쪽 위 x.Top-left x.
- yf64
- 왼쪽 위 y.Top-left y.
- widthf64
- 폭. (음수면 x 에서 왼쪽으로)Width. (leftward from x if negative)
- heightf64
- 높이. (음수면 y 에서 위로)Height. (upward from y if negative)
pub fn round_rect<R: Into<CanvasRadius> + Copy>(&mut self, x: f32, y: f32, width: f32, height: f32, radius_list: &[R]) -> bool#둥근 사각형 조각. (원본 roundRect, 반지름은 수(f32)나 타원 모서리((x, y), CanvasRadius::Elliptical))
Rounded rectangle segment. (the original roundRect, radii are numbers (f32) or elliptical corners ((x, y), CanvasRadius::Elliptical))
- xf32
- 왼쪽 위 x.Top-left x.
- yf32
- 왼쪽 위 y.Top-left y.
- widthf32
- 폭. (음수면 x 에서 왼쪽으로)Width. (leftward from x if negative)
- heightf32
- 높이. (음수면 y 에서 위로)Height. (upward from y if negative)
- radius_list&[R]
- 모서리 반지름 1 ~ 4 개. (원본처럼 1 개는 네 모서리, 2 개는 왼위와 오른아래 / 오른위와 왼아래, 3 개는 왼위 / 오른위와 왼아래 / 오른아래, 4 개는 왼위, 오른위, 오른아래, 왼아래)Corner radii, 1 ~ 4 of them. (as in the original: 1 for all four corners, 2 for top-left and bottom-right / top-right and bottom-left, 3 for top-left / top-right and bottom-left / bottom-right, 4 for top-left, top-right, bottom-right, bottom-left)
반환Returnsbool 반지름이 1 ~ 4 개가 아니거나 음수 반지름이 있으면 false(원본의 예외 자리), 그 밖에는 true.false if there are not 1 ~ 4 radii or a radius is negative (where the original throws), otherwise true.
지금 경로 채우기. (원본 fill(fillRule))
Fills the current path. (the original fill(fillRule))
- fill_ruleCanvasFillRule
- 채우기 규칙.Fill rule.
경로 채우기. (원본 fill(path, fillRule), 경로는 지금 변환으로 옮겨 칠한다)
Fills a path. (the original fill(path, fillRule), the path is transformed by the current transform when painted)
- path&Path2D
- 채울 경로.Path to fill.
- fill_ruleCanvasFillRule
- 채우기 규칙.Fill rule.
지금 경로 긋기. (원본 stroke(), 선 굵기는 지금 변환을 받는다)
Strokes the current path. (the original stroke(), the line width is affected by the current transform)
경로 긋기. (원본 stroke(path))
Strokes a path. (the original stroke(path))
- path&Path2D
- 그을 경로. (지금 변환으로 옮겨 긋는다)Path to stroke. (stroked after transforming with the current transform)
지금 경로로 자르기. (원본 clip(fillRule), 이미 자른 영역과 겹친 곳만 남는다)
Clips to the current path. (the original clip(fillRule), only the area overlapping the existing clip remains)
- fill_ruleCanvasFillRule
- 채우기 규칙.Fill rule.
경로로 자르기. (원본 clip(path, fillRule))
Clips to a path. (the original clip(path, fillRule))
- path&Path2D
- 자를 경로. (지금 변환으로 옮겨 자른다)Path to clip with. (clipped after transforming with the current transform)
- fill_ruleCanvasFillRule
- 채우기 규칙.Fill rule.
점이 지금 경로 안에 있는지. (원본 isPointInPath(x, y, fillRule), 점은 변환을 받지 않는 캔버스 좌표)
Whether a point is inside the current path. (the original isPointInPath(x, y, fillRule), the point is in canvas coordinates not affected by the transform)
- xf64
- 점 x. (변환을 받지 않는 캔버스 좌표)Point x. (canvas coordinates not affected by the transform)
- yf64
- 점 y. (변환을 받지 않는 캔버스 좌표)Point y. (canvas coordinates not affected by the transform)
- fill_ruleCanvasFillRule
- 채우기 규칙.Fill rule.
반환Returnsbool 점이 안에 있으면 true.true if the point is inside.
pub fn is_point_in_path2d(&self, path: &Path2D, x: f64, y: f64, fill_rule: CanvasFillRule) -> bool#점이 경로 안에 있는지. (원본 isPointInPath(path, x, y, fillRule), 경로는 지금 변환으로 옮겨 본다)
Whether a point is inside a path. (the original isPointInPath(path, x, y, fillRule), the path is transformed by the current transform when tested)
- path&Path2D
- 볼 경로.Path to test.
- xf64
- 점 x. (변환을 받지 않는 캔버스 좌표)Point x. (canvas coordinates not affected by the transform)
- yf64
- 점 y. (변환을 받지 않는 캔버스 좌표)Point y. (canvas coordinates not affected by the transform)
- fill_ruleCanvasFillRule
- 채우기 규칙.Fill rule.
반환Returnsbool 점이 안에 있으면 true.true if the point is inside.
글 재기. (원본 measureText, 엔진 글자 캐시로 잰다. 글꼴이 하나도 없으면 0)
Measures text. (the original measureText, measured with the engine glyph cache. 0 if there are no fonts at all)
- text&str
- 잴 글.Text to measure.
반환ReturnsTextMetrics 잰 값. (폭, 글꼴의 위아래 높이, 실제로 칠하는 상자)The measured values. (width, font ascent and descent, the box actually painted)
글 채우기. (원본 fillText(text, x, y, maxWidth), 글이 maxWidth 보다 넓으면 가로로 좁힌다)
Fills text. (the original fillText(text, x, y, maxWidth), squeezes the text horizontally if it is wider than maxWidth)
- text&str
- 칠할 글.Text to fill.
- xf64
- 기준 점 x. (글 가로 정렬이 정하는 자리)Reference point x. (the position set by the horizontal text alignment)
- yf64
- 기준 점 y. (글 기준선이 정하는 자리)Reference point y. (the position set by the text baseline)
- maximum_widthOption<f64>
- 가장 넓은 폭. (None 이면 좁히지 않는다)Maximum width. (not squeezed if None)
글 긋기. (원본 strokeText, 선은 lineWidth 굵기로 윤곽선 가운데에 긋는다)
Strokes text. (the original strokeText, the line is stroked at lineWidth thickness centered on the outline)
- text&str
- 그을 글.Text to stroke.
- xf64
- 기준 점 x. (글 가로 정렬이 정하는 자리)Reference point x. (the position set by the horizontal text alignment)
- yf64
- 기준 점 y. (글 기준선이 정하는 자리)Reference point y. (the position set by the text baseline)
- maximum_widthOption<f64>
- 가장 넓은 폭. (None 이면 좁히지 않는다)Maximum width. (not squeezed if None)
pub fn draw_image<'a>(&mut self, source: impl Into<CanvasImageSource<'a>>, destination_x: f64, destination_y: f64)#그림 그리기. (원본 drawImage(image, dx, dy))
Draws an image. (the original drawImage(image, dx, dy))
- sourceimpl Into<CanvasImageSource<'a>>
- 그릴 그림. (엔진 Image,
Rc<Image>, 다른 Canvas2D)Image to draw. (engine Image,Rc<Image>, another Canvas2D) - destination_xf64
- 그릴 자리 왼쪽 x.Left x of the draw position.
- destination_yf64
- 그릴 자리 위 y.Top y of the draw position.
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)#그림 늘여 그리기. (원본 drawImage(image, dx, dy, dw, dh))
Draws a stretched image. (the original drawImage(image, dx, dy, dw, dh))
- sourceimpl Into<CanvasImageSource<'a>>
- 그릴 그림. (엔진 Image,
Rc<Image>, 다른 Canvas2D)Image to draw. (engine Image,Rc<Image>, another Canvas2D) - destination_xf64
- 그릴 자리 왼쪽 x.Left x of the draw position.
- destination_yf64
- 그릴 자리 위 y.Top y of the draw position.
- destination_widthf64
- 그릴 폭. (음수면 destination_x 에서 왼쪽으로)Width to draw. (leftward from destination_x if negative)
- destination_heightf64
- 그릴 높이. (음수면 destination_y 에서 위로)Height to draw. (upward from destination_y if negative)
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)#그림 일부 그리기. (원본 drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh), 음수 폭과 높이는 원본처럼 뒤집어 맞춘다)
Draws part of an image. (the original drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh), negative widths and heights are flipped to fit like the original)
- sourceimpl Into<CanvasImageSource<'a>>
- 그릴 그림. (엔진 Image,
Rc<Image>, 다른 Canvas2D)Image to draw. (engine Image,Rc<Image>, another Canvas2D) - source_xf64
- 떼어 올 영역 왼쪽. (그림 픽셀)Left of the source area. (image pixels)
- source_yf64
- 떼어 올 영역 위. (그림 픽셀)Top of the source area. (image pixels)
- source_widthf64
- 떼어 올 영역 폭. (그림 픽셀, 음수면 source_x 에서 왼쪽으로)Width of the source area. (image pixels, leftward from source_x if negative)
- source_heightf64
- 떼어 올 영역 높이. (그림 픽셀, 음수면 source_y 에서 위로)Height of the source area. (image pixels, upward from source_y if negative)
- destination_xf64
- 그릴 자리 왼쪽 x.Left x of the draw position.
- destination_yf64
- 그릴 자리 위 y.Top y of the draw position.
- destination_widthf64
- 그릴 폭. (음수면 destination_x 에서 왼쪽으로)Width to draw. (leftward from destination_x if negative)
- destination_heightf64
- 그릴 높이. (음수면 destination_y 에서 위로)Height to draw. (upward from destination_y if negative)
빈 픽셀 묶음. (원본 createImageData)
Empty pixel data. (the original createImageData)
- widthu32
- 폭. (픽셀)Width. (pixels)
- heightu32
- 높이. (픽셀)Height. (pixels)
반환ReturnsImageData 모든 바이트가 0 인 픽셀 묶음.Pixel data with every byte 0.
pub fn get_image_data(&self, source_x: i32, source_y: i32, width: u32, height: u32) -> ImageData#픽셀 읽기. (원본 getImageData, 프리멀티플라이하지 않은 RGBA. 캔버스 밖은 투명한 검정)
Reads pixels. (the original getImageData, non-premultiplied RGBA. Transparent black outside the canvas)
- source_xi32
- 읽을 영역 왼쪽. (캔버스 픽셀, 변환을 받지 않는다)Left of the area to read. (canvas pixels, not affected by the transform)
- source_yi32
- 읽을 영역 위. (캔버스 픽셀, 변환을 받지 않는다)Top of the area to read. (canvas pixels, not affected by the transform)
- widthu32
- 읽을 폭. (픽셀)Width to read. (pixels)
- heightu32
- 읽을 높이. (픽셀)Height to read. (pixels)
반환ReturnsImageData 프리멀티플라이하지 않은 RGBA 픽셀 묶음. (캔버스 밖은 투명한 검정)Non-premultiplied RGBA pixel data. (transparent black outside the canvas)
pub fn put_image_data(&mut self, image_data: &ImageData, destination_x: i32, destination_y: i32)#픽셀 쓰기. (원본 putImageData: 자르기, 투명도, 합치기, 그림자 없이 그대로 바꾼다)
- 곧은 RGBA 를 크롬처럼 (색 x 알파 + 127) / 255 로 프리멀티플라이해 담는다.
- 폭이나 높이가 0 이거나 i32 를 넘거나, data 가 폭 x 높이 x 4 바이트가 아니면 쓰지 않는다. (원본 new ImageData 가 받지 않는 픽셀 묶음)
Writes pixels. (the original putImageData: replaces them as is, without clip, alpha, compositing or shadow)
- Straight RGBA is premultiplied as (color x alpha + 127) / 255, like Chrome.
- Nothing is written when the width or height is 0 or exceeds i32, or when data is not width x height x 4 bytes. (pixel data the original new ImageData does not accept)
- image_data&ImageData
- 쓸 픽셀 묶음. (프리멀티플라이하지 않은 RGBA)Pixel data to write. (non-premultiplied RGBA)
- destination_xi32
- 쓸 자리 왼쪽. (캔버스 픽셀, 변환을 받지 않는다)Left of the write position. (canvas pixels, not affected by the transform)
- destination_yi32
- 쓸 자리 위. (캔버스 픽셀, 변환을 받지 않는다)Top of the write position. (canvas pixels, not affected by the transform)
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)#픽셀 묶음의 한 사각형만 쓰기. (원본 putImageData 의 dirtyX, dirtyY, dirtyWidth, dirtyHeight 꼴, 크롬 base_rendering_context_2d.cc 의 셈)
- 폭 x 높이가 i32 를 넘으면 쓰지 않는다. 음수 폭과 높이는 시작을 그만큼 옮겨 뒤집고(시작이 음수였으면 0), 픽셀 묶음과 캔버스 밖은 자른다.
Writes only one rectangle of the pixel data. (the dirtyX, dirtyY, dirtyWidth, dirtyHeight form of the original putImageData, computed like Chrome's base_rendering_context_2d.cc)
- Nothing is written when width x height exceeds i32. A negative width or height flips the rectangle by moving its start by that amount (0 if the start was negative), and parts outside the pixel data and the canvas are clipped.
- image_data&ImageData
- 쓸 픽셀 묶음. (프리멀티플라이하지 않은 RGBA)Pixel data to write. (non-premultiplied RGBA)
- destination_xi32
- 픽셀 묶음 왼쪽이 놓일 자리. (캔버스 픽셀, 변환을 받지 않는다)Where the left of the pixel data goes. (canvas pixels, not affected by the transform)
- destination_yi32
- 픽셀 묶음 위가 놓일 자리. (캔버스 픽셀, 변환을 받지 않는다)Where the top of the pixel data goes. (canvas pixels, not affected by the transform)
- dirty_xi32
- 쓸 사각형 왼쪽. (픽셀 묶음 픽셀)Left of the rectangle to write. (pixel data pixels)
- dirty_yi32
- 쓸 사각형 위. (픽셀 묶음 픽셀)Top of the rectangle to write. (pixel data pixels)
- dirty_widthi32
- 쓸 사각형 폭. (음수면 왼쪽으로)Width of the rectangle to write. (leftward if negative)
- dirty_heighti32
- 쓸 사각형 높이. (음수면 위로)Height of the rectangle to write. (upward if negative)
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]);엔진 그림으로. (Graphic, UIImageView 에 쓴다. 그 뒤로 그리지 않았으면 같은 Image)
To an engine image. (used for Graphic, UIImageView. The same Image if nothing was drawn since)
반환ReturnsRc<Image> 이 캔버스 픽셀의 엔진 그림. (그 뒤로 그리지 않았으면 같은 Rc)An engine image of this canvas's pixels. (the same Rc if nothing was drawn since)