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.
This commit is contained in:
dotCooCoo
2026-11-18 19:13:08 -08:00
parent 1233b23b19
commit f4b015cf08
2 changed files with 41 additions and 10 deletions
+23
View File
@@ -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)]) {
+18 -10
View File
@@ -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<f32>)]) -> 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);
}