From f4b015cf083717b54005be56a7777e64799d5251 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 19:13:08 -0800 Subject: [PATCH] EPS: a diamond gradient without a frame is its color at 1 A diamond gradient whose vector has no length has no inside, and the renderer draws it with its color at 1 everywhere. With two stops at 1, that is the first of them, which ends the stretch before it. The EPS writer painted the last stop instead, so such a diamond came out in the other color, and on a PostScript plate an overprinting one whose last stop is paper white knocked out the ink below at Level 3. The writer now paints the color at 1, and on a plate leaves the ink below when that color is paper white, at both levels. --- crates/eps/src/print/tests.rs | 23 +++++++++++++++++++++++ crates/eps/src/scene.rs | 28 ++++++++++++++++++---------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/crates/eps/src/print/tests.rs b/crates/eps/src/print/tests.rs index 8d2f81851c..218a25ed96 100644 --- a/crates/eps/src/print/tests.rs +++ b/crates/eps/src/print/tests.rs @@ -263,6 +263,29 @@ fn an_overprinting_gradient_with_a_hard_stop_at_an_end_keeps_the_ink_below_on_a_ assert_keeps_the_ink_below_of(&cases, true); } +#[test] +fn an_overprinting_diamond_gradient_without_a_frame_keeps_the_ink_below_on_a_postscript_plate() { + // A vector of no length: the diamond is its color at 1 everywhere. With two stops at 1, that is + // the first of them, which ends the stretch before it, not the last stop. + let (inked, none) = (Color::cmyk(0.6, 0.3, 0.0, 0.0), Color::cmyk(0.0, 0.3, 0.0, 0.0)); + let c = Point::new(100.0, 50.0); + let flat = GradientGeom { start: c, end: c, aspect: 0.7, focal: None }; + let cyan = Paint::solid(Color::cmyk(1.0, 0.0, 0.0, 0.0)); + let cases = [ + ("none last", [(0.0, inked), (1.0, inked), (1.0, none)]), + ("cyan last", [(0.0, none), (1.0, none), (1.0, inked)]), + ("none throughout", [(0.0, none), (0.5, none), (1.0, none)]), + ("cyan throughout", [(0.0, inked), (0.5, inked), (1.0, inked)]), + ]; + let cases: Vec<_> = cases + .iter() + .map(|(name, stops)| { + (*name, overprinting(gradient(GradientKind::Diamond, stops, flat, GradientSpread::Pad), Paint::None), cyan.clone(), "Cyan") + }) + .collect(); + assert_keeps_the_ink_below(&cases); +} + /// [`keeps_the_ink_below`] for each of `cases` (a name, the art, the paint under it and the ink /// of the plate) at Level 3 and Level 2, with every case that fails named. fn assert_keeps_the_ink_below(cases: &[(&str, Node, Paint, &str)]) { diff --git a/crates/eps/src/scene.rs b/crates/eps/src/scene.rs index feee718176..c715d817ec 100644 --- a/crates/eps/src/scene.rs +++ b/crates/eps/src/scene.rs @@ -241,6 +241,13 @@ fn unit(v: f32) -> f32 { if v.is_finite() { v.clamp(0.0, 1.0) } else { 0.0 } } +/// The color of `stops` (offsets in order, from 0 to 1) at 1, which a diamond gradient without a +/// frame is everywhere, as [`vectorcraft_color::Gradient::sample`] gives it: the first stop at +/// 1, the end of the stretch before it when several stops share that offset. +fn frameless_color(stops: &[(f64, Vec)]) -> Option<&[f32]> { + stops.iter().find(|(o, _)| *o >= 1.0).or(stops.last()).map(|(_, c)| c.as_slice()) +} + /// Can `a` be drawn through (a finite, non-flat map)? fn invertible(a: Affine) -> bool { let det = a.determinant(); @@ -1231,15 +1238,15 @@ impl<'a> Scene<'a> { GradientKind::Conic => self.conic_steps(&geom, area, space, &stops, &g.gradient), GradientKind::Diamond => { // Its levels are diamonds about the center, the square's edge at 1. - let frame = geom.diamond_frame(); + let Some(frame) = geom.diamond_frame() else { + // Without a frame it is its color at 1 everywhere; overprinting on a plate, + // paper white there leaves the ink below. + if !(self.keep_below && frameless_color(&stops).is_some_and(|c| space.paper(c))) { + self.diamond_quadrants(&geom, area, space, &stops, smooth); + } + return; + }; if let Some(spans) = &spans { - let Some(frame) = frame else { - // Without a frame it is its last stop everywhere. - if stops.last().is_some_and(|(_, c)| !space.paper(c)) { - self.diamond_quadrants(&geom, area, space, &stops, smooth); - } - return; - }; let level = |t: f64| (t > 0.0).then(|| frame * BezPath::from_vec(diamond(t))); self.line("q"); let clipped = self.clip_rings(spans, area.inflate(1.0, 1.0), level); @@ -1444,7 +1451,8 @@ impl<'a> Scene<'a> { /// frame and equal to the diamond there (PostScript has no diamond shading; /// [`vectorcraft_color::GradientGeom::diamond_quadrants`]): smooth axial shadings, else /// stepped fills. Each quadrant but the last runs on under the next (stops are opaque here), - /// so no hairline shows between them. A diamond without an extent is its last stop. + /// so no hairline shows between them. A diamond without an extent is its color at 1 + /// ([`frameless_color`]). fn diamond_quadrants( &mut self, geom: &vectorcraft_color::GradientGeom, @@ -1454,7 +1462,7 @@ impl<'a> Scene<'a> { smooth: bool, ) { let Some(quadrants) = geom.diamond_quadrants(area) else { - if let Some((_, c)) = stops.last() { + if let Some(c) = frameless_color(stops) { self.set_comps(space, c); self.rect_fill(area); }