mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
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:
committed by
bflatastic
parent
4062e74ff3
commit
159e20053c
@@ -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),
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user