fix(render): ByBlock attributes take the reference's transparency without its locked-layer fade

This commit is contained in:
mattlafy
2026-10-26 15:44:59 -04:00
parent a35a9add42
commit 16290fd8d6
2 changed files with 20 additions and 1 deletions
+2 -1
View File
@@ -1737,7 +1737,8 @@ fn insert(b: &mut Builder, ctx: &Ctx, e: &Entity, ins: &cadcraft_doc::Insert, rg
(def, _) => {
let c = a.props.over(&def.map(|d| d.common.clone()).unwrap_or_else(by_block));
let (ink, lw, _, _, shown, layer_t, fade) = resolve_common(&sub_ctx(ctx, e, Mat3::IDENTITY), &c, b.plotting);
let t = if b.opts.transparency { transparency(c.transparency, layer_t, reference) } else { 0 };
// ByBlock takes the reference's own transparency, not its locked-layer fade.
let t = if b.opts.transparency { transparency(c.transparency, layer_t, own) } else { 0 };
let t = if b.opts.on_screen { t.max(fade) } else { t };
(ink, lw, shown, t)
}
+18
View File
@@ -1006,6 +1006,24 @@ fn byblock_child_on_an_unlocked_layer_does_not_inherit_the_fade() {
assert_eq!(faded(&build(&drawing(Percent(20)), &Space::Model, &on_screen(with_transparency()))), vec![20]);
}
#[test]
fn byblock_attribute_on_an_unlocked_layer_does_not_inherit_the_fade() {
use cadcraft_doc::Transparency::{ByBlock, Percent};
// A ByBlock attribute definition on unlocked layer "Open", in a reference on locked "Locked".
for (reference, want) in [(cadcraft_doc::Transparency::ByLayer, 0), (Percent(20), 20)] {
let mut d = attributed(
Common { layer: "Open".into(), transparency: ByBlock, ..Default::default() },
Common { layer: "Locked".into(), transparency: reference, ..Default::default() },
);
d.layers.push(cadcraft_doc::Layer { name: "Open".into(), ..Default::default() });
d.layer_mut("Locked").unwrap().locked = true;
let l = build(&d, &Space::Model, &on_screen(with_transparency()));
let (line, text) = l.prims.split_first().unwrap();
assert_eq!(line.transparency, 50, "the layer-0 line takes the locked reference layer's fade");
assert!(!text.is_empty() && text.iter().all(|p| p.transparency == want), "{:?}", faded(&l));
}
}
/// #1434: a closed polyline with a global width narrower than a pixel loses whole sides at
/// some zooms, while the same polyline with width 0 always shows every side.
#[test]