Add Vello support for Outline view mode rendering; add non_scaling to strokes (SVG, not yet Vello) (#2455)

* fix noise pattern parameter issue

* removed the commented out line

* Fix outline mode stroke width not consistent

* add non scaling stroke option

* Fix backward compatibility

* Clean Debug Message

* clean code

* clean code 2

* Add vello outline support

* Code review

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Ellen Gu
2025-04-06 20:02:11 -04:00
committed by GitHub
parent 3c425d9a71
commit 32aee1ebf9
6 changed files with 185 additions and 121 deletions

View File

@@ -526,6 +526,8 @@ pub struct Stroke {
pub line_join_miter_limit: f64,
#[serde(default = "daffine2_identity")]
pub transform: DAffine2,
#[serde(default)]
pub non_scaling: bool,
}
impl core::hash::Hash for Stroke {
@@ -538,6 +540,7 @@ impl core::hash::Hash for Stroke {
self.line_cap.hash(state);
self.line_join.hash(state);
self.line_join_miter_limit.to_bits().hash(state);
self.non_scaling.hash(state);
}
}
@@ -563,6 +566,7 @@ impl Stroke {
line_join: LineJoin::Miter,
line_join_miter_limit: 4.,
transform: DAffine2::IDENTITY,
non_scaling: false,
}
}
@@ -579,6 +583,7 @@ impl Stroke {
time * self.transform.matrix2 + (1. - time) * other.transform.matrix2,
self.transform.translation * time + other.transform.translation * (1. - time),
),
non_scaling: if time < 0.5 { self.non_scaling } else { other.non_scaling },
}
}
@@ -655,7 +660,10 @@ impl Stroke {
if let Some(line_join_miter_limit) = line_join_miter_limit {
let _ = write!(&mut attributes, r#" stroke-miterlimit="{}""#, line_join_miter_limit);
}
// Add vector-effect attribute to make strokes non-scaling
if self.non_scaling {
let _ = write!(&mut attributes, r#" vector-effect="non-scaling-stroke""#);
}
attributes
}
@@ -702,6 +710,11 @@ impl Stroke {
self.line_join_miter_limit = limit;
self
}
pub fn with_non_scaling(mut self, non_scaling: bool) -> Self {
self.non_scaling = non_scaling;
self
}
}
// Having an alpha of 1 to start with leads to a better experience with the properties panel
@@ -716,6 +729,7 @@ impl Default for Stroke {
line_join: LineJoin::Miter,
line_join_miter_limit: 4.,
transform: DAffine2::IDENTITY,
non_scaling: false,
}
}
}
@@ -878,7 +892,10 @@ impl PathStyle {
match view_mode {
ViewMode::Outline => {
let fill_attribute = Fill::None.render(svg_defs, element_transform, stroke_transform, bounds, transformed_bounds);
let stroke_attribute = Stroke::new(Some(LAYER_OUTLINE_STROKE_COLOR), LAYER_OUTLINE_STROKE_WEIGHT).render();
let mut outline_stroke = Stroke::new(Some(LAYER_OUTLINE_STROKE_COLOR), LAYER_OUTLINE_STROKE_WEIGHT);
// Outline strokes should be non-scaling by default
outline_stroke.non_scaling = true;
let stroke_attribute = outline_stroke.render();
format!("{fill_attribute}{stroke_attribute}")
}
_ => {

View File

@@ -183,6 +183,7 @@ where
line_join,
line_join_miter_limit: miter_limit,
transform: DAffine2::IDENTITY,
non_scaling: false,
};
for vector in vector_data.vector_iter_mut() {
let mut stroke = stroke.clone();