diff --git a/crates/effects/src/catalog.rs b/crates/effects/src/catalog.rs index 38f73689d7..ea727b804c 100644 --- a/crates/effects/src/catalog.rs +++ b/crates/effects/src/catalog.rs @@ -182,28 +182,28 @@ pub fn effect_catalog() -> Vec { REVOLVE, "Revolve…", &["Effect", "3D and Materials"], - "{angle: degrees (0..360, 360), offset: pt (0..100000, 0), edge: left|right, rotationX: degrees (0), rotationY: degrees (0), rotationZ: degrees (0), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), segments: integer (8..128, 64), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; the first light casts a hard-edged shadow, black at 50% times the art's opacity), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), cap: bool (true: solid, closing circular ends of open profiles and a partial sweep's cut sides; false: hollow), expandVisibleOnly: bool (true, trim covered opaque solid surfaces only on Expand Appearance; surfaces with graphics keep every face), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the swept side, see threeD.mapGraphic: symbol: name of a document symbol, face: front (the side), x: pt (0; the offset of the graphic's center from the middle of the side, around the axis: the angle times the profile's distance from the axis at that point), y: pt (0; along the profile, toward its lower end), scale: % (1..10000, 100), rotation: degrees (-360..360, 0; counterclockwise); wrapped around the side at its own size, so it reaches farther around where the profile comes nearer the axis, shaded with it and drawn only where the side's outside faces the viewer; a full turn cuts it at the back; nothing on the caps), render: object ({mode: shaded}; mode: shaded|wireframe, wireframe draws the edges of the faces the effect draws, each once, stroked 0.5 pt black with round joins, with no fill, shadow or graphics, whatever the opacity of the fills, strokes and group members, while the effect stays live; the stroke is VectorCraft's own)}. Shaded surfaces use smooth vector gradients automatically; intersecting profiles use approximate painter visibility.", + "{angle: degrees (0..360, 360), offset: pt (0..100000, 0), edge: left|right, rotationX: degrees (0), rotationY: degrees (0), rotationZ: degrees (0), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), segments: integer (8..128, 64), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), cap: bool (true: solid, closing circular ends of open profiles and a partial sweep's cut sides; false: hollow), expandVisibleOnly: bool (true, trim covered opaque solid surfaces only on Expand Appearance; surfaces with graphics keep every face), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the swept side, see threeD.mapGraphic: symbol: name of a document symbol, face: front (the side), x: pt (0; the offset of the graphic's center from the middle of the side, around the axis: the angle times the profile's distance from the axis at that point), y: pt (0; along the profile, toward its lower end), scale: % (1..10000, 100), rotation: degrees (-360..360, 0; counterclockwise); wrapped around the side at its own size, so it reaches farther around where the profile comes nearer the axis, shaded with it and drawn only where the side's outside faces the viewer; a full turn cuts it at the back; nothing on the caps), render: object ({mode: shaded}; mode: shaded|wireframe, wireframe draws the edges of the faces the effect draws, each once, stroked 0.5 pt black with round joins, with no fill, shadow or graphics, whatever the opacity of the fills, strokes and group members, while the effect stays live; the stroke is VectorCraft's own)}. Shaded surfaces use smooth vector gradients automatically; intersecting profiles use approximate painter visibility.", json!({"angle":360.0,"offset":0.0,"edge":"left","rotationX":0.0,"rotationY":0.0,"rotationZ":0.0,"perspectiveAngle":0.0,"segments":64,"shade":true,"lightColor":"#ffffff","lights":null,"lightRotation":125.26438968275465,"lightHeight":30.0,"lightBehind":false,"lightIntensity":80.0,"lightSoftness":0.0,"ambient":25.0,"shadow":false,"shadowPosition":"behind","shadowDistance":0.0,"shadowBounds":100.0,"cap":true,"expandVisibleOnly":true,"graphics":[],"render":{"mode":"shaded"}}), ), g( EXTRUDE, "Extrude & Bevel…", &["Effect", "3D and Materials"], - "{depth: pt (0..2000, 50), twist: degrees (0..360, 0; the back turned against the front), taper: % (1..100, 100; the back's size), cap: bool (true: solid; false: hollow), bevel: none|classic|rounded|cove|step|ogee (none), bevelWidth: pt (0..1000, 4), bevelHeight: pt (0..1000, 4), bevelRepeat: integer (1..32, 1), bevelSpace: % (0..90, 0; flat between repeats), bevelInside: bool (false: added around the shape; true: carved into it), bevelBothSides: bool (false), rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; the first light casts a hard-edged shadow, black at 50% times the art's opacity), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the caps, see threeD.mapGraphic: symbol: name of a document symbol, face: front|back (front; the back reads left to right as seen from behind), x: pt (0; the offset of the graphic's center from the center of the object's bounds, in the face's own plane), y: pt (0), scale: % (1..10000, 100; of the symbol's own size), rotation: degrees (-360..360, 0; counterclockwise); drawn turned, foreshortened and shaded with the cap and clipped to it, on a solid cap only), render: object ({mode: shaded}; mode: shaded|wireframe, as Revolve's)}. The front face is the art, extruded backwards about the centre of its bounds; painted with the top fill (else the top stroke).", + "{depth: pt (0..2000, 50), twist: degrees (0..360, 0; the back turned against the front), taper: % (1..100, 100; the back's size), cap: bool (true: solid; false: hollow), bevel: none|classic|rounded|cove|step|ogee (none), bevelWidth: pt (0..1000, 4), bevelHeight: pt (0..1000, 4), bevelRepeat: integer (1..32, 1), bevelSpace: % (0..90, 0; flat between repeats), bevelInside: bool (false: added around the shape; true: carved into it), bevelBothSides: bool (false), rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the caps, see threeD.mapGraphic: symbol: name of a document symbol, face: front|back (front; the back reads left to right as seen from behind), x: pt (0; the offset of the graphic's center from the center of the object's bounds, in the face's own plane), y: pt (0), scale: % (1..10000, 100; of the symbol's own size), rotation: degrees (-360..360, 0; counterclockwise); drawn turned, foreshortened and shaded with the cap and clipped to it, on a solid cap only), render: object ({mode: shaded}; mode: shaded|wireframe, as Revolve's)}. The front face is the art, extruded backwards about the centre of its bounds; painted with the top fill (else the top stroke).", json!({"depth":50.0,"twist":0.0,"taper":100.0,"cap":true,"bevel":"none","bevelWidth":4.0,"bevelHeight":4.0,"bevelRepeat":1,"bevelSpace":0.0,"bevelInside":false,"bevelBothSides":false,"rotationX":-21.88,"rotationY":-23.4,"rotationZ":9.06,"perspectiveAngle":0.0,"shade":true,"lightColor":"#ffffff","lights":null,"lightRotation":125.26438968275465,"lightHeight":30.0,"lightBehind":false,"lightIntensity":80.0,"lightSoftness":0.0,"ambient":25.0,"shadow":false,"shadowPosition":"behind","shadowDistance":0.0,"shadowBounds":100.0,"graphics":[],"render":{"mode":"shaded"}}), ), g( INFLATE, "Inflate…", &["Effect", "3D and Materials"], - "{depth: pt (0..2000, 0; flat depth between front and back), twist: degrees (0..360, 0; the back turned against the front), taper: % (1..100, 100; the back's size), cap: bool (true: solid; false: no back, a shell open behind), volume: % (0..100, 50; 50 rounds the edge like a half sphere), bothSides: bool (false: flat back), rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; the first light casts a hard-edged shadow, black at 50% times the art's opacity), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), render: object ({mode: shaded}; mode: shaded|wireframe, as Revolve's)}. Painted with the top fill (else the top stroke).", + "{depth: pt (0..2000, 0; flat depth between front and back), twist: degrees (0..360, 0; the back turned against the front), taper: % (1..100, 100; the back's size), cap: bool (true: solid; false: no back, a shell open behind), volume: % (0..100, 50; 50 rounds the edge like a half sphere), bothSides: bool (false: flat back), rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), render: object ({mode: shaded}; mode: shaded|wireframe, as Revolve's)}. Painted with the top fill (else the top stroke).", json!({"depth":0.0,"twist":0.0,"taper":100.0,"cap":true,"volume":50.0,"bothSides":false,"rotationX":-21.88,"rotationY":-23.4,"rotationZ":9.06,"perspectiveAngle":0.0,"shade":true,"lightColor":"#ffffff","lights":null,"lightRotation":125.26438968275465,"lightHeight":30.0,"lightBehind":false,"lightIntensity":80.0,"lightSoftness":0.0,"ambient":25.0,"shadow":false,"shadowPosition":"behind","shadowDistance":0.0,"shadowBounds":100.0,"render":{"mode":"shaded"}}), ), g( ROTATE, "Rotate…", &["Effect", "3D and Materials"], - "{rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; the first light casts a hard-edged shadow, black at 50% times the art's opacity), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the plane, as Extrude & Bevel's, with face front only), render: object ({mode: shaded}; mode: shaded|wireframe, as Revolve's)}. Turns the flat art in 3D about the centre of its bounds; every fill and stroke keeps its paint, shaded as one plane.", + "{rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the plane, as Extrude & Bevel's, with face front only), render: object ({mode: shaded}; mode: shaded|wireframe, as Revolve's)}. Turns the flat art in 3D about the centre of its bounds; every fill and stroke keeps its paint, shaded as one plane.", json!({"rotationX":-21.88,"rotationY":-23.4,"rotationZ":9.06,"perspectiveAngle":0.0,"shade":true,"lightColor":"#ffffff","lights":null,"lightRotation":125.26438968275465,"lightHeight":30.0,"lightBehind":false,"lightIntensity":80.0,"lightSoftness":0.0,"ambient":25.0,"shadow":false,"shadowPosition":"behind","shadowDistance":0.0,"shadowBounds":100.0,"graphics":[],"render":{"mode":"shaded"}}), ), g( diff --git a/crates/effects/src/lib.rs b/crates/effects/src/lib.rs index 6c6bec1387..9d5e96744a 100644 --- a/crates/effects/src/lib.rs +++ b/crates/effects/src/lib.rs @@ -86,9 +86,9 @@ pub use raster::{ without_geometry, }; pub use reshape::{ - SYMBOL_ART_MAX_NODES, expand_outlined, follows_image_pixels, gives_image_shape, has_gradient_copies, has_instance_row_raster, has_item_geometry, - has_painted_effects, has_transform_art, has_transform_copies, has_transform_options, image_paint, instance_as_art, needs_outline, outer_effects, - outline_art, outline_text, paint_type_piece, reshape, + SYMBOL_ART_MAX_NODES, expand_outlined, follows_image_pixels, gives_image_shape, has_copied_row_raster, has_gradient_copies, + has_instance_row_raster, has_item_geometry, has_painted_effects, has_transform_art, has_transform_copies, has_transform_options, image_paint, + instance_as_art, needs_outline, outer_effects, outline_art, outline_text, paint_type_piece, reshape, }; pub use revolve::{ CLASSIC_REVOLVE, REVOLVE, has_revolve, is_revolve, revolve_art, revolve_art_in, revolve_options, validate_revolve, validate_revolve_in, diff --git a/crates/effects/src/reshape.rs b/crates/effects/src/reshape.rs index 172eab2348..441e78e9e2 100644 --- a/crates/effects/src/reshape.rs +++ b/crates/effects/src/reshape.rs @@ -107,15 +107,66 @@ fn reaches_appearance(e: &Effect) -> bool { } /// Is `n` a path or compound path that its Transform effects make into art of separate objects -/// ([`has_gradient_copies`], [`has_layered_copies`], [`has_transform_options`], [`copied_raster_at`]), -/// or whose live-effect plug-ins paint what they return ([`has_painted_effects`])? It is drawn, -/// baked and expanded through that art ([`reshape`]). +/// ([`has_gradient_copies`], [`has_layered_copies`], [`has_transform_options`], [`copied_raster_at`], +/// [`has_copied_row_raster`]), or whose live-effect plug-ins paint what they return +/// ([`has_painted_effects`])? It is drawn, baked and expanded through that art ([`reshape`]). pub fn has_transform_art(n: &Node) -> bool { has_gradient_copies(n) || has_layered_copies(n) || has_transform_options(n) || has_painted_effects(n) || (matches!(n.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) && copied_raster_at(n).is_some()) + || has_copied_row_raster(n) +} + +/// Is `n` a path or compound path with a fill or stroke that paints and whose raster effects are +/// carried by copies: one whose own effects list a Transform effect that makes copies after a +/// raster effect that follows it ([`copied_row_raster_at`]), or one with a raster effect that +/// follows a Transform effect ([`crate::raster::follows`]) on a path whose own Transform effect makes +/// copies ([`has_transform_copies`])? Each copy is then an object of its own carrying that fill's or +/// stroke's raster effects, moved, turned, reflected and scaled with it ([`transform_item_leaf`], +/// [`follow_copies`]). +pub fn has_copied_row_raster(n: &Node) -> bool { + if !matches!(n.kind, NodeKind::Path { guide: false, clipping: false, .. } | NodeKind::Compound { .. }) { + return false; + } + // Checked first: this runs for every object drawn. + if !n.appearance.items.iter().any(follows_row_raster) { + return false; + } + n.appearance.items.iter().any(|i| crate::paints(i) && copied_row_raster_at(i.effects()).is_some()) || has_transform_copies(n) +} + +/// Does `item` paint and carry a visible raster effect that follows a Transform effect +/// ([`crate::raster::follows`])? +fn follows_row_raster(item: &AppearanceItem) -> bool { + crate::paints(item) && item.effects().iter().any(|e| e.visible && crate::raster::follows(&e.id)) +} + +/// Where a fill's or stroke's own effects `fx` split so that each copy of a Transform effect carries +/// the raster effects listed before it: the index of the first visible Transform effect that makes +/// copies (an earlier one that makes copies included) for which a visible raster effect that +/// follows a Transform effect ([`crate::raster::follows`]) is listed before it, every other visible +/// effect before it is a geometry effect or such a raster effect, and no Transform effect before it +/// that makes copies or moves at random holds those raster effects back +/// ([`crate::raster::held_back`]). `None` otherwise, and when a raster effect is listed after it +/// and before a later Transform effect that makes copies or moves at random, which would apply to +/// the art that raster effect paints. +fn copied_row_raster_at(fx: &[Effect]) -> Option { + let copying = + |e: &Effect| e.visible && e.id == "distort.transform" && crate::distort::transform_map(Rect::ZERO, &merged_params(&e.id, &e.params), 0).1 > 0; + // Is a visible raster effect in `rest` listed before its last Transform effect that holds back? + let raster_held = |rest: &[Effect]| { + rest.iter().rposition(crate::raster::holds_back).is_some_and(|k| rest[..k].iter().any(|e| e.visible && crate::is_raster(&e.id))) + }; + (0..fx.len()).find(|&t| { + let before = &fx[..t]; + copying(&fx[t]) + && !raster_held(&fx[t + 1..]) + && crate::raster::held_back(before) == 0 + && before.iter().any(|e| e.visible && crate::raster::follows(&e.id)) + && before.iter().all(|e| !e.visible || is_geometry(&e.id) || crate::raster::follows(&e.id)) + }) } /// Where the own effects of `n`, a path, compound path, type, image or symbol instance, split so @@ -999,7 +1050,7 @@ fn as_art_opts( } _ => outline_art_with(symbols, paint_doc, n, symbol_art, outline, nodes, apart)?, }; - reshape_leaves_apart(&mut art, &fx, &n.appearance.effects, Budget::EFFECTS, apart, paint_doc); + reshape_leaves_apart(&mut art, &fx, &n.appearance.effects, Budget::EFFECTS, (apart, has_copied_row_raster(n)), paint_doc); if apart { hoist_copies(&mut art); } @@ -1068,7 +1119,8 @@ fn copied_raster_art(doc: Option<&Document>, n: &Node, t: usize, apart: bool, ou } None => { let mut art = one_piece(&source); - let carry = reshape_leaves_apart(&mut art, &geometry_effects(&source), &source.appearance.effects, Budget::EFFECTS, apart, doc); + let rows = has_copied_row_raster(&source); + let carry = reshape_leaves_apart(&mut art, &geometry_effects(&source), &source.appearance.effects, Budget::EFFECTS, (apart, rows), doc); if apart { hoist_copies(&mut art); } @@ -1109,7 +1161,7 @@ fn copied_raster_art(doc: Option<&Document>, n: &Node, t: usize, apart: bool, ou } } let later: Vec<&Effect> = rest.iter().skip(1).filter(|e| e.visible && is_geometry(&e.id)).collect(); - let carry = reshape_leaves_apart(&mut art, &later, &n.appearance.effects, Budget::EFFECTS, apart, doc); + let carry = reshape_leaves_apart(&mut art, &later, &n.appearance.effects, Budget::EFFECTS, (apart, has_copied_row_raster(n)), doc); let mut ran = n.appearance.effects.clone(); if carry.skipped() { carry.hide_skipped(&mut ran); @@ -1240,19 +1292,19 @@ pub(crate) fn geometry_effects(n: &Node) -> Vec<&Effect> { /// that live-effect plug-ins painting their pieces name are looked up in `doc`, and a deferred one /// is listed by its index in `owner`, the effect list `fx` was taken from ([`reshape_leaves_apart`]). pub(crate) fn reshape_leaves(art: &mut Node, fx: &[&Effect], owner: &[Effect], doc: Option<&Document>) { - reshape_leaves_apart(art, fx, owner, Budget::EFFECTS, false, doc); + reshape_leaves_apart(art, fx, owner, Budget::EFFECTS, (false, false), doc); } /// [`reshape_leaves`], and how gradients that paint the art as a whole (a group's own fills and /// strokes) follow the effects ([`crate::Carry`]). pub(crate) fn reshape_leaves_carrying(art: &mut Node, fx: &[&Effect], owner: &[Effect], doc: Option<&Document>) -> crate::Carry { - reshape_leaves_apart(art, fx, owner, Budget::EFFECTS, false, doc) + reshape_leaves_apart(art, fx, owner, Budget::EFFECTS, (false, false), doc) } /// [`reshape_leaves_carrying`] whose paths keep to `budget` together, or to what they cost. #[cfg(test)] pub(crate) fn reshape_leaves_within(art: &mut Node, fx: &[&Effect], budget: Budget, doc: Option<&Document>) -> crate::Carry { - reshape_leaves_apart(art, fx, &[], budget, false, doc) + reshape_leaves_apart(art, fx, &[], budget, (false, false), doc) } /// `art`, the group of the one piece a path's copies are made from ([`outline_art_with`]), holding @@ -1273,7 +1325,10 @@ fn hoist_copies(art: &mut Node) { /// [`reshape_leaves_carrying`] whose paths keep to `budget` together, or to what they cost; with /// `apart`, a Transform effect's copies of each path are objects -/// of their own ([`copy_leaf`]) whatever paints them, as Expand Appearance makes them. A live-effect +/// of their own ([`copy_leaf`]) whatever paints them, as Expand Appearance makes them. With `rows`, +/// so are the copies of a path with a fill or stroke whose raster effects follow a Transform effect +/// ([`crate::raster::follows`]), and each copy's fills and strokes carry those raster effects moved, +/// turned, reflected and scaled with it ([`follow_copies`]). A live-effect /// plug-in that paints what it returns makes each path a group of its pieces ([`paint_leaf`]), /// whose swatches and patterns must be in `doc` (without one, pieces that name one are refused). /// Returns how gradients that paint the art as a whole follow the effects, and the Transform @@ -1284,7 +1339,14 @@ fn hoist_copies(art: &mut Node) { /// type and live objects in it outlined and evaluated first ([`outlined_members`]). When a mask /// stays as it was, or a Transform effect makes fewer copies than it asks for, art with linked /// masks keeps its shape under that effect. -fn reshape_leaves_apart(art: &mut Node, fx: &[&Effect], owner: &[Effect], budget: Budget, apart: bool, doc: Option<&Document>) -> crate::Carry { +fn reshape_leaves_apart( + art: &mut Node, + fx: &[&Effect], + owner: &[Effect], + budget: Budget, + (apart, rows): (bool, bool), + doc: Option<&Document>, +) -> crate::Carry { let mut whole = crate::Carry::default(); if fx.is_empty() { return whole; @@ -1321,7 +1383,7 @@ fn reshape_leaves_apart(art: &mut Node, fx: &[&Effect], owner: &[Effect], budget let params = merged_params(&e.id, &e.params); // Where a live-effect plug-in sits, which it is listed by when it is deferred. let effect = owner.iter().position(|x| std::ptr::eq(x, *e)).or_else(|| listed.iter().position(|x| std::ptr::eq(*x, *e))); - let step = Step { e, params: ¶ms, bounds, seed, effect, apart, doc, wholes: &wholes, held }; + let step = Step { e, params: ¶ms, bounds, seed, effect, apart, rows, doc, wholes: &wholes, held }; // Art with linked masks keeps its shape under an effect that a mask in it could not take // as the art it masks did, so no mask is left apart from its art. let before = masked.then(|| (art.clone(), used)); @@ -1365,6 +1427,7 @@ struct Step<'a> { seed: u64, effect: Option, apart: bool, + rows: bool, doc: Option<&'a Document>, wholes: &'a HashMap, held: bool, @@ -1529,8 +1592,12 @@ impl Step<'_> { // make together; and Expand Appearance (`apart`) makes each copy an object. // Fills and strokes that stack paint each copy below the one before (#5920, #6316). // Each copy of a path with a linked mask carries the mask, moved with it. + // With `rows`, each copy carries the raster effects of its fills and strokes, + // following that copy's map. + let rows = self.rows && copies > 0 && leaf.appearance.items.iter().any(follows_row_raster); let separate = copies > 0 && (self.apart + || rows || leaf.appearance.has_unplaced_gradient() || leaf.appearance.has_placed_gradient() || paints_copies_apart(&leaf.appearance, rule) @@ -1538,9 +1605,12 @@ impl Step<'_> { // The copies of a path replace it by a group of them, the path included. let copied = |leaf: &Node| leaf.children().map_or(0, Vec::len); if options.reach_appearance() { - let (made, moved) = transform_leaf(leaf, &path, map, copies, options, room, raster_map.is_some(), None); + let (made, moved) = transform_leaf(leaf, &path, map, copies, options, room, raster_map.is_some() || rows, None); *used = used.minus(before).plus(made); took |= moved; + if moved && rows { + follow_copies(leaf, map, None); + } if moved { // With Transform Objects off the path stays, and its mask takes the // effect's stroke and pattern changes as its own art. @@ -1556,6 +1626,9 @@ impl Step<'_> { if separate { let scaling = vectorcraft_doc::Scaling { keep_fit_when_flat: true, ..Default::default() }; let made = copy_leaf(leaf, &path, m, copies, scaling, room, None); + if rows { + follow_copies(leaf, m, None); + } *used = used.minus(before).plus(made); took = true; moved_ids.insert(leaf.id); @@ -1947,7 +2020,7 @@ fn transform_leaf( kept: Kept, ) -> (Budget, bool) { let mut scaling = copy_scaling(options); - if follows && copies == 0 { + if follows { scaling.effects = options.strokes.then_some(scale_unfollowed as fn(&mut Effect, f64)); } if !options.objects { @@ -2263,7 +2336,8 @@ fn paint_piece( /// Every path and compound path under `art` (other than clipping paths) with a fill or stroke whose /// own Transform effect has Transform Patterns or Scale Strokes & Effects on -/// ([`item_transform_options`]), or whose own live-effect plug-in paints what it returns +/// ([`item_transform_options`]) or makes copies that carry the raster effects before it +/// ([`copied_row_raster_at`]), or whose own live-effect plug-in paints what it returns /// ([`painted_plugin`]), made into a group of objects of its own ([`transform_item_leaf`]). The /// new paths keep to one [`Budget::EFFECTS`] together (or to what `art` costs, when that is more). /// The swatches and patterns painted pieces name must be in `doc`; without one they may name none. @@ -2280,9 +2354,20 @@ fn makes_piece(e: &Effect) -> bool { reaches_appearance(e) || painted_plugin(e).is_some() } -/// Does `item` paint and carry an effect that [`makes_piece`]? +/// Where the fill's or stroke's own effects `fx` make its piece of a path an object of its own: the +/// index of the first effect that [`makes_piece`], or of the Transform effect whose copies carry the +/// raster effects before it ([`copied_row_raster_at`]), whichever is listed first. +fn piece_at(fx: &[Effect]) -> Option { + let copied = copied_row_raster_at(fx); + match fx.iter().position(makes_piece) { + Some(at) => Some(copied.map_or(at, |t| t.min(at))), + None => copied, + } +} + +/// Does `item` paint and carry an effect that makes its piece an object of its own ([`piece_at`])? fn item_makes_piece(item: &AppearanceItem) -> bool { - crate::paints(item) && item.effects().iter().any(makes_piece) + crate::paints(item) && piece_at(item.effects()).is_some() } /// `leaf`, a path or compound path with a fill or stroke whose own Transform effect has Transform @@ -2292,12 +2377,17 @@ fn item_makes_piece(item: &AppearanceItem) -> bool { /// as [`transform_leaf`] transforms an object with that effect's map, copies and options, so the /// stroke's weight and dashes, the distances of the effects before the Transform effect and its /// pattern follow the map, and the raster effects before it that follow it take their followed -/// values ([`follow_piece`]). The effects after it keep their values and apply to what it made +/// values ([`follow_piece`]), on each copy the values that copy's map gives them +/// ([`follow_copies`]). The effects after it keep their values and apply to what it made /// ([`keep_listed`]), and with Transform Objects off so do the effects before it. The reference box /// is that geometry's bounds and the seed is the leaf's id, as the renderer draws a fill's or -/// stroke's own effects. The geometry effects after the Transform effect then +/// stroke's own effects. A fill or stroke whose first such Transform effect makes copies that carry +/// the raster effects before it ([`copied_row_raster_at`]) becomes a path of its own the same way, +/// with neither option. The geometry effects after the Transform effect then /// apply to the transformed path and its copies as one piece ([`transform_piece`]), and its other -/// effects stay on each of them. The other fills and strokes stay together on paths of the leaf's +/// effects stay on each of them, except that without either option the raster effects after a +/// Transform effect that makes copies paint once around all of them ([`lift_later_raster`]). The +/// other fills and strokes stay together on paths of the leaf's /// geometry between them, with their own effects. `max` is the budget of the whole art and `used` /// what it has spent. /// @@ -2343,7 +2433,7 @@ fn transform_item_leaf(leaf: &mut Node, max: Budget, used: &mut Budget, doc: Opt let later = |i: usize| (i + 1..transformed.len()).filter(|&j| transformed[j] || j == i + 1 || transformed[j - 1]).count(); for (i, item) in original.appearance.items.iter().enumerate() { let fx = item.effects(); - let Some(at) = fx.iter().position(makes_piece).filter(|_| crate::paints(item)) else { + let Some(at) = piece_at(fx).filter(|_| crate::paints(item)) else { plain.push(item.clone()); continue; }; @@ -2421,13 +2511,24 @@ fn transform_item_leaf(leaf: &mut Node, max: Budget, used: &mut Budget, doc: Opt set_geometry(&mut p, g.clone(), rule); let after = kept_before.len(); let keep = |k: usize| k >= after || !options.objects; - let (made, moved) = transform_leaf(&mut p, &g, map, copies, options, room, false, Some((&rest, &keep))); - *used = used.plus(made); let from = crate::raster::held_back(before); - if moved && !held_later { + // Each copy carries the raster effects before the Transform effect, following that copy's + // map, unless a Transform effect before or after it holds them back. + let copied = copies > 0 && !held_later && from == 0; + let (made, moved) = transform_leaf(&mut p, &g, map, copies, options, room, copied, Some((&rest, &keep))); + *used = used.plus(made); + if moved && copied { + follow_copies(&mut p, map, Some(0..after)); + } else if moved && !held_later { follow_piece(&mut p, kept_before.get(from..).unwrap_or_default(), from, &fx[at]); } transform_piece(&mut p, (ctx.seed, i, &kept), crate::raster::held_back(&fx[..=at]), false, limit, used, doc); + // Without Transform Patterns and Scale Strokes & Effects, the raster effects after the + // Transform effect paint once around all the copies, as they paint around the one path of + // every copy. + if copies > 0 && !options.reach_appearance() { + lift_later_raster(&mut p, after); + } pieces.push(Arc::new(p)); } if !plain.is_empty() { @@ -2478,6 +2579,7 @@ fn transform_piece( count = count.max(item.effects().len()); } }); + let outer = held; // The effects before a Transform effect among the piece's effects that makes copies or moves at // random are held back from the Transform effects before it too. let mut held = held; @@ -2498,7 +2600,7 @@ fn transform_piece( let from = held.min(j); let mut holds = false; let stage = vectorcraft_plugins::deferred::Stage { object: seed, effect: kept.get(j).copied().unwrap_or(j), item: Some(source) }; - let at = PieceStage { j, from, seed, bounds, doc, stage }; + let at = PieceStage { j, from, outer, seed, bounds, doc, stage }; // Stage `j` on `leaf`, a path `used` counts at `piece_cost` when `share`: whether `used` // counts each path it became so, or `None` when it stays as it was. let mut on_leaf = |leaf: &mut Node, share: bool| -> Option> { @@ -2719,12 +2821,14 @@ thread_local! { /// Where a stage of [`transform_piece`] runs: `j`, the index of its effect among the piece's /// effects; `from`, the first of the effects before it whose raster effects follow a Transform -/// effect; the object's `seed`; the reference box `bounds` of all the piece's paths; the document -/// that painted pieces' swatches and patterns must be in; and the `stage` a deferred live-effect -/// plug-in is listed by. +/// effect; `outer`, how many of the piece's effects a Transform effect before them holds back; the +/// object's `seed`; the reference box `bounds` of all the piece's paths; the document that painted +/// pieces' swatches and patterns must be in; and the `stage` a deferred live-effect plug-in is +/// listed by. struct PieceStage<'a> { j: usize, from: usize, + outer: usize, seed: u64, bounds: Rect, doc: Option<&'a Document>, @@ -2767,15 +2871,30 @@ fn piece_stage(leaf: &mut Node, e: &Effect, at: &PieceStage, (appearance, index) let params = merged_params(&e.id, &e.params); return paint_piece(leaf, &item, (appearance, index), (plugin, ¶ms), at.bounds, room, at.doc, Some(at.stage)); } - if reaches_appearance(e) { + let copied = copies_carry(item.effects(), e, at); + if reaches_appearance(e) || copied { let params = merged_params(&e.id, &e.params); let (_, copies) = crate::distort::transform_map(at.bounds, ¶ms, at.seed); let options = crate::distort::TransformOptions::of(¶ms); let map = crate::distort::transform_affine(at.bounds, ¶ms, at.seed); let j = at.j; let keep = |k: usize| k > j || (k < j && !options.objects); - let (made, moved) = transform_leaf(leaf, &path, map, copies, options, room, false, Some((item.effects(), &keep))); - if moved { + let (made, moved) = transform_leaf(leaf, &path, map, copies, options, room, copied, Some((item.effects(), &keep))); + if moved && copied { + // Each copy's raster effects before the Transform effect follow that copy's map. The + // Transform effects before it have already moved them, so each run between two of + // them follows on its own. + let fx = item.effects(); + let mut start = 0; + for k in 0..=j { + if k == j || fx.get(k).is_some_and(|f| f.id == "distort.transform") { + if start < k { + follow_copies(leaf, map, Some(start..k)); + } + start = k + 1; + } + } + } else if moved { follow_piece(leaf, was, at.from, e); } return Some(made); @@ -2800,6 +2919,37 @@ fn piece_stage(leaf: &mut Node, e: &Effect, at: &PieceStage, (appearance, index) Some(made) } +/// Does Transform effect `e`, at stage `at` of [`transform_piece`] of a fill or stroke whose effects +/// are `fx`, make copies that each carry the raster effects listed before it, following that copy's +/// map ([`follow_copies`]), as the copies of the piece's first Transform effect do +/// ([`transform_item_leaf`])? It does when it makes copies with Transform Objects on, a visible +/// raster effect that follows a Transform effect ([`crate::raster::follows`]) is listed before it, +/// and no Transform effect that makes copies or moves at random holds those raster effects back: +/// none before the piece's effects, none listed before it after such a raster effect, and none +/// after it. Without Transform Patterns and Scale Strokes & Effects, every other visible effect +/// before it must also be a geometry effect or such a raster effect, and no visible raster effect +/// may be listed after it, as for [`copied_row_raster_at`]. +fn copies_carry(fx: &[Effect], e: &Effect, at: &PieceStage) -> bool { + if !e.visible || e.id != "distort.transform" || at.outer > 0 { + return false; + } + let params = merged_params(&e.id, &e.params); + if !crate::distort::TransformOptions::of(¶ms).objects || crate::distort::transform_map(Rect::ZERO, ¶ms, 0).1 == 0 { + return false; + } + let before = fx.get(..at.j).unwrap_or_default(); + let after = fx.get(at.j + 1..).unwrap_or_default(); + if crate::raster::held_back(before) > 0 + || !before.iter().any(|f| f.visible && crate::raster::follows(&f.id)) + || after.iter().any(crate::raster::holds_back) + { + return false; + } + reaches_appearance(e) + || (before.iter().all(|f| !f.visible || is_geometry(&f.id) || crate::raster::follows(&f.id)) + && !after.iter().any(|f| f.visible && crate::is_raster(&f.id))) +} + /// Are `a` and `b` paths or compound paths that differ only in their fills and strokes? fn same_path(a: &Node, b: &Node) -> bool { let leaf = |n: &Node| matches!(n.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }); @@ -2872,6 +3022,52 @@ fn follow_piece(leaf: &mut Node, was: &[Effect], from: usize, t: &Effect) { } } +/// Make the raster effects that follow a Transform effect ([`crate::raster::follows`]) on the fills +/// and strokes of each copy [`copy_leaf`] made of `leaf` with map `m` follow that copy's map: the +/// copy `k` places below the original takes the linear part of `m` `k` times +/// ([`crate::raster::follow_contents`]), and the original, on top, keeps its effects. `range`, when +/// given, is which of each fill's or stroke's effects follow; the others keep their values. +fn follow_copies(leaf: &mut Node, m: Affine, range: Option>) { + let step = m.with_translation(vectorcraft_geom::Vec2::ZERO); + let Some(children) = leaf.children_mut() else { return }; + let mut a = Affine::IDENTITY; + for c in children.iter_mut().rev().skip(1) { + a *= step; + for item in &mut Arc::make_mut(c).appearance.items { + let fx = item.effects_mut(); + let fx = match &range { + Some(r) => fx.get_mut(r.clone()).unwrap_or_default(), + None => fx.as_mut_slice(), + }; + crate::raster::follow_contents(fx, a, Affine::IDENTITY); + } + } +} + +/// Move the raster effects from index `after` on of the fills and strokes of the paths under `p`, +/// a group of copies of one fill or stroke with the same effects, onto `p` itself, so they paint +/// once around all of the copies. The other effects stay where they are. +fn lift_later_raster(p: &mut Node, after: usize) { + if p.children().is_none() { + return; + } + let mut lifted: Option> = None; + for_each_leaf(p, &mut |l| { + for item in &mut l.appearance.items { + let fx = item.effects_mut(); + if fx.len() <= after { + continue; + } + let (raster, other): (Vec, Vec) = fx.split_off(after).into_iter().partition(|e| crate::is_raster(&e.id)); + fx.extend(other); + lifted.get_or_insert(raster); + } + }); + if let Some(raster) = lifted { + p.appearance.effects.extend(raster); + } +} + /// The bounds of each group of type's outlines under `n` ([`outline_text`]), `n` included, in /// order. A group inside one of them is part of it. fn type_outline_bounds(n: &Node, out: &mut Vec>) { diff --git a/crates/effects/src/revolve.rs b/crates/effects/src/revolve.rs index c0955e2032..c065e507df 100644 --- a/crates/effects/src/revolve.rs +++ b/crates/effects/src/revolve.rs @@ -992,7 +992,8 @@ fn art(doc: Option<&Document>, n: &Node, expand: bool) -> Option { if let Some(b) = p.bounds() && let Some(mut shadow) = shadow_of(n.id, fx, &p, item, b, rule_options(fx, rule), kept).ok()? { - shadow.appearance.effects = art.appearance.effects.clone(); + // The shadow keeps its own blur (the light's Softness) below the later effects. + shadow.appearance.effects.extend(art.appearance.effects.iter().cloned()); shadows.push(Arc::new(shadow)); } children.push(Arc::new(art)); diff --git a/crates/effects/src/solids.rs b/crates/effects/src/solids.rs index 06f6951791..19b134f53b 100644 --- a/crates/effects/src/solids.rs +++ b/crates/effects/src/solids.rs @@ -2177,7 +2177,11 @@ pub fn solid_art_in(doc: Option<&Document>, n: &Node) -> Option { Arc::make_mut(&mut art).appearance.effects = later.clone(); art }; - shadows.extend(shadow.into_iter().map(with_later)); + // A shadow keeps its own blur (the light's Softness) below the later effects. + shadows.extend(shadow.into_iter().map(|mut art| { + Arc::make_mut(&mut art).appearance.effects.extend(later.iter().cloned()); + art + })); children.extend(surfaces.into_iter().map(with_later)); } else { let flat = Appearance { items: vec![item.clone()], ..Default::default() }; diff --git a/crates/effects/src/solids/shadow.rs b/crates/effects/src/solids/shadow.rs index 81542a3722..7b84214d29 100644 --- a/crates/effects/src/solids/shadow.rs +++ b/crates/effects/src/solids/shadow.rs @@ -1,12 +1,12 @@ //! The shadow of the 3D and Materials effects (Extrude & Bevel, Inflate, Rotate and Revolve): the //! `shadow` switch with `shadowPosition`, `shadowDistance` and `shadowBounds`, and the shape it -//! draws behind the solids. +//! draws behind the solids, blurred by the first light's Softness. use std::ops::Range; use std::sync::Arc; -use serde_json::Value; +use serde_json::{Value, json}; use vectorcraft_doc::color::{BlendMode, Color, Paint}; -use vectorcraft_doc::{Appearance, AppearanceItem, FillLayer, Node, NodeId}; +use vectorcraft_doc::{Appearance, AppearanceItem, Effect, FillLayer, Node, NodeId}; use vectorcraft_three_d::{Shadow, ShadowCaster, ShadowPlane, ShadowPosition}; use super::Scope; @@ -15,15 +15,21 @@ use crate::util::{flag, num, text}; /// The shadow's paint: black at this opacity. VectorCraft's own values. const SHADOW_OPACITY: f32 = 0.5; +/// Blur radii below this, in points, leave the shadow hard-edged. +const MIN_BLUR: f64 = 0.01; + /// The shadow `p` asks for, or `None` with the switch off or when the first light lights nothing -/// (Shading is off or its intensity is 0), so that no shadow is built. +/// (Shading is off or its intensity is 0), so that no shadow is built. Its softness is the first +/// light's. pub(crate) fn options(p: &Value) -> Option { - let intensity = crate::lighting::lights(p).and_then(|l| l.iter().next().map(|l| l.intensity)).unwrap_or_else(|| num(p, "lightIntensity", 80.0)); + let first = crate::lighting::lights(p).and_then(|l| l.iter().next().copied()); + let intensity = first.map_or_else(|| num(p, "lightIntensity", 80.0), |l| l.intensity); let lit = flag(p, "shade", true) && intensity > 0.0; (lit && flag(p, "shadow", false)).then(|| Shadow { position: ShadowPosition::parse(text(p, "shadowPosition", "behind")).unwrap_or_default(), distance: num(p, "shadowDistance", 0.0) / 100.0, bounds: num(p, "shadowBounds", 100.0) / 100.0, + softness: first.map_or_else(|| num(p, "lightSoftness", 0.0) / 100.0, |l| l.softness), }) } @@ -64,8 +70,9 @@ pub(crate) fn casts(opacity: f32) -> bool { } /// The shadow of the faces in `caster` as a path of object `id`, cast by art in `ink`: filled -/// black at [`SHADOW_OPACITY`] times its opacity, in its blending mode, with the nonzero rule; -/// `None` when it casts nothing. +/// black at [`SHADOW_OPACITY`] times its opacity, in its blending mode, with the nonzero rule, and +/// with the light's Softness a Gaussian Blur of the plane's radius ([`ShadowPlane::blur`]), which +/// is drawn, measured, exported and expanded as that effect is; `None` when it casts nothing. pub(crate) fn art(id: NodeId, caster: &ShadowCaster, shadow: Shadow, ink: Ink) -> Option { let all = 0..caster.len(); let all = std::slice::from_ref(&all); @@ -78,7 +85,9 @@ fn piece(id: NodeId, caster: &ShadowCaster, plane: &ShadowPlane, faces: &[Range< let mut fill = FillLayer::new(Paint::solid(Color::BLACK)); fill.opacity = SHADOW_OPACITY * ink.opacity.clamp(0.0, 1.0); fill.blend = ink.blend; - Some(Node::path(id, path, Appearance { items: vec![AppearanceItem::Fill(fill)], ..Default::default() })) + let blur = plane.blur(); + let effects = if blur >= MIN_BLUR { vec![Effect { id: "blur.gaussian".into(), params: json!({"radius": blur}), visible: true }] } else { vec![] }; + Some(Node::path(id, path, Appearance { items: vec![AppearanceItem::Fill(fill)], effects, ..Default::default() })) } /// Whether `a` and `b` are the same objects' scopes (each member holds its own copies). diff --git a/crates/effects/src/solids/tests_shadow.rs b/crates/effects/src/solids/tests_shadow.rs index d24cd6e86f..2d82d571c8 100644 --- a/crates/effects/src/solids/tests_shadow.rs +++ b/crates/effects/src/solids/tests_shadow.rs @@ -87,6 +87,40 @@ fn the_shadow_moves_with_its_settings() { } } +/// The radius of the Gaussian Blur on shadow `n`; `None` without one. +fn shadow_blur(n: &Node) -> Option { + match n.appearance.effects.as_slice() { + [] => None, + [e] if e.id == "blur.gaussian" && e.visible => e.params["radius"].as_f64(), + other => panic!("unexpected effects on the shadow: {other:?}"), + } +} + +/// The first light's Softness blurs the shadow, more with Softness and with Distance from Object; +/// at 0 % it stays the hard-edged path. A list of lights takes the first light's Softness. +#[test] +fn the_first_lights_softness_blurs_the_shadow() { + for id in CASTING { + let blur = |params: Value| { + let mut n = square_node(1, 0.0); + n.appearance.effects.push(crate::new_effect(id, ¶ms).unwrap()); + let lit = art(&n, id).unwrap(); + let shadow = &lit.children().unwrap()[0]; + assert!(is_shadow(shadow), "{id} {params}"); + shadow_blur(shadow) + }; + assert_eq!(blur(json!({"shadow": true})), None, "{id}: hard at 0 %"); + let soft = blur(json!({"shadow": true, "lightSoftness": 50})).unwrap_or_else(|| panic!("{id}")); + let softer = blur(json!({"shadow": true, "lightSoftness": 100})).unwrap(); + let far = blur(json!({"shadow": true, "lightSoftness": 100, "shadowDistance": 100})).unwrap(); + assert!(soft > 0.0 && softer > soft && far > softer, "{id}: {soft} {softer} {far}"); + let first = json!({"shadow": true, "lightSoftness": 0, "lights": [{"softness": 100}, {"softness": 0}]}); + assert_eq!(blur(first), Some(softer), "{id}: the first light's"); + let second = json!({"shadow": true, "lightSoftness": 100, "lights": [{"softness": 0}, {"softness": 100}]}); + assert_eq!(blur(second), None, "{id}: only the first light casts"); + } +} + #[test] fn shadow_settings_out_of_range_or_of_the_wrong_kind_are_refused() { for id in CASTING { @@ -203,6 +237,26 @@ fn the_shadows_of_every_fill_go_behind_every_fill_s_solid() { } } +/// A fill's own 3D effect blurs its shadow by the light's Softness too, and the effects after it +/// in the fill's list follow the blur. +#[test] +fn a_fills_own_3d_effect_keeps_the_blur_below_its_later_effects() { + for id in CASTING { + for later in [None, Some(crate::new_effect("distort.roughen", &json!({})).unwrap())] { + let mut n = square_node(1, 0.0); + let fill = n.appearance.items.iter_mut().find(|i| matches!(i, AppearanceItem::Fill(_))).unwrap(); + fill.effects_mut().push(crate::new_effect(id, &json!({"shadow": true, "lightSoftness": 100})).unwrap()); + fill.effects_mut().extend(later.clone()); + let lit = art(&n, id).unwrap_or_else(|| panic!("{id}")); + let shadow = &lit.children().unwrap()[0]; + assert!(is_shadow(shadow), "{id}"); + let ids: Vec<&str> = shadow.appearance.effects.iter().map(|e| e.id.as_str()).collect(); + let want: Vec<&str> = std::iter::once("blur.gaussian").chain(later.as_ref().map(|e| e.id.as_str())).collect(); + assert_eq!(ids, want, "{id}"); + } + } +} + #[test] fn expand_appearance_keeps_the_shadow_as_a_path() { for id in CASTING { diff --git a/crates/effects/src/tests/rasterfollow.rs b/crates/effects/src/tests/rasterfollow.rs index 26399fe162..e463fb5332 100644 --- a/crates/effects/src/tests/rasterfollow.rs +++ b/crates/effects/src/tests/rasterfollow.rs @@ -816,8 +816,8 @@ fn a_groups_transform_applies_after_its_members_own() { } /// An object's Transform effect transforms the raster effects of its fills and strokes with the -/// art, whatever its options: drawn, drawn through the art an option makes, and baked. One that -/// makes copies leaves them. +/// art, whatever its options: drawn, drawn through the art an option makes, and baked. For one that +/// makes copies, see [`each_copy_of_an_objects_transform_carries_its_fills_or_strokes_shadow`]. #[test] fn an_objects_transform_moves_its_fills_shadows() { let cases = [ @@ -825,7 +825,6 @@ fn an_objects_transform_moves_its_fills_shadows() { (json!({"scaleH": 200, "scaleV": 100, "strokes": true}), (20.0, 10.0)), (json!({"rotate": 90, "patterns": true}), (10.0, -10.0)), (json!({"rotate": 90, "strokes": true}), (10.0, -10.0)), - (json!({"scaleH": 200, "scaleV": 200, "copies": 1}), (10.0, 10.0)), ]; for (params, want) in cases { let mut n = fill_square(40, vec![shadow(10.0, 10.0, 0.0)]); @@ -1217,6 +1216,169 @@ fn copies_past_the_budget_each_keep_their_shadow() { assert_eq!(shadows_in(&art).len(), paths); } +/// `n` with only its fill (or only a 4 pt blue stroke, with `stroke`), whose own effects are +/// `effects`. +fn one_row(mut n: Node, stroke: bool, effects: Vec) -> Node { + let mut item = if stroke { + vectorcraft_doc::AppearanceItem::Stroke(vectorcraft_doc::StrokeLayer::new(Paint::solid(Color::rgb(0.0, 0.0, 1.0)), 4.0)) + } else { + n.appearance.items.remove(0) + }; + *item.effects_mut() = effects; + n.appearance.items = vec![item]; + n +} + +/// A case of [`copying_cases`]: the params, each copy's offset and each copy's blur. +type CopyingCase = (Value, Vec<(f64, f64)>, Vec); + +/// The cases of a Transform effect that makes copies with a drop shadow (10, 0) and a blur of 4 +/// before it: the params, each copy's offset and each copy's blur, the last copy first. +fn copying_cases() -> Vec { + vec![ + (json!({"moveH": 100, "copies": 2}), vec![(10.0, 0.0), (10.0, 0.0), (10.0, 0.0)], vec![4.0, 4.0, 4.0]), + // A turn of 90° counterclockwise on screen takes an offset to the right to one upward. + (json!({"rotate": 90, "copies": 2}), vec![(-10.0, 0.0), (0.0, -10.0), (10.0, 0.0)], vec![4.0, 4.0, 4.0]), + (json!({"reflectX": true, "moveH": 100, "copies": 1}), vec![(-10.0, 0.0), (10.0, 0.0)], vec![4.0, 4.0]), + (json!({"scaleH": 200, "scaleV": 200, "moveH": 100, "copies": 1}), vec![(20.0, 0.0), (10.0, 0.0)], vec![8.0, 4.0]), + // Scale Strokes & Effects does not scale the shadow a second time, nor leave it unturned. + ( + json!({"scaleH": 200, "scaleV": 200, "rotate": 90, "moveH": 100, "copies": 1, "strokes": true}), + vec![(0.0, -20.0), (10.0, 0.0)], + vec![8.0, 4.0], + ), + ( + json!({"scaleH": 200, "scaleV": 200, "rotate": 90, "moveH": 100, "copies": 1, "patterns": true}), + vec![(0.0, -20.0), (10.0, 0.0)], + vec![8.0, 4.0], + ), + ] +} + +/// Check that `n` is drawn, expanded and baked as `want.len()` paths, each with one shadow at the +/// offset and blur `want` and `blurs` give it, the last copy first. +fn assert_copies_carry(n: &Node, want: &[(f64, f64)], blurs: &[f64], what: &str) { + assert!(crate::has_transform_art(n), "{what}"); + for (how, art) in + [("drawn", crate::reshape(None, n, None).unwrap()), ("expanded", expand_outlined(None, n, None).unwrap()), ("baked", baked(n.clone()))] + { + assert_eq!(paths_in(&art), want.len(), "{what}: {how} {art:?}"); + let drawn = shadows_in(&art); + assert!(near(&drawn, want), "{what}: {how} {drawn:?}"); + let b = shadow_blurs_in(&art); + assert!(b.len() == blurs.len() && b.iter().zip(blurs).all(|(x, y)| (x - y).abs() < 1e-9), "{what}: {how} blurs {b:?}"); + } +} + +/// A fill's or stroke's own Transform effect that makes copies gives each copy the shadow listed +/// before it in that fill's or stroke's effects, moved, turned, reflected and scaled with that copy, +/// the last copy lowest: drawn, expanded and baked. The original keeps the shadow as it is. +#[test] +fn each_copy_of_a_fills_or_strokes_own_transform_carries_the_shadow_before_it() { + for stroke in [false, true] { + for (params, want, blurs) in copying_cases() { + let n = one_row(square(95, vec![]), stroke, vec![shadow(10.0, 0.0, 4.0), transform(params.clone())]); + assert_copies_carry(&n, &want, &blurs, &format!("stroke {stroke}: {params}")); + } + // A Transform effect that makes copies before the shadow: its copies make one piece, which + // the Transform effect after the shadow copies, each copy with its own shadow. + let effects = + vec![transform(json!({"moveV": 100, "copies": 1})), shadow(10.0, 0.0, 4.0), transform(json!({"rotate": 90, "moveH": 200, "copies": 1}))]; + let n = one_row(square(95, vec![]), stroke, effects); + assert!(crate::has_transform_art(&n), "stroke {stroke}"); + for (how, art) in + [("drawn", crate::reshape(None, &n, None).unwrap()), ("expanded", expand_outlined(None, &n, None).unwrap()), ("baked", baked(n.clone()))] + { + let drawn = shadows_in(&art); + assert!(near(&drawn, &[(0.0, -10.0), (10.0, 0.0)]), "stroke {stroke}: two copying Transform effects, {how} {drawn:?}"); + } + } +} + +/// A Transform effect that makes copies, listed after a fill's or stroke's first Transform effect +/// with Transform Patterns on, gives each copy the shadow listed before it, as the first one's +/// copies do, with or without options of its own: drawn, expanded and baked. +#[test] +fn each_copy_of_a_later_copying_transform_carries_the_shadow_before_it() { + for stroke in [false, true] { + for (params, want, blurs) in copying_cases() { + let effects = vec![transform(json!({"patterns": true})), shadow(10.0, 0.0, 4.0), transform(params.clone())]; + let n = one_row(square(102, vec![]), stroke, effects); + assert_copies_carry(&n, &want, &blurs, &format!("stroke {stroke}: {params}")); + } + } +} + +/// A fill's or stroke's shadow under its object's Transform effect that makes copies is carried by +/// each copy, moved, turned, reflected and scaled with it: for a single fill, a single stroke, and +/// a fill and a stroke that paint each copy below the one before. Drawn, expanded and baked. +#[test] +fn each_copy_of_an_objects_transform_carries_its_fills_or_strokes_shadow() { + for (params, want, blurs) in copying_cases() { + for stroke in [false, true] { + let mut n = one_row(square(96, vec![]), stroke, vec![shadow(10.0, 0.0, 4.0)]); + n.appearance.effects = vec![transform(params.clone())]; + assert_copies_carry(&n, &want, &blurs, &format!("stroke {stroke}: {params}")); + } + // Both a fill and a stroke: only the fill has the shadow. + let mut n = square(97, vec![transform(params.clone())]); + if let Some(vectorcraft_doc::AppearanceItem::Stroke(s)) = n.appearance.items.get_mut(1) { + s.paint = Paint::solid(Color::BLACK); + s.width = 2.0; + } + *n.appearance.items[0].effects_mut() = vec![shadow(10.0, 0.0, 4.0)]; + assert!(crate::has_transform_art(&n), "{params}"); + for (how, art) in + [("drawn", crate::reshape(None, &n, None).unwrap()), ("expanded", expand_outlined(None, &n, None).unwrap()), ("baked", baked(n.clone()))] + { + let drawn = shadows_in(&art); + assert!(near(&drawn, &want), "layered {params}: {how} {drawn:?}"); + } + } +} + +/// A shadow listed after a fill's own Transform effect that makes copies paints once around all of +/// them, and one listed before it on each copy. A Transform effect that makes no copies, or has +/// Transform Objects off, draws the fill as before, without art. +#[test] +fn a_fills_shadow_after_its_own_copying_transform_paints_once_around_the_copies() { + let effects = vec![shadow(10.0, 0.0, 0.0), transform(json!({"rotate": 90, "copies": 1})), shadow(0.0, 5.0, 0.0)]; + let n = one_row(square(98, vec![]), false, effects); + for (how, art) in + [("drawn", crate::reshape(None, &n, None).unwrap()), ("expanded", expand_outlined(None, &n, None).unwrap()), ("baked", baked(n.clone()))] + { + assert!(near(&shadows_in(&art), &[(0.0, 5.0), (0.0, -10.0), (10.0, 0.0)]), "{how}: {:?}", shadows_in(&art)); + assert_eq!(paths_in(&art), 2, "{how}"); + } + for params in [json!({"rotate": 90}), json!({"rotate": 90, "copies": 1, "objects": false})] { + let n = one_row(square(99, vec![]), false, vec![shadow(10.0, 0.0, 0.0), transform(params.clone())]); + assert!(!crate::has_transform_art(&n), "{params}"); + assert!(!crate::has_copied_row_raster(&n), "{params}"); + } + // A shadow between two Transform effects that make copies paints on what the second one + // copies, so the fill is drawn as before, without art. + let copies = transform(json!({"rotate": 90, "copies": 1})); + let n = one_row(square(99, vec![]), false, vec![shadow(10.0, 0.0, 0.0), copies.clone(), shadow(0.0, 5.0, 0.0), copies]); + assert!(!crate::has_copied_row_raster(&n)); + assert!(!crate::has_transform_art(&n)); +} + +/// Copies of a fill's own Transform effect that stop at the effect budget each keep their shadow, +/// and so do those of an object's Transform effect for its fill's shadow. +#[test] +fn row_copies_past_the_budget_each_keep_their_shadow() { + let copies = transform(json!({"moveV": 50, "copies": 1000})); + let own = one_row(path_node(100, wavy(30_000), vec![]), false, vec![shadow(1.0, 0.5, 0.0), copies.clone()]); + let mut owner = one_row(path_node(101, wavy(30_000), vec![]), false, vec![shadow(1.0, 0.5, 0.0)]); + owner.appearance.effects = vec![copies]; + for n in [own, owner] { + let art = crate::reshape(None, &n, None).unwrap(); + let paths = paths_in(&art); + assert!(paths > 1 && paths < 1001, "{paths}"); + assert_eq!(shadows_in(&art).len(), paths); + } +} + /// Black 40 pt "IIII" with its baseline at (5, 60) and `effects`. fn type_node(id: u64, effects: Vec) -> Node { use vectorcraft_doc::text::{CharStyle, TextObject}; @@ -1309,3 +1471,44 @@ fn type_with_a_reshaped_fill_keeps_one_shadow_around_its_copies() { })); assert_eq!(crate::outer_effects(&filled).len(), 2); } + +/// Type whose own fill's Transform effect makes copies is drawn as its outlines, and each copy +/// carries the shadow listed before that Transform effect, as a path's copies do: for the fill's +/// first Transform effect and for one listed after a Transform effect with Transform Patterns on. +/// Drawn, expanded and baked. +#[test] +fn type_carries_its_fills_shadow_on_each_copy() { + let filled = |mut n: Node, effects: Vec| { + n.appearance.items.push(vectorcraft_doc::AppearanceItem::Fill(vectorcraft_doc::FillLayer { + effects, + ..vectorcraft_doc::FillLayer::new(Paint::solid(Color::BLACK)) + })); + n + }; + let copying = vec![shadow(10.0, 0.0, 0.0), transform(json!({"moveH": 100, "copies": 1}))]; + if !crate::outline_text(&type_node(95, vec![])).is_some_and(|o| paths_in(&o) > 0) { + eprintln!("type skipped: built without fonts (enable vectorcraft-text's bundled-fonts to run it)"); + return; + } + let later = vec![transform(json!({"patterns": true})), shadow(10.0, 0.0, 0.0), transform(json!({"moveH": 100, "copies": 1}))]; + for (what, effects) in [("first", copying), ("later", later)] { + let n = filled(type_node(95, vec![]), effects); + for (how, art) in + [("drawn", crate::reshape(None, &n, None)), ("expanded", expand_outlined(None, &n, None)), ("baked", Some(baked(n.clone())))] + { + let art = art.unwrap_or_else(|| panic!("{what}: {how}")); + assert!(near(&shadows_in(&art), &[(10.0, 0.0), (10.0, 0.0)]), "{what}: {how} {:?}", shadows_in(&art)); + // The two shadows are on two objects 100 pt apart: the type and its copy. + let mut lefts = vec![]; + art.walk(&mut |m| { + let lists = std::iter::once(&m.appearance.effects).chain(m.appearance.items.iter().map(|i| i.effects())); + let shadows = lists.map(|l| l.iter().filter(|e| e.id == "stylize.dropShadow").count()).sum::(); + if let Some(b) = m.geometric_bounds() { + lefts.extend(std::iter::repeat_n(b.x0, shadows)); + } + }); + lefts.sort_by(f64::total_cmp); + assert!(lefts.len() == 2 && (lefts[1] - lefts[0] - 100.0).abs() < 1e-6, "{what}: {how} {lefts:?}"); + } + } +} diff --git a/crates/engine/src/cmd/clipboard/resources.rs b/crates/engine/src/cmd/clipboard/resources.rs index fdaeddf39d..f912fce7ae 100644 --- a/crates/engine/src/cmd/clipboard/resources.rs +++ b/crates/engine/src/cmd/clipboard/resources.rs @@ -703,7 +703,7 @@ impl Relink { self.name(Res::ParaStyle, s); } } - for r in [&mut l.values_rows, &mut l.categories_rows, &mut l.legend_rows].into_iter().flatten() { + for r in [&mut l.values_rows, &mut l.categories_rows, &mut l.legend_rows, &mut l.axis_rows, &mut l.ring_rows].into_iter().flatten() { r.paint.fill.iter_mut().chain(r.paint.stroke.iter_mut()).for_each(|p| self.paint(p)); } } diff --git a/crates/engine/src/cmd/effectcmd.rs b/crates/engine/src/cmd/effectcmd.rs index c5e5969247..cbe942183a 100644 --- a/crates/engine/src/cmd/effectcmd.rs +++ b/crates/engine/src/cmd/effectcmd.rs @@ -1089,6 +1089,27 @@ fn expand_pieces( expanded } +/// `m`, the art a 3D effect expanded into, with each object in it that has effects of its own (a +/// shadow blurred by the light's Softness) expanded as Expand Appearance expands it on its own: +/// a blurred shadow becomes an image. Groups in `m` without effects that hold such an object are +/// looked into; the rest are left as they are. The objects `skip` lists are not expanded. +fn expand_raster_pieces(d: &mut Document, mut m: Node, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId], raster: &mut RasterBudget) -> Node { + for c in m.children_mut().into_iter().flatten() { + if !c.appearance.effects.is_empty() { + if let Some(e) = expanded_node(d, (**c).clone(), brushes, skip, &mut vec![], raster) { + *c = Arc::new(e); + } + } else if c.children().is_some() { + let mut holds = false; + c.walk(&mut |n| holds |= !n.appearance.effects.is_empty()); + if holds { + *c = Arc::new(expand_raster_pieces(d, (**c).clone(), brushes, skip, raster)); + } + } + } + m +} + /// Replace each symbol instance in `m`, art an instance placed (`depth` instances deep), whose /// active fill or stroke has a geometry or raster effect ([`effects::has_item_geometry`], /// [`effects::has_instance_row_raster`]) by its art ([`expanded_instance`]), and the instances in @@ -1353,6 +1374,9 @@ fn expanded_node( m }) }; + // A 3D effect's shadow blurred by the light's Softness keeps its blur in the art: it + // expands in turn, to an image. + let m = if effects::has_solid(&v) || effects::has_revolve(&v) { m.map(|m| expand_raster_pieces(d, m, brushes, skip, raster)) } else { m }; match image { Some((image, _)) => { let mut m = m.unwrap_or(v); diff --git a/crates/engine/src/cmd/effectcmd/tests.rs b/crates/engine/src/cmd/effectcmd/tests.rs index f7e7206c57..5a1146f28f 100644 --- a/crates/engine/src/cmd/effectcmd/tests.rs +++ b/crates/engine/src/cmd/effectcmd/tests.rs @@ -1017,6 +1017,49 @@ fn a_3d_shadow_is_one_undo_step_saved_exported_and_expanded() { assert_eq!(shadows, 1); } +/// With the light's Softness, the 3D shadow is blurred: the canvas paints past the hard shadow's +/// edge, the object's bounds take the blur in, SVG export blurs it as it does a Gaussian Blur +/// effect, and Expand Appearance keeps it as an image with no live effect left. +#[test] +fn a_soft_3d_shadow_is_drawn_measured_exported_and_expanded_blurred() { + let (mut s, id) = session_with_rect(); + s.execute("effect.apply", &json!({"effect": effects::EXTRUDE, "ids": [id.0], "item": null})).unwrap(); + let set = |s: &mut Session, params: serde_json::Value| { + s.execute("effect.setParams", &json!({"ids": [id.0], "index": 0, "item": null, "params": params})).unwrap(); + }; + let draw = |s: &Session| { + vectorcraft_render::Renderer::new().render(&s.doc().unwrap().doc, 400, 400, vectorcraft_geom::Affine::IDENTITY, &Default::default()).pixels + }; + let bounds = |s: &Session| { + let doc = &s.doc().unwrap().doc; + vectorcraft_render::effect_bounds(&doc.symbol_boxes(), doc.node(id).unwrap()).unwrap() + }; + let blurs = |s: &mut Session| { + let svg = s.execute("document.serialize", &json!({"format": "svg"})).unwrap(); + let svg = svg["data"].as_str().or_else(|| svg["text"].as_str()).map(str::to_string).unwrap_or_else(|| svg.to_string()); + svg.matches(" 100, "{spread}"); + assert!(soft_bounds.contains_rect(hard_bounds) && soft_bounds.area() > hard_bounds.area(), "{hard_bounds:?} {soft_bounds:?}"); + assert_eq!(blurs(&mut s), hard_blurs + 1, "SVG export blurs the shadow as a Gaussian Blur effect"); + s.execute("effect.expandAppearance", &json!({"ids": [id.0]})).unwrap(); + let (mut live, mut pictures) = (0, 0); + s.doc().unwrap().doc.walk(|n| { + live += usize::from(!n.appearance.effects.is_empty() || n.appearance.items.iter().any(|i| !i.effects().is_empty())); + pictures += usize::from(matches!(n.kind, NodeKind::Image(_))); + }); + assert_eq!((live, pictures), (0, 1), "the blurred shadow expands to an image"); +} + /// Radial Blur's Blur Center: stored as given, drawn about that point of the object's bounds, and /// a value outside 0 to 1 (or not a number) is refused with nothing changed and no undo step. #[test] diff --git a/crates/engine/src/cmd/fileio.rs b/crates/engine/src/cmd/fileio.rs index d8c9074001..6817f28b35 100644 --- a/crates/engine/src/cmd/fileio.rs +++ b/crates/engine/src/cmd/fileio.rs @@ -129,9 +129,9 @@ mod commands; mod export_names; mod formats; -pub(crate) use access::check_images_in; #[cfg(not(target_arch = "wasm32"))] pub(crate) use access::list_dir; +pub(crate) use access::{check_images_in, check_scripts_of}; pub use access::{check_linked_images, check_linked_scripts, write_file_with, write_save_file, write_save_file_with}; #[cfg(all(test, not(target_arch = "wasm32")))] diff --git a/crates/engine/src/cmd/fileio/access.rs b/crates/engine/src/cmd/fileio/access.rs index 856656f564..9d2d9a4a33 100644 --- a/crates/engine/src/cmd/fileio/access.rs +++ b/crates/engine/src/cmd/fileio/access.rs @@ -121,22 +121,54 @@ pub(crate) fn naming_in_message(msg: &str, path: &str, name: &str) -> String { out } -/// The error for an SVG of a document that links a JavaScript file outside the read roots. +/// The error for a file that would name a JavaScript file the document links outside the read roots. pub(crate) const SCRIPT_OUTSIDE: &str = "a linked JavaScript file is outside the read roots"; -/// `cmd` may write `st`'s document in format `format` (a format id): any format but SVG and SVGZ, -/// and those too unless read roots are in force and the document links a JavaScript file outside -/// them (`svg_scripts`, a relative path taken from the document's folder; a URL is not checked), -/// which the file's `