Add a Clear gradient spread that cuts off to transparency beyond the ends (#4410)

This commit is contained in:
Keavon Chambers
2026-08-05 00:27:18 -07:00
committed by Dennis Kobert
parent fb6a0f9460
commit e54b348166
6 changed files with 178 additions and 34 deletions

View File

@@ -1,4 +1,4 @@
use crate::renderer::{RenderParams, format_transform_matrix, gradient_placement, transform_is_invertible};
use crate::renderer::{ClearGuardPlacement, RenderParams, format_transform_matrix, gradient_placement, spread_adjusted_samples, transform_is_invertible};
use crate::{Render, RenderSvgSegmentList, SvgRender};
use core_types::Color;
use core_types::attribute::Transform;
@@ -112,7 +112,9 @@ pub fn render_gradient_paint<S: core_types::lane::LaneSource<Element = Gradient>
let local_gradient_transform: DAffine2 = source.attr::<Transform>(0);
let gradient_spread: GradientSpread = source.attr::<GradientSpreadAttr>(0);
for (position, color, original_midpoint) in stops.interpolated_samples() {
let (samples, _) = spread_adjusted_samples(stops, gradient_spread, gradient_form, ClearGuardPlacement::SvgStopOrder);
for (position, color, original_midpoint) in samples {
stop.push_str("<stop");
if position != 0. {
let _ = write!(stop, r#" offset="{}""#, (position * 1_000_000.).round() / 1_000_000.);
@@ -149,7 +151,7 @@ pub fn render_gradient_paint<S: core_types::lane::LaneSource<Element = Gradient>
format!(r#" gradientTransform="{gradient_transform}""#)
};
let gradient_spread = if gradient_spread == GradientSpread::Pad {
let gradient_spread = if matches!(gradient_spread, GradientSpread::Pad | GradientSpread::Clear) {
String::new()
} else {
format!(r#" spreadMethod="{}""#, gradient_spread.svg_name())