diff options
author | Lukas Lihotzki <lukas@lihotzki.de> | 2025-03-26 13:12:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-26 12:12:44 +0000 |
commit | 251eeb2c2dee8aa91b69d7f451b1a1a7607a3bd1 (patch) | |
tree | 369165369cb932d19b88b9d7269bbec8a0f30432 /components/shared | |
parent | f0ea3c6150ba4e2523ed07f7f3864cfa6c88772f (diff) | |
download | servo-251eeb2c2dee8aa91b69d7f451b1a1a7607a3bd1.tar.gz servo-251eeb2c2dee8aa91b69d7f451b1a1a7607a3bd1.zip |
Add `Path2D` (#35783)
Signed-off-by: Lukas Lihotzki <lukas@lihotzki.de>
Diffstat (limited to 'components/shared')
-rw-r--r-- | components/shared/canvas/canvas.rs | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/components/shared/canvas/canvas.rs b/components/shared/canvas/canvas.rs index 1db7675cf42..b01246bf9c1 100644 --- a/components/shared/canvas/canvas.rs +++ b/components/shared/canvas/canvas.rs @@ -13,6 +13,59 @@ use serde_bytes::ByteBuf; use style::color::AbsoluteColor; use style::properties::style_structs::Font as FontStyleStruct; +#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)] +pub enum PathSegment { + ClosePath, + MoveTo { + x: f32, + y: f32, + }, + LineTo { + x: f32, + y: f32, + }, + Quadratic { + cpx: f32, + cpy: f32, + x: f32, + y: f32, + }, + Bezier { + cp1x: f32, + cp1y: f32, + cp2x: f32, + cp2y: f32, + x: f32, + y: f32, + }, + ArcTo { + cp1x: f32, + cp1y: f32, + cp2x: f32, + cp2y: f32, + radius: f32, + }, + Ellipse { + x: f32, + y: f32, + radius_x: f32, + radius_y: f32, + rotation: f32, + start_angle: f32, + end_angle: f32, + anticlockwise: bool, + }, + SvgArc { + radius_x: f32, + radius_y: f32, + rotation: f32, + large_arc: bool, + sweep: bool, + x: f32, + y: f32, + }, +} + #[derive(Clone, Debug, Deserialize, Serialize)] pub enum FillRule { Nonzero, @@ -41,14 +94,17 @@ pub enum Canvas2dMsg { BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>), ClearRect(Rect<f32>), Clip, + ClipPath(Vec<PathSegment>), ClosePath, Ellipse(Point2D<f32>, f32, f32, f32, f32, f32, bool), Fill(FillOrStrokeStyle), + FillPath(FillOrStrokeStyle, Vec<PathSegment>), FillText(String, f64, f64, Option<f64>, FillOrStrokeStyle, bool), FillRect(Rect<f32>, FillOrStrokeStyle), GetImageData(Rect<u64>, Size2D<u64>, IpcBytesSender), GetTransform(IpcSender<Transform2D<f32>>), - IsPointInPath(f64, f64, FillRule, IpcSender<bool>), + IsPointInCurrentPath(f64, f64, FillRule, IpcSender<bool>), + IsPointInPath(Vec<PathSegment>, f64, f64, FillRule, IpcSender<bool>), LineTo(Point2D<f32>), MoveTo(Point2D<f32>), MeasureText(String, IpcSender<TextMetrics>), @@ -59,6 +115,7 @@ pub enum Canvas2dMsg { SaveContext, StrokeRect(Rect<f32>, FillOrStrokeStyle), Stroke(FillOrStrokeStyle), + StrokePath(FillOrStrokeStyle, Vec<PathSegment>), SetLineWidth(f32), SetLineCap(LineCapStyle), SetLineJoin(LineJoinStyle), |