diff --git a/crates/render/src/tests/typeedges.rs b/crates/render/src/tests/typeedges.rs index e6230a767..fae0207d0 100644 --- a/crates/render/src/tests/typeedges.rs +++ b/crates/render/src/tests/typeedges.rs @@ -642,13 +642,13 @@ fn type_with_a_brush_stroke_is_drawn_as_sharp() { } } -/// Strong and Crisp type in the art of a scatter brush, on an undashed path at 50% opacity, keep -/// that opacity inside the characters: the coverage the method reshapes the edges by is drawn -/// without the path's opacity. +/// Strong and Crisp type in the art of a scatter brush, on an undashed path at 50% opacity, draw +/// every pixel at half of what the same path draws at full opacity: the coverage the method +/// reshapes the edges by is drawn without the path's opacity. #[test] fn type_in_a_translucent_scatter_brush_stroke_keeps_its_opacity() { use vectorcraft_brush::{Brush, BrushKind, Scatter}; - let draw = |m: TypeAntiAlias| { + let draw = |m: TypeAntiAlias, opacity: f32| { let mut d = Document::new(f64::from(W), f64::from(H)); let mut t = TextObject::point(Point::new(0.0, 0.0), "H", CharStyle { size: 40.0, ..Default::default() }); t.anti_alias = m; @@ -662,18 +662,19 @@ fn type_in_a_translucent_scatter_brush_stroke_keeps_its_opacity() { } let line = vectorcraft_geom::shapes::line(Point::new(20.0, 45.0), Point::new(240.0, 45.0)); let mut n = Node::path(d.alloc_id(), line, ap); - n.opacity = 0.5; + n.opacity = opacity; let l = d.layers[0].id; d.insert(Some(l), 0, n).unwrap(); alphas(&d, &RenderOptions::default()) }; let most = |a: &[u8]| a.iter().copied().max().unwrap_or(0); - let sharp = draw(TypeAntiAlias::Sharp); + let sharp = draw(TypeAntiAlias::Sharp, 0.5); assert!((126..=129).contains(&most(&sharp)), "half opaque: {}", most(&sharp)); for m in [TypeAntiAlias::Crisp, TypeAntiAlias::Strong] { - let drawn = draw(m); - assert!((126..=129).contains(&most(&drawn)), "{m:?} keeps the path's opacity: {}", most(&drawn)); - assert_ne!(drawn, sharp, "{m:?} changes the edges"); + let (half, full) = (draw(m, 0.5), draw(m, 1.0)); + assert_ne!(half, sharp, "{m:?} changes the edges"); + let off = half.iter().zip(&full).filter(|&(&h, &f)| (2 * i32::from(h) - i32::from(f)).abs() > 6).count(); + assert_eq!(off, 0, "{m:?}: pixels not at half of full opacity"); } }