Gradients: a dithered gradient without stops draws nothing, as an undithered one does

Review follow-up (CodeRabbit): a dithered fill skipped set_paint's guard for
a gradient without stops and sampled a transparent grid to draw nothing. It
now takes the same no-fill path.
This commit is contained in:
Taha-Mahmoodi
2026-10-23 00:08:52 +07:00
committed by bflatastic
parent 4062e74ff3
commit 159e20053c
2 changed files with 15 additions and 3 deletions
+3 -3
View File
@@ -52,11 +52,11 @@ pub(crate) fn set_paint(ctx: &mut RenderContext, p: &Paint, bounds: Rect, f: &Fr
}
}
/// [`set_paint`] for a fill: a dithered gradient (dither applies to fills only) is drawn as
/// pixels with fine noise ([`crate::dither`]).
/// [`set_paint`] for a fill: a dithered gradient (dither applies to fills only) with stops is
/// drawn as pixels with fine noise ([`crate::dither`]).
pub(crate) fn set_fill_paint(ctx: &mut RenderContext, p: &Paint, bounds: Rect, f: &Frame) -> bool {
match p {
Paint::Gradient(g) if g.gradient.dither && g.gradient.kind != GradientKind::Freeform => {
Paint::Gradient(g) if g.gradient.dither && g.gradient.kind != GradientKind::Freeform && !g.gradient.stops.is_empty() => {
crate::dither::set_dithered_paint(ctx, g, bounds, f.ink)
}
_ => set_paint(ctx, p, bounds, f),
+12
View File
@@ -121,3 +121,15 @@ fn a_large_dithered_box_mostly_off_screen_samples_only_what_shows() {
// ...from the cells around it only, not the whole grid.
assert!(bytes > 0 && bytes <= 512 * 512 * 4, "{bytes} bytes of grid for a 64-pixel view");
}
#[test]
fn a_dithered_gradient_without_stops_draws_nothing_and_samples_nothing() {
let mut g = Gradient::new(GradientKind::Linear, Vec::new());
g.dither = true;
let d = doc(Paint::Gradient(Box::new(GradientPaint::new(g))), Paint::None);
let mut r = None;
let bytes = dither::grid_bytes_after(|| r = Some(render(&d, Affine::IDENTITY)));
assert_eq!(bytes, 0, "no grid is sampled");
let r = r.unwrap();
assert!((0..H).all(|y| (0..W).all(|x| r.pixel(x, y) == [255, 255, 255, 255])), "nothing is drawn");
}