Skip to content

Commit 212e088

Browse files
committed
Add basic clipping-based fill for SVG rendering
1 parent 28b9fba commit 212e088

3 files changed

Lines changed: 309 additions & 108 deletions

File tree

node-graph/libraries/core-types/src/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub const ATTR_SPREAD_METHOD: &str = "spread_method";
7777
/// Gradient's `GradientType` (`Linear` or `Radial`).
7878
pub const ATTR_GRADIENT_TYPE: &str = "gradient_type";
7979

80-
/// Table<Graphic> data for fill.
80+
/// List<Graphic> data for fill.
8181
pub const ATTR_FILL_GRAPHIC: &str = "fill_graphic";
8282

8383
// ========================

node-graph/libraries/rendering/src/render_ext.rs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ use core_types::list::List;
33
use core_types::uuid::generate_uuid;
44
use core_types::{ATTR_GRADIENT_TYPE, ATTR_SPREAD_METHOD, ATTR_TRANSFORM, Color};
55
use glam::{DAffine2, DVec2};
6-
use graphic_types::Graphic;
7-
use graphic_types::graphic::fill_to_graphic_list;
86
use graphic_types::vector_types::gradient::GradientType;
9-
use graphic_types::vector_types::vector::style::{Fill, PaintOrder, PathStyle, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
7+
use graphic_types::vector_types::vector::style::{PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
108
use std::fmt::Write;
119
use vector_types::GradientStops;
1210
use vector_types::gradient::GradientSpreadMethod;
@@ -112,27 +110,6 @@ impl RenderExt for List<GradientStops> {
112110
}
113111
}
114112

115-
impl RenderExt for Fill {
116-
type Output = String;
117-
118-
/// Renders the fill, adding necessary defs through mutating the first argument.
119-
fn render(&self, svg_defs: &mut String, element_transform: DAffine2, stroke_transform: DAffine2, bounds: DAffine2, transformed_bounds: DAffine2, render_params: &RenderParams) -> Self::Output {
120-
let Some(paint_list) = fill_to_graphic_list(self) else { return r#" fill="none""#.to_string() };
121-
let Some(paint) = paint_list.element(0) else { return String::new() };
122-
123-
match paint {
124-
Graphic::Color(color_list) => color_list.render(svg_defs, element_transform, stroke_transform, bounds, transformed_bounds, render_params),
125-
Graphic::Gradient(stops_list) => {
126-
let gradient_id = stops_list.render(svg_defs, element_transform, stroke_transform, bounds, transformed_bounds, render_params);
127-
format!(r##" fill="url('#{gradient_id}')""##)
128-
}
129-
_ => {
130-
todo!()
131-
}
132-
}
133-
}
134-
}
135-
136113
impl RenderExt for Stroke {
137114
type Output = String;
138115

@@ -196,19 +173,3 @@ impl RenderExt for Stroke {
196173
attributes
197174
}
198175
}
199-
200-
impl RenderExt for PathStyle {
201-
type Output = String;
202-
203-
/// Renders the shape's fill and stroke attributes as a string with them concatenated together.
204-
#[allow(clippy::too_many_arguments)]
205-
fn render(&self, svg_defs: &mut String, element_transform: DAffine2, stroke_transform: DAffine2, bounds: DAffine2, transformed_bounds: DAffine2, render_params: &RenderParams) -> String {
206-
let fill_attribute = self.fill.render(svg_defs, element_transform, stroke_transform, bounds, transformed_bounds, render_params);
207-
let stroke_attribute = self
208-
.stroke
209-
.as_ref()
210-
.map(|stroke| stroke.render(svg_defs, element_transform, stroke_transform, bounds, transformed_bounds, render_params))
211-
.unwrap_or_default();
212-
format!("{fill_attribute}{stroke_attribute}")
213-
}
214-
}

0 commit comments

Comments
 (0)