From 3245184c214627e8c9fc985a6d31249d12e1b2d4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 17:46:49 -0800 Subject: [PATCH] Color Wheel: a group's opacity in a blending group leaves out the art beside it color.contrast added the alpha of the art beside a level inside the nearest blending group at every level on the way out, so a translucent group around the object multiplied that art's alpha by its own opacity and then added it again. The alpha each level takes the art below back out by now adds only the art beside it inside the level around it. The progress-doc line says graphics have an AA result only. --- crates/engine/src/cmd/colorcmds.rs | 11 +++++----- crates/engine/src/tests/colorcontrast.rs | 28 ++++++++++++++++++++++++ docs/target-app-parity.md | 2 +- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/colorcmds.rs b/crates/engine/src/cmd/colorcmds.rs index e337597ce7..a6b9f2effe 100644 --- a/crates/engine/src/cmd/colorcmds.rs +++ b/crates/engine/src/cmd/colorcmds.rs @@ -1062,7 +1062,8 @@ fn contrast(s: &mut Session, p: &Value) -> Result { let sampled = below && opacity.is_none(); // A level with a blend mode that does not isolate draws what is inside it over the art below it, // then takes that art back out by the alpha of what it holds drawn alone, and blends the rest: - // `alone` is that alpha for the nearest such level around, from the levels inside it so far. + // `alone` is the alpha of what the next level out holds drawn alone. Each level's opacity + // applies to what it holds, and the art beside it in the level around it adds to the alpha once. let blends = |a: &Step| a.blend != BlendMode::Normal && !a.isolate; let mut x = (shown(&color), 1.0f32); let mut alone = 1.0f32; @@ -1081,10 +1082,10 @@ fn contrast(s: &mut Session, p: &Value) -> Result { None if step.hide.is_none() && full.is_empty() => (against, 1.0), _ => read(scope.map(|a| &a.within))?, }; - // The alpha of the art below the level inside the nearest blending level around it (none - // for a given background). - let inner = match above.iter().take_while(|a| !a.isolate).find(|a| blends(a)) { - Some(group) if sampled => read(Some(&group.within))?.1, + // The alpha of the art below the level inside the level around it, while a blending level + // lies further out (none for a given background). + let inner = match above.first() { + Some(around) if sampled && above.iter().take_while(|a| !a.isolate).any(blends) => read(Some(&around.within))?.1, _ => 0.0, }; let source = if !blends(step) { diff --git a/crates/engine/src/tests/colorcontrast.rs b/crates/engine/src/tests/colorcontrast.rs index a5e846b184..39f496557d 100644 --- a/crates/engine/src/tests/colorcontrast.rs +++ b/crates/engine/src/tests/colorcontrast.rs @@ -275,6 +275,34 @@ fn an_instances_opacity_for_a_group_of_its_art_applies_once() { assert!((ratio(&r) - drawn).abs() < 0.02, "{r} against {drawn}"); } +/// A selected 50 % black square in a 50 % group, over a 50 % white square, all in a Difference group +/// over gray: the inner group's opacity applies to the black square only, and the white beside the +/// inner group counts once in the alpha the Difference group takes the gray back out by. +#[test] +fn a_groups_opacity_leaves_out_the_art_beside_it_in_a_blending_group() { + let mut s = session(); + let id = |v: Value| vectorcraft_doc::NodeId(v["id"].as_u64().unwrap()); + s.execute("shape.rectangle", &json!({"x": 20, "y": 20, "width": 160, "height": 160})).unwrap(); + s.execute("paint.setFill", &json!({"color": "#8c8c8c"})).unwrap(); + s.execute("object.lock", &json!({})).unwrap(); + let white = id(s.execute("shape.rectangle", &json!({"x": 40, "y": 40, "width": 120, "height": 120})).unwrap()); + s.execute("paint.setFill", &json!({"color": "#ffffff"})).unwrap(); + s.execute("transparency.set", &json!({"opacity": 50})).unwrap(); + let black = id(s.execute("shape.rectangle", &json!({"x": 60, "y": 60, "width": 80, "height": 80})).unwrap()); + s.execute("paint.setFill", &json!({"color": "#000000"})).unwrap(); + s.execute("transparency.set", &json!({"opacity": 50})).unwrap(); + let inner = id(s.execute("object.group", &json!({"ids": [black.0]})).unwrap()); + s.execute("transparency.set", &json!({"opacity": 50})).unwrap(); + s.execute("object.group", &json!({"ids": [white.0, inner.0]})).unwrap(); + s.execute("transparency.set", &json!({"blend": "difference"})).unwrap(); + s.active_mut().unwrap().selection.objects = vec![black]; + let r = s.execute("color.contrast", &json!({})).unwrap(); + let (p, drawn) = canvas_ratio(&s, &r); + // The canvas pixel is rounded to 8 bits, which moves this dark gray's ratio by up to 0.04; with + // the white counted twice the answer is 3.15. + assert!((ratio(&r) - drawn).abs() < 0.05, "{r} against {drawn} ({p:?})"); +} + /// An object that isolates its blending, with a white Multiply fill over a blue one, over red: the /// white multiplies with the blue row below it. #[test] diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index a618c06f05..3792e136fd 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1875,7 +1875,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Missing library files:** a persistent swatch or graphic style library panel whose file is gone at startup reopens and stays in the preferences, showing the file's path with Locate Library… (`ui.libraryPanel.locate`), which reads the file from where it is now into the same panel. - **Swatch library and Recolor Artwork parameters:** the `swatch.library.*` commands, `swatch.resetDefaults`, the graphic style library save, load and add, the `recolor.*` commands and `color.harmony`'s `limitTo` refuse parameters of the wrong form, such as `names: "Grays"`, `limitTo: 5` or `includeImages: "false"`. Errors name the parameter, except that a `limitTo` that is not a string, such as `5`, gets an unknown-library error. A `null` counts as left out except for `recolor.apply`'s `model`, which must be a string when given. - **Color Wheel panel (part of #978):** Window › Color Wheel shows the Fill and Stroke proxy beside a hue ring around a square with saturation across and brightness up. It edits what the Color panel's sliders edit (the active proxy's color, the selected gradient stop or freeform point) through the same paint commands, and a drag is one undo step. Alt paints the other proxy, and Shift steps the ring by 45°. A pick goes from display sRGB into the working RGB space; an RGB, CMYK or Lab color keeps its model, and a Gray color or a tint of a global swatch becomes a process color in the document's color mode. A click gives the ring or the square the keyboard focus, and the arrow keys then step the color; both report their names and values to screen readers, and the Color Picker's color field takes the same keys. The panel menu's Box View puts a box in the wheel's place: a color field with a channel strip at its right for Hue, Saturation, Brightness, Red, Green or Blue (Box Channel), on the Color Picker's axes, kept with the preferences (`ui.colorWheel`); the strip and the Color Picker's channel slider take the arrow keys after a click. Scores and estimates are unchanged. - The panel menu's Show Contrast (VectorCraft's own) adds a row with the [WCAG 2 contrast ratio](https://www.w3.org/TR/WCAG22/#dfn-contrast-ratio) of the color, at the opacity it is drawn with, against the color drawn behind the selection (locked art, opacity and blending included) or a pinned color, cut off at two decimals, with the AA and AAA results for normal text, large text or graphics. `color.contrast` answers the same for agents. + The panel menu's Show Contrast (VectorCraft's own) adds a row with the [WCAG 2 contrast ratio](https://www.w3.org/TR/WCAG22/#dfn-contrast-ratio) of the color, at the opacity it is drawn with, against the color drawn behind the selection (locked art, opacity and blending included) or a pinned color, cut off at two decimals, with the AA and AAA results for normal text, large text or graphics (AA only for graphics). `color.contrast` answers the same for agents. - **Colour:** a Color Picker (colour field, H/S/B/R/G/B channel slider, HSB/RGB/Lab/CMYK fields, hex, web-only snapping, out-of-gamut correction); the Color panel shows a selected colour in its own model and, with nothing selected, the new-art defaults in the mode picked last, which it keeps between sessions; Alt-click paints the other proxy; proxies look through groups and show "?" for mixed paint; Invert, Complement, Apply Last Color (`,`) and Apply Last Gradient (`.`) keep the colour model; every paint command feeds the recent colours. The Color Guide has 21 harmony rules, Steps and Variation options and Limit to Library. Adjust Color Balance (its Global mode shifts tints) and Saturate preview live; Edit Colors and Recolor also reach meshes, images and patterns. Recolor Artwork has colour reduction, five recolour methods, presets, Limit to Library, a colour-wheel Edit tab and Edit Color Group; a local Color Themes panel saves five-colour themes. Fill/Stroke chips open swatch and mixer popovers (the Properties panel has the Control bar's Fill and Stroke chips, Stroke link and weight spinner, with nothing selected too), panels have Illustrator's Window menu keys (Align Shift+F7, Transform Shift+F8, Pathfinder Cmd+Shift+F9, Layers F7, Character Cmd+T…; every panel can be given one in Edit › Keyboard Shortcuts), and Eyedropper Options pick up and apply chosen attributes (Alt and Shift+Alt, image pixels). An ICC CMYK profile converts straight into the RGB working space (not through sRGB, so a wider space such as Wide Gamut RGB keeps colours sRGB can't hold) with the colour settings' black-point compensation, on the canvas and in RGB exports alike (the built-in Generic CMYK compensates both ways, so RGB black separated to a rich black displays as black again). Fills and strokes can overprint (Attributes panel, Overprint Black options), and CMYK documents blend in inks on screen, in PDF and when flattening. Document Color Mode converts the art, symbols, pattern tiles and swatches through the colour settings: Gray stays Gray, RGB grays separate into light grays in cyan, magenta and yellow only, darker four-color grays and a rich black, or go on the black plate only with `grays: "black"` (also for `document.open {colorMode}`). **Color panel spectrum mode tooltip (part of #7235):** hovering the spectrum names the displayed mode (Grayscale, RGB, HSB, CMYK, Web Safe RGB or Lab), including after Shift-clicking to switch modes and with Show Options or Hide Options. Hovering changes no paint or undo history. Spectrum rendering and vertical resizing remain open. Evidence: `spectrum_tooltip_names_its_displayed_mode` and `spectrum_tooltip_follows_shift_cycle_without_painting` in `crates/ui-egui/tests/color_working_components.rs`. Scores and estimates unchanged.