mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 02:07:10 +01:00
Color Wheel: contrast lines stain picks for a symbol object with no fill
With a picked object of a dynamic symbol instance whose fill or stroke is None or a pattern, the contrast lines measured picks unstained, although a solid pick there is mixed towards the instance's stain when drawn. Picks are now measured with the stain, as for a solid color; gradients are still measured unstained.
This commit is contained in:
1 parent
5552e8a015
commit
4ec043813a
2 files changed
+27
-5
No files matched your search
@@ -1341,7 +1341,7 @@ fn contrast_reading(s: &Session, p: &Value, need_color: bool) -> Result<(Option<
|
||||
(_, alpha, alone) = pass.draw(([0.0; 3], alpha, alone));
|
||||
passes.push(pass);
|
||||
}
|
||||
let stain = if given { None } else { stain_of(s) };
|
||||
let stain = if given { None } else { stain_of(s, !need_color) };
|
||||
Ok((color, Backdrop { against, written, passes, stain, rich_black }))
|
||||
}
|
||||
|
||||
@@ -1619,11 +1619,14 @@ fn drawn_settings(s: &Session, n: &Node, item: Option<usize>, stroke: bool) -> s
|
||||
|
||||
/// The color and amount a fill stains the picked object of a dynamic symbol instance with
|
||||
/// (`symbol_overrides::instance_art` mixes the art's solid paints towards the instance's fill), when
|
||||
/// such an object is picked and its proxy shows a solid color.
|
||||
fn stain_of(s: &Session) -> Option<(Color, f32)> {
|
||||
/// such an object is picked and its proxy shows a solid color. For a pick (`pick`), a proxy of None
|
||||
/// or a pattern counts too, as the pick puts a solid color in its place.
|
||||
fn stain_of(s: &Session, pick: bool) -> Option<(Color, f32)> {
|
||||
let (fill, stroke) = s.proxy_paints();
|
||||
if !matches!(if s.fill_active { fill } else { stroke }, Paint::Solid { .. }) {
|
||||
return None;
|
||||
match if s.fill_active { fill } else { stroke } {
|
||||
Paint::Solid { .. } => {}
|
||||
Paint::None | Paint::Pattern { .. } if pick => {}
|
||||
_ => return None,
|
||||
}
|
||||
let st = s.active()?;
|
||||
let sp = st.selection.symbol_part.as_ref()?;
|
||||
|
||||
@@ -786,6 +786,25 @@ fn a_picked_symbol_object_is_measured_with_its_instances_stain() {
|
||||
assert!((4.5..4.57).contains(&got), "{fix:?} draws {drawn:?}: {got}");
|
||||
}
|
||||
|
||||
/// A pick for a picked symbol object with a fill of None puts a solid color there, which the
|
||||
/// instance's stain mixes like any other, so the Color Wheel's contrast lines measure it stained.
|
||||
#[test]
|
||||
fn a_pick_for_a_picked_symbol_object_with_no_fill_is_measured_with_the_stain() {
|
||||
let mut s = picked_symbol_part();
|
||||
let inst = s.active().unwrap().selection.symbol_part.as_ref().unwrap().instance;
|
||||
s.active_mut().unwrap().selection.symbol_part = None;
|
||||
s.execute("paint.setFill", &json!({"color": "#000000"})).unwrap();
|
||||
s.execute("transparency.set", &json!({"item": fill_index(&s), "opacity": 50})).unwrap();
|
||||
s.active_mut().unwrap().selection.symbol_part = Some(vectorcraft_doc::SymbolPart { instance: inst, path: vec![1] });
|
||||
s.execute("paint.setFill", &json!({"none": true})).unwrap();
|
||||
assert!(s.execute("color.contrast", &json!({})).is_err(), "no color to measure");
|
||||
let backdrop = crate::cmd::contrast_pick_backdrop(&s, &json!({"against": "#000000", "opacity": 100})).unwrap();
|
||||
let cms = vectorcraft_color::cms::active();
|
||||
let white = backdrop.ratio(backdrop.shown(&cms, &vectorcraft_color::Color::rgb(1.0, 1.0, 1.0)));
|
||||
let want = vectorcraft_color::wcag::contrast_ratio([0.5; 3], [0.0; 3]);
|
||||
assert!((white - want).abs() < 1e-3, "a white pick stained half way to black: {white} against {want}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_picked_symbol_object_is_drawn_at_its_instances_opacity() {
|
||||
let mut s = picked_symbol_part();
|
||||
|
||||
Reference in new issue
Block a user