Stroke Emboss bevels every enabled stroke, not only the first (#9337)

With several Stroke effects, the reference application embosses their union: a 4 px stroke
listed over a 10 px one shades the whole 10 px band. The PR used only the first stroke, so the
outer part of a wider second stroke stayed flat. A stroke at 0 % opacity still has its band
embossed there, so the bevel stays independent of the stroke's opacity (pinned by the test).
Inside painting and the interior-blend decision now need every stroke to be inside-only.

Co-Authored-By: DuBearte <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
committed 2026-11-09 19:18:22 +01:00
1 parent 4eb25099b7
commit 13dcec6a78
2 files changed
+63 -11

No files matched your search

+24 -11
View File
@@ -56,16 +56,22 @@ pub(crate) fn build_maps_prepared(
Effect::OuterGlow(g) => vec![glow_map(&shape, g, false, (rect.x0, rect.y0))],
Effect::InnerGlow(g) => vec![glow_map(&shape, g, true, (rect.x0, rect.y0))],
Effect::Satin(s) => vec![satin_map(&shape, s)],
// Stroke Emboss (#8639): an Inner Bevel of the layer's outline with its top Stroke
// effect (the stroked shape's outer edge, inside the stroke too), shading only the
// stroke, over the finished layer, as Photoshop's corpus files show it. Without a
// stroke it has nothing to emboss.
// Stroke Emboss (#8639): an Inner Bevel of the layer's outline with its Stroke effects
// (the stroked shape's outer edge, inside the stroke too), shading only the strokes,
// over the finished layer, as Photoshop's corpus files show it. Several strokes emboss
// as their union (a 4 px stroke over a 10 px one shades the whole 10 px band). Without
// a stroke it has nothing to emboss.
Effect::BevelEmboss(b) if b.style == BevelStyle::StrokeEmboss => {
let stroke = items.iter().find_map(|e| if let Effect::Stroke(st) = e { Some(st) } else { None });
let band = stroke.map(|st| stroke_band(&shape, st));
// A stroke inside the layer shades with the layer, as an Inner Bevel does; one
let strokes: Vec<&photocraft_doc::StrokeFx> = items.iter().filter_map(|e| if let Effect::Stroke(st) = e { Some(st) } else { None }).collect();
let band = strokes.iter().map(|st| stroke_band(&shape, st)).reduce(|mut acc, m| {
for (a, s) in acc.v.iter_mut().zip(&m.v) {
*a = a.max(*s);
}
acc
});
// Strokes inside the layer shade with the layer, as an Inner Bevel does; one
// reaching outside shades over the finished layer and its backdrop.
bevel_paint[i] = if stroke.is_some_and(|st| stroke_widths(st).1 <= 0.0) { BevelPaint::Inner } else { BevelPaint::Both };
bevel_paint[i] = if strokes_inside(&strokes) { BevelPaint::Inner } else { BevelPaint::Both };
match band {
Some(band) => {
// The shape keeps its own (anti-aliased) edge; the stroke adds what lies outside it.
@@ -192,15 +198,22 @@ fn stroke_band(shape: &Map, st: &photocraft_doc::StrokeFx) -> Map {
band
}
/// `true` if there are strokes and none reaches outside the layer: Stroke Emboss then shades with
/// the layer, as an Inner Bevel does.
fn strokes_inside(strokes: &[&photocraft_doc::StrokeFx]) -> bool {
!strokes.is_empty() && strokes.iter().all(|st| stroke_widths(st).1 <= 0.0)
}
/// `true` if an enabled effect painted inside the layer (with its content) blends in a mode
/// other than Normal.
pub(super) fn blends_inside(layer: &Layer) -> bool {
let blends = |m: BlendMode| m != BlendMode::Normal;
// Stroke Emboss with its stroke wholly inside shades with the layer (`BevelPaint::Inner` in
// Stroke Emboss with its strokes wholly inside shades with the layer (`BevelPaint::Inner` in
// `build_maps_prepared`), as an Inner Bevel does; one reaching outside shades over the
// finished layer.
let top_stroke = layer.effects.items.iter().filter(|e| e.enabled()).find_map(|e| if let Effect::Stroke(st) = e { Some(st) } else { None });
let stroke_inside = top_stroke.is_some_and(|st| stroke_widths(st).1 <= 0.0);
let strokes: Vec<&photocraft_doc::StrokeFx> =
layer.effects.items.iter().filter(|e| e.enabled()).filter_map(|e| if let Effect::Stroke(st) = e { Some(st) } else { None }).collect();
let stroke_inside = strokes_inside(&strokes);
layer.effects.items.iter().filter(|e| e.enabled()).any(|e| match e {
Effect::ColorOverlay { common, .. } | Effect::GradientOverlay { common, .. } | Effect::PatternOverlay { common, .. } => blends(common.blend),
Effect::Satin(s) => blends(s.common.blend),
+39
View File
@@ -1074,3 +1074,42 @@ fn an_inside_stroke_emboss_counts_as_an_interior_blend() {
assert!(!super::composite::blends_inside(&layer(vec![stroke(StrokePosition::Center), emboss.clone()])));
assert!(!super::composite::blends_inside(&layer(vec![emboss])));
}
/// #8639 review, measured in the reference application: Stroke Emboss bevels the union of every
/// enabled Stroke (a 4 px stroke listed over a 10 px one shades the whole 10 px band), and a
/// stroke at 0 % opacity still has its band embossed over the backdrop.
#[test]
fn stroke_emboss_bevels_every_stroke_even_a_transparent_one() {
let stroke = |size: f32, position: StrokePosition, opacity: f32| {
Effect::Stroke(photocraft_doc::StrokeFx {
common: photocraft_doc::FxCommon::new(BlendMode::Normal, opacity),
size,
position,
paint: photocraft_doc::FxPaint::Color(photocraft_color::Color::BLACK),
overprint: false,
})
};
let emboss = Effect::BevelEmboss(bevel_of(BevelStyle::StrokeEmboss, BevelTechnique::Smooth));
let maps = |effects: Vec<Effect>| {
let mut l =
photocraft_doc::Layer::new("L", photocraft_doc::LayerContent::Raster(photocraft_raster::Surface::new(photocraft_color::PixelFormat::RGBA8)));
l.effects.items = effects;
let n = l.effects.items.len();
let m = build_maps(&l, square(60, 20, 40).v, Rect::new(0, 0, 60, 60), &GlobalLight::default(), &no_tex());
(m.per[n - 1].clone(), m.bevel_paint[n - 1])
};
// 7 px above the shape: inside the 10 px band only; the bevel (light from the top) lights it.
let lit = |m: &[Map]| m[0].v[13 * 60 + 30];
let (two, paint) = maps(vec![stroke(4.0, StrokePosition::Outside, 1.0), stroke(10.0, StrokePosition::Outside, 1.0), emboss.clone()]);
assert!(lit(&two) > 0.1, "{}", lit(&two));
assert_eq!(paint, BevelPaint::Both);
let (thin, _) = maps(vec![stroke(4.0, StrokePosition::Outside, 1.0), emboss.clone()]);
assert_eq!(lit(&thin), 0.0);
let (clear, _) = maps(vec![stroke(10.0, StrokePosition::Outside, 0.0), emboss.clone()]);
assert!(lit(&clear) > 0.1, "{}", lit(&clear));
// Inside only when every stroke is.
let (_, inside) = maps(vec![stroke(4.0, StrokePosition::Inside, 1.0), stroke(6.0, StrokePosition::Inside, 1.0), emboss.clone()]);
assert_eq!(inside, BevelPaint::Inner);
let (_, mixed) = maps(vec![stroke(4.0, StrokePosition::Inside, 1.0), stroke(6.0, StrokePosition::Outside, 1.0), emboss]);
assert_eq!(mixed, BevelPaint::Both);
}