diff --git a/crates/effects/src/lib.rs b/crates/effects/src/lib.rs index aa95c8cfdd..6c6bec1387 100644 --- a/crates/effects/src/lib.rs +++ b/crates/effects/src/lib.rs @@ -87,8 +87,8 @@ pub use raster::{ }; 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, needs_outline, outer_effects, outline_art, - outline_text, paint_type_piece, reshape, + 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 de528cec8d..172eab2348 100644 --- a/crates/effects/src/reshape.rs +++ b/crates/effects/src/reshape.rs @@ -900,6 +900,16 @@ pub fn expand_outlined(doc: Option<&Document>, n: &Node, symbol_art: Option<&Nod as_art(doc, n, symbol_art) } +/// Symbol instance `n` as plain art for Expand Appearance, with or without geometry effects: the +/// art it places, reshaped by those effects when it has some, in the form [`expand_outlined`] +/// gives. `None` for other kinds of objects and for an instance without `symbol_art`. +pub fn instance_as_art(doc: Option<&Document>, n: &Node, symbol_art: Option<&Node>) -> Option { + if !matches!(n.kind, NodeKind::SymbolInstance { .. }) { + return None; + } + as_art(doc, n, symbol_art) +} + /// [`reshape`] without its checks (no geometry effects: just the art). pub(crate) fn as_art(doc: Option<&Document>, n: &Node, symbol_art: Option<&Node>) -> Option { as_art_with(doc, doc, n, symbol_art, &outline_text, &SymbolNodes::default()) diff --git a/crates/engine/src/cmd/effectcmd.rs b/crates/engine/src/cmd/effectcmd.rs index 1f471d84a3..c5e5969247 100644 --- a/crates/engine/src/cmd/effectcmd.rs +++ b/crates/engine/src/cmd/effectcmd.rs @@ -97,7 +97,7 @@ fn effect_specs() -> Vec { "Expand Appearance", ["Object"], None, - "{ids?|id?: [..], target?} turn each object's appearance into objects: every fill and stroke becomes an object of its own (a stroke stays a stroke, with its weight, dashes, arrowheads and width profile, on its own copy of the path, which object.expand or object.path.outlineStroke outline; brushed strokes become their brush art) grouped in paint order under the object's id and transparency, geometry effects are baked, raster effects become an embedded image (shadows and outer glows below the art; blur, feather and inner glow replace it; an object whose only raster effect is its own Rasterize becomes the image object.rasterize makes with the effect's options), type with effects or fills of its own is outlined; Crop Marks become a group of the object and its marks; Vector Halftone (addon.color.halftone) becomes a group of its dot paths, one per ink; a group's or layer's own fills and strokes become objects among its members, which are expanded too; a symbol instance whose topmost fill or stroke is visible, has an opacity above 0 and has a geometry effect becomes a group of its art, that fill's effects reshaping the art's filled shapes and that stroke's effects reshaping its stroked shapes, as the canvas draws them. An outlined frame of threaded text leaves its thread with the text it shows, and a frame kept as type in a group stays in its thread. A dimension whose art it changes becomes a plain group of its art, except one selected with art it measures, directly or in groups without fills, strokes or effects of their own: its lines and label stay as they are, and if the new art no longer fits its link it stays where it was, no longer linked. Hidden fills, strokes and effects are dropped. In Safe Mode, an object with a visible plug-in effect (in it, or in a symbol it places) is an error and nothing changes. Enabled when a selected or targeted object's appearance isn't basic (`ids` then pick which objects) → {ids, warning? (an image in the art couldn't be decoded, as object.rasterize says)}", + "{ids?|id?: [..], target?} turn each object's appearance into objects: every fill and stroke becomes an object of its own (a stroke stays a stroke, with its weight, dashes, arrowheads and width profile, on its own copy of the path, which object.expand or object.path.outlineStroke outline; brushed strokes become their brush art) grouped in paint order under the object's id and transparency, geometry effects are baked, raster effects become an embedded image (shadows and outer glows below the art; blur, feather and inner glow replace it; an object whose only raster effect is its own Rasterize becomes the image object.rasterize makes with the effect's options), type with effects or fills of its own is outlined; Crop Marks become a group of the object and its marks; Vector Halftone (addon.color.halftone) becomes a group of its dot paths, one per ink; a group's or layer's own fills and strokes become objects among its members, which are expanded too; a symbol instance whose topmost fill or stroke is visible, has an opacity above 0 and has a geometry or raster effect becomes a group of its art, that fill's effects reshaping the art's filled shapes and that stroke's effects reshaping its stroked shapes, as the canvas draws them, its raster effects an image as for other objects; a symbol instance in that art whose topmost fill or stroke has such an effect (its own or one the outer instance passes on) becomes its art and image in turn. An outlined frame of threaded text leaves its thread with the text it shows, and a frame kept as type in a group stays in its thread. A dimension whose art it changes becomes a plain group of its art, except one selected with art it measures, directly or in groups without fills, strokes or effects of their own: its lines and label stay as they are, and if the new art no longer fits its link it stays where it was, no longer linked. Hidden fills, strokes and effects are dropped. One expansion makes at most 1,024 images of raster effects, 256 megapixels in all (VectorCraft's own limits): an object or symbol instance whose image would go past them stays as it is, with its effects, and when nothing else expands that is an error. In Safe Mode, an object with a visible plug-in effect (in it, or in a symbol it places) is an error and nothing changes. Enabled when a selected or targeted object's appearance isn't basic (`ids` then pick which objects) → {ids, warning? (an image in the art couldn't be decoded, as object.rasterize says; or raster effects were left past the limits), rasterLeft? (how many objects were left so)}", can_expand, expand_appearance ), @@ -963,16 +963,74 @@ fn is_container(n: &Node) -> bool { /// The raster effects of `n` (its own, its fills' and strokes') as an embedded image rendered at /// the document's raster effects resolution or a Rasterize effect's finer one, with whether they -/// all paint below it (shadows and outer glows: the image then holds just them). A group's or -/// layer's image leaves out its members' raster effects, which are expanded with them. `None` -/// when it has none. -fn raster_image(d: &mut Document, n: &Node) -> Option<(Node, bool)> { +/// all paint below it (shadows and outer glows: the image then holds just them, and paints with +/// their blend mode when they all use one). A group's or layer's image leaves out its members' +/// raster effects, which are expanded with them. `None` when it has none. +/// `Err` when that image would take `budget` past its limits: the object then stays as it is. +fn raster_image(d: &mut Document, n: &Node, budget: &mut RasterBudget) -> std::result::Result, OverBudget> { let fx = rasterfx::raster_fx(n); if fx.is_empty() { - return None; + return Ok(None); } let below = fx.iter().all(effects::RasterFx::is_below); - Some((rasterfx::raster_image(d, n, below, true)?, below)) + let pixels = budget.take(rasterfx::raster_pixels(d, n, below, true))?; + let mut image = rasterfx::raster_image(d, n, below, true); + if image.is_none() { + // No image was made: it takes nothing from the budget. + budget.images += 1; + budget.pixels += pixels; + } + // Rendered alone, over nothing, the shadows and glows can't blend with the art below the + // object, so the image does, as the canvas draws them. + let mut modes = fx.iter().filter_map(effects::RasterFx::mode); + if below + && let (Some(mode), Some(image)) = (modes.next(), image.as_mut()) + && modes.all(|m| m == mode) + { + image.blend = mode; + } + Ok(image.map(|image| (image, below))) +} + +/// The most images of raster effects one Expand Appearance makes. +const MAX_RASTER_IMAGES: u32 = 1_024; + +/// The most pixels the images of raster effects one Expand Appearance makes hold in all. +const MAX_RASTER_PIXELS: u64 = 256_000_000; + +/// The note when objects keep their raster effects because their images would take an Expand +/// Appearance past [`MAX_RASTER_IMAGES`] or [`MAX_RASTER_PIXELS`]. +pub(crate) const RASTER_EFFECTS_LEFT: &str = + "some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all"; + +/// An image of raster effects that would take a [`RasterBudget`] past its limits. +#[derive(Debug)] +struct OverBudget; + +/// What one Expand Appearance has left of [`MAX_RASTER_IMAGES`] and [`MAX_RASTER_PIXELS`], and the +/// objects whose raster effects it left as they are because their images would go past them. +pub(crate) struct RasterBudget { + images: u32, + pixels: u64, + pub(crate) left: usize, +} + +impl RasterBudget { + pub(crate) fn new() -> Self { + Self { images: MAX_RASTER_IMAGES, pixels: MAX_RASTER_PIXELS, left: 0 } + } + + /// Take an image of `pixels` ([`rasterfx::raster_pixels`]) before it is made, and return + /// them; `Err`, with its object counted in `left`, when it would go past what is left. + fn take(&mut self, pixels: u64) -> std::result::Result { + if self.images == 0 || pixels > self.pixels { + self.left += 1; + return Err(OverBudget); + } + self.images -= 1; + self.pixels -= pixels; + Ok(pixels) + } } /// Expand the pieces of `m`, art evaluated from the object of the same id (its pieces share that @@ -983,6 +1041,7 @@ fn raster_image(d: &mut Document, n: &Node) -> Option<(Node, bool)> { /// pieces with the ids they have before that. `kept` gets the new id of each object in them that /// had an id `skip` lists before. Returns what each of those other members' expansions lists, by /// the member's new id. +#[allow(clippy::too_many_arguments)] fn expand_pieces( d: &mut Document, m: &mut Node, @@ -991,6 +1050,7 @@ fn expand_pieces( skip: &[NodeId], kept: &mut Vec, stroke_art: effects::StrokeArt, + raster: &mut RasterBudget, ) -> std::collections::HashMap> { let id = m.id; let mut seen = std::collections::HashSet::from([id]); @@ -1005,7 +1065,7 @@ fn expand_pieces( if all || c.id == id { effects::expand_art(d, c, stroke_art); } else if has_seeded(c) && repeats_an_id(c, &seen) { - listed = Some(expand_in_place(d, c, brushes, skip)); + listed = Some(expand_in_place(d, c, brushes, skip, raster)); } let mut was = vec![]; if !skip.is_empty() { @@ -1030,37 +1090,65 @@ fn expand_pieces( } /// Replace each symbol instance in `m`, art an instance placed (`depth` instances deep), whose -/// active fill or stroke has a geometry effect ([`effects::has_item_geometry`]) by its art as -/// [`effects::expand_outlined`] makes it, and the instances in that art in turn, so -/// [`expand_pieces`] bakes their effects with the rest. An instance stays as it is when it is more -/// than [`vectorcraft_doc::depth::MAX_DEPTH`] instances deep, its symbol is missing, or its art -/// would take the objects placed so far past `budget`. -fn expand_nested_instances(d: &Document, m: &mut Node, depth: usize, budget: &mut u64) { +/// 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 +/// that art in turn, so [`expand_pieces`] bakes their effects with the rest. +fn expand_nested_instances(d: &mut Document, m: &mut Node, depth: usize, budget: &mut u64, raster: &mut RasterBudget) { for c in m.children_mut().into_iter().flatten() { if !matches!(c.kind, NodeKind::SymbolInstance { .. }) { if c.children().is_some() { - expand_nested_instances(d, Arc::make_mut(c), depth, budget); + expand_nested_instances(d, Arc::make_mut(c), depth, budget, raster); } continue; } - let NodeKind::SymbolInstance { symbol, .. } = &c.kind else { continue }; - if depth >= vectorcraft_doc::depth::MAX_DEPTH || !effects::has_item_geometry(c) { - continue; - } - let Some(sym) = d.symbols.iter().find(|s| s.name == *symbol) else { continue }; - let count = sym.art.count() as u64; - if count > *budget { - continue; - } - *budget -= count; - let art = vectorcraft_render::instance_art(&sym.art, c); - if let Some(mut a) = effects::expand_outlined(Some(d), c, Some(&art)) { - expand_nested_instances(d, &mut a, depth + 1, budget); + if let Some(a) = expanded_instance(d, c, depth, budget, raster) { *c = Arc::new(a); } } } +/// Symbol instance `c`, art an instance placed (`depth` instances deep), as art: the raster +/// effects of its active fill or stroke an embedded image ([`raster_image`]) that replaces the art +/// (blur, feather, inner glow) or goes below it (shadows, outer glows), and its art as +/// [`effects::expand_outlined`] makes it without them, or as [`effects::instance_as_art`] does when +/// it has no geometry effect, with the instances in that art expanded in turn. `None`, the instance +/// staying as it is, when its active fill and stroke have no such effect, it is more than +/// [`vectorcraft_doc::depth::MAX_DEPTH`] instances deep, its symbol is missing, or its art would +/// take the objects placed so far past `budget`, or the image of its raster effects would take +/// `raster` past its limits. When that image can't be made, they stay on the art its geometry +/// effects make, and without one it stays as it is. +fn expanded_instance(d: &mut Document, c: &Node, depth: usize, budget: &mut u64, raster: &mut RasterBudget) -> Option { + let NodeKind::SymbolInstance { symbol, .. } = &c.kind else { return None }; + let has_raster = effects::has_instance_row_raster(c); + if depth >= vectorcraft_doc::depth::MAX_DEPTH || !(has_raster || effects::has_item_geometry(c)) { + return None; + } + let sym = d.symbols.iter().find(|s| s.name == *symbol)?; + let count = sym.art.count() as u64; + if count > *budget { + return None; + } + let art = vectorcraft_render::instance_art(&sym.art, c); + let image = if has_raster { raster_image(d, c, raster).ok()? } else { None }; + *budget -= count; + let mut v = c.clone(); + if image.is_some() { + rasterfx::strip_raster(&mut v, false); + } + let below = match image { + Some((image, false)) => return Some(rasterfx::replace_with_image(v, image)), + Some((image, true)) => Some(image), + None => None, + }; + let mut a = effects::expand_outlined(Some(&*d), &v, Some(&art)) + .or_else(|| if below.is_some() { effects::instance_as_art(Some(&*d), &v, Some(&art)) } else { None })?; + expand_nested_instances(d, &mut a, depth + 1, budget, raster); + if let Some(image) = below { + rasterfx::put_below(d, &mut a, image); + } + Some(a) +} + /// Does `n` hold an id of `seen`, or one id twice: does [`effects::fresh_ids`] give it new ids? fn repeats_an_id(n: &Node, seen: &std::collections::HashSet) -> bool { let mut ids = std::collections::HashSet::new(); @@ -1075,9 +1163,9 @@ fn repeats_an_id(n: &Node, seen: &std::collections::HashSet) -> bool { type Listed = (NodeId, usize); /// [`expanded_node`] of `c` in place. Returns what the expansion lists, by places in the walk of `c`. -fn expand_in_place(d: &mut Document, c: &mut Node, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId]) -> Vec { +fn expand_in_place(d: &mut Document, c: &mut Node, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId], raster: &mut RasterBudget) -> Vec { let mut listed = vec![]; - if let Some(e) = expanded_node(d, c.clone(), brushes, skip, &mut listed) { + if let Some(e) = expanded_node(d, c.clone(), brushes, skip, &mut listed, raster) { *c = e; } listed @@ -1099,18 +1187,26 @@ fn fresh_ids_listed(d: &mut Document, c: &mut Node, seen: &mut std::collections: /// Expand Appearance of `id` (and, recursively, of a group's or layer's members): every fill and /// stroke becomes an object of its own (a stroke a path stroked by it alone, brushes as their art), /// geometry effects are baked, raster effects become an embedded image, and the object keeps its -/// transparency. -pub(crate) fn expand_node(d: &mut Document, id: NodeId, brushes: &[vectorcraft_brush::Brush], out: &mut Vec) { - expand_node_except(d, id, brushes, &[], out); +/// transparency. An object whose raster effects' image would take `raster` past its limits stays +/// as it is, with what is inside it. +pub(crate) fn expand_node(d: &mut Document, id: NodeId, brushes: &[vectorcraft_brush::Brush], out: &mut Vec, raster: &mut RasterBudget) { + expand_node_except(d, id, brushes, &[], out, raster); } /// [`expand_node`], leaving the objects `skip` lists, and what they hold, as they are. A geometry /// effect of a group or layer around one still reshapes it with the rest of its members, and the /// copies of it that such an effect makes are left as they are too. -fn expand_node_except(d: &mut Document, id: NodeId, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId], out: &mut Vec) { +fn expand_node_except( + d: &mut Document, + id: NodeId, + brushes: &[vectorcraft_brush::Brush], + skip: &[NodeId], + out: &mut Vec, + raster: &mut RasterBudget, +) { let Some(n) = d.node(id).cloned() else { return }; let mut listed = vec![]; - let m = expanded_node(d, n, brushes, skip, &mut listed); + let m = expanded_node(d, n, brushes, skip, &mut listed, raster); out.extend(listed.into_iter().map(|(id, _)| id)); if let Some(mut m) = m { // Art made from type takes its emoji's pixels into the document. @@ -1124,11 +1220,20 @@ fn expand_node_except(d: &mut Document, id: NodeId, brushes: &[vectorcraft_brush /// [`expand_node`] of `n`, which need not be in `d`: `n` with its appearance expanded, `None` when /// it has nothing to expand. `out` gets the objects whose appearance expands, by places in the walk /// of the expanded `n`, `n`'s first when its own does. The objects `skip` lists are not expanded. -fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId], out: &mut Vec) -> Option { +fn expanded_node( + d: &mut Document, + mut n: Node, + brushes: &[vectorcraft_brush::Brush], + skip: &[NodeId], + out: &mut Vec, + raster: &mut RasterBudget, +) -> Option { let id = n.id; if skip.contains(&id) || !expandable(&n) { return None; } + // What `out` held before `n`: an object left by the raster budget lists nothing. + let listed_before = out.len(); // Colour adjustments: the colours inside become the adjusted ones (an embedded image a // recoloured copy), then the rest of the appearance expands. let mut changed = false; @@ -1141,6 +1246,10 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br } _ => None, }; + // The embedded images before the adjustment, when the raster budget may yet leave `n` as it + // is: the recolored copies the adjustment adds then go again. + let images_before = (effects::has_adjustment(&n) && !rasterfx::raster_fx(&n).is_empty()) + .then(|| d.images.keys().cloned().collect::>()); if effects::has_adjustment(&n) && let Some(m) = effects::adjust_in_document(d, &n, symbol_art) { @@ -1163,7 +1272,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br for (i, c) in m.children_mut().into_iter().flatten().enumerate() { let c = Arc::make_mut(c); if i == 0 { - expanded = expand_in_place(d, c, brushes, skip); + expanded = expand_in_place(d, c, brushes, skip, raster); fresh_ids_listed(d, c, &mut seen, &mut expanded); } else { effects::fresh_ids(d, c, &mut seen); @@ -1186,7 +1295,15 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br } return Some(m); } - let image = raster_image(d, &n); + // Raster effects whose image would go past the budget stay: so does the object, with what is + // inside it and its color adjustments (a symbol instance stays an instance of its symbol). + let Ok(image) = raster_image(d, &n, raster) else { + out.truncate(listed_before); + if let Some(keys) = images_before { + d.images.retain(|k, _| keys.contains(k)); + } + return None; + }; let mut v = n.clone(); rasterfx::strip_raster(&mut v, false); let mut stroke_art = @@ -1206,7 +1323,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br } else if container { // A group's or layer's own fills and strokes become art among its members. effects::evaluate_container(Some(&*d), &v).map(|mut m| { - members = expand_pieces(d, &mut m, false, brushes, skip, &mut kept, &mut stroke_art); + members = expand_pieces(d, &mut m, false, brushes, skip, &mut kept, &mut stroke_art, raster); m }) } else if matches!(n.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) @@ -1224,10 +1341,15 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br } _ => None, }; - effects::expand_outlined(Some(&*d), &v, symbol.as_ref()).map(|mut m| { + // A symbol instance whose active fill or stroke has only effects that paint below it + // (now in the image) becomes its art as well. + let row_raster = image.is_some() && effects::has_instance_row_raster(&n); + let outlined = effects::expand_outlined(Some(&*d), &v, symbol.as_ref()) + .or_else(|| if row_raster { effects::instance_as_art(Some(&*d), &v, symbol.as_ref()) } else { None }); + outlined.map(|mut m| { let mut budget = vectorcraft_doc::MAX_SYMBOL_NODES; - expand_nested_instances(d, &mut m, 1, &mut budget); - expand_pieces(d, &mut m, true, brushes, skip, &mut kept, &mut stroke_art); + expand_nested_instances(d, &mut m, 1, &mut budget, raster); + expand_pieces(d, &mut m, true, brushes, skip, &mut kept, &mut stroke_art, raster); m }) }; @@ -1262,7 +1384,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br match members.remove(&c.id) { Some(listed) => out.extend(listed), None => { - if let Some(e) = expanded_node(d, (**c).clone(), brushes, &skip, out) { + if let Some(e) = expanded_node(d, (**c).clone(), brushes, &skip, out, raster) { *c = Arc::new(e); changed = true; } @@ -1336,6 +1458,7 @@ fn expand_appearance(s: &mut Session, p: &Value) -> Result { } let failed = vectorcraft_render::decode_failures(); let colorized_ok = super::paint::check_colorized(&s.doc()?.doc).is_ok(); + let mut raster = RasterBudget::new(); let ids = s.edit("Expand Appearance", |d, _| { let before = d.clone(); // The art of graph designs in the graphs and series among the roots stays as the graph draws it. A group whose @@ -1351,7 +1474,7 @@ fn expand_appearance(s: &mut Session, p: &Value) -> Result { let mut out = vec![]; let threaded = super::threads::frames(d); for id in &roots { - expand_node_except(d, *id, &brushes, &designs, &mut out); + expand_node_except(d, *id, &brushes, &designs, &mut out, &mut raster); } super::dimension::put_back(d, lifted); // A dimension whose source was replaced stays where it was, no longer linked. @@ -1360,6 +1483,9 @@ fn expand_appearance(s: &mut Session, p: &Value) -> Result { // stays type under a new id takes its frame's place. super::threads::leave_threads(d, &threaded); if out.is_empty() || (kept && d.layers == before.layers) { + if raster.left > 0 { + return Err(EngineError::Other(RASTER_EFFECTS_LEFT.into())); + } return Err(EngineError::Other("Expand Appearance: the selection has a basic appearance".into())); } super::paint::check_colorized_kept(colorized_ok, d).map_err(|e| bad("Expand Appearance", e))?; @@ -1367,8 +1493,12 @@ fn expand_appearance(s: &mut Session, p: &Value) -> Result { })?; let mut out = json!({ "ids": ids_json(&ids) }); // Raster effects become images rendered from the art. - if let Some(w) = rasterfx::undecoded_warning(failed) { - out["warning"] = json!(w); + let warnings: Vec<&str> = rasterfx::undecoded_warning(failed).into_iter().chain((raster.left > 0).then_some(RASTER_EFFECTS_LEFT)).collect(); + if !warnings.is_empty() { + out["warning"] = json!(warnings.join("; ")); + } + if raster.left > 0 { + out["rasterLeft"] = json!(raster.left); } Ok(out) } diff --git a/crates/engine/src/cmd/effectcmd/tests.rs b/crates/engine/src/cmd/effectcmd/tests.rs index b3389e190d..f7e7206c57 100644 --- a/crates/engine/src/cmd/effectcmd/tests.rs +++ b/crates/engine/src/cmd/effectcmd/tests.rs @@ -1082,3 +1082,28 @@ fn radial_blur_center_stays_in_the_object_when_the_stack_splits() { let differ = (0..300 * 300).filter(|i| plain[i * 4 + 3].abs_diff(split[i * 4 + 3]) > 8).count(); assert!(differ < 50, "{differ} pixels' coverage moved with the room around the art"); } + +/// The raster budget charges each image its pixels before it is made: an image past what is left +/// is refused and counted, and the object keeps its blur. +#[test] +fn an_image_past_the_pixels_left_stays_unmade() { + let (mut s, id) = session_with_rect(); + s.execute("effect.apply", &json!({"ids": [id.0], "effect": "blur.gaussian", "params": {"radius": 3}})).unwrap(); + let mut d = s.doc().unwrap().doc.as_ref().clone(); + let n = d.node(id).cloned().unwrap(); + let pixels = super::rasterfx::raster_pixels(&d, &n, false, true); + assert!(pixels > 10_000, "a 100 pt square at 72 ppi: {pixels}"); + + let mut budget = super::RasterBudget { images: 10, pixels: pixels - 1, left: 0 }; + assert!(super::raster_image(&mut d, &n, &mut budget).is_err()); + assert_eq!((budget.images, budget.pixels, budget.left), (10, pixels - 1, 1), "nothing is taken"); + + let mut budget = super::RasterBudget { images: 10, pixels, left: 0 }; + let (image, _) = super::raster_image(&mut d, &n, &mut budget).unwrap().expect("the image is made"); + let NodeKind::Image(img) = &image.kind else { panic!("not an image") }; + assert_eq!(u64::from(img.width) * u64::from(img.height), pixels, "the charge is the image's size"); + assert_eq!((budget.images, budget.pixels, budget.left), (9, 0, 0)); + + let mut budget = super::RasterBudget { images: 0, pixels, left: 0 }; + assert!(super::raster_image(&mut d, &n, &mut budget).is_err(), "no image is left"); +} diff --git a/crates/engine/src/cmd/fileio/legacy_ai.rs b/crates/engine/src/cmd/fileio/legacy_ai.rs index 23168f1e25..028d9fe5a6 100644 --- a/crates/engine/src/cmd/fileio/legacy_ai.rs +++ b/crates/engine/src/cmd/fileio/legacy_ai.rs @@ -142,7 +142,9 @@ pub(super) fn encode(cmd: &str, f: &Format, doc: &Document, p: &Value) -> Result let one = super::save::artboard_doc(doc, b); let (full, placed) = crate::cmd::place::document::full_documents(&one); let mut d = full.into_owned(); - expand_appearances(&mut d); + if expand_appearances(&mut d) { + note(&mut enc.warnings, super::super::effectcmd::RASTER_EFFECTS_LEFT); + } if mode == SeeThrough::Flatten { expand_image_patterns(&mut d)?; } @@ -175,14 +177,17 @@ pub(super) fn encode(cmd: &str, f: &Format, doc: &Document, p: &Value) -> Result Ok(enc) } -/// Expand Appearance of every layer's art whose appearance the format can't hold. -fn expand_appearances(d: &mut Document) { +/// Expand Appearance of every layer's art whose appearance the format can't hold. Returns whether +/// objects kept raster effects whose images would go past Expand Appearance's limits. +fn expand_appearances(d: &mut Document) -> bool { let brushes = vectorcraft_brush::library(d); let layers: Vec = d.layers.iter().map(|l| l.id).collect(); let mut out = vec![]; + let mut raster = super::super::effectcmd::RasterBudget::new(); for id in layers { - super::super::effectcmd::expand_node(d, id, &brushes, &mut out); + super::super::effectcmd::expand_node(d, id, &brushes, &mut out, &mut raster); } + raster.left > 0 } /// Expand every layer's pattern fills that paint an image with see-through pixels, a colorize paint, diff --git a/crates/engine/src/cmd/rasterfx.rs b/crates/engine/src/cmd/rasterfx.rs index 5f412e080d..aaaef531bf 100644 --- a/crates/engine/src/cmd/rasterfx.rs +++ b/crates/engine/src/cmd/rasterfx.rs @@ -174,19 +174,14 @@ pub(crate) fn effects_scale(doc: &Document) -> f64 { (doc.raster_effects_ppi / 72.0).clamp(1.0 / 72.0, 2400.0 / 72.0) } -/// An embedded image (a new node of `out`, its pixels in `out.images`) of `whole` rendered alone -/// with `out`'s resources at `scale` over all it paints (the reach of its own, its members' and its -/// fills' and strokes' raster effects included). With `knockout`, the coverage of that art is knocked out -/// of the image, which then only holds what the effects add around it (a shadow to go under the -/// vector object). The document's raster effects settings add room around it and finish its pixels. -/// `None` when it paints nothing, when the area it covers overflows `f64` or the scale is not -/// positive, or when its PNG can't be encoded. -pub(crate) fn effect_image(out: &mut Document, whole: &Node, knockout: Option<&Node>, scale: f64) -> Option { +/// The region [`effect_image`] renders `whole` over in `d`, and the scale it renders at (`scale`, or +/// less for an image past 64 Mpx or a side the renderer can't address). `None` when it paints +/// nothing, when the area it covers overflows `f64` or the scale is not positive. +fn effect_region(d: &Document, whole: &Node, scale: f64) -> Option<(Rect, f64)> { // What it paints (its members' effects included), and how far its fills' and strokes' raster // effects reach beyond that. - let b = vectorcraft_render::painted_bounds(out, whole)?; - let look = out.raster_effects.clone(); - let reach = whole.appearance.items.iter().map(|i| effects::outset(i.effects(), b)).fold(0.0, f64::max) + 2.0 + look.add_around; + let b = vectorcraft_render::painted_bounds(d, whole)?; + let reach = whole.appearance.items.iter().map(|i| effects::outset(i.effects(), b)).fold(0.0, f64::max) + 2.0 + d.raster_effects.add_around; let b = b.inflate(reach, reach); // An area too large for f64 gives a zero scale and an image transform that is not finite. let area = b.width() * b.height(); @@ -201,6 +196,19 @@ pub(crate) fn effect_image(out: &mut Document, whole: &Node, knockout: Option<&N return None; } let region = Rect::new(b.x0, b.y0, b.x0 + (b.width() * scale).ceil().max(1.0) / scale, b.y0 + (b.height() * scale).ceil().max(1.0) / scale); + Some((region, scale)) +} + +/// An embedded image (a new node of `out`, its pixels in `out.images`) of `whole` rendered alone +/// with `out`'s resources at `scale` over all it paints (the reach of its own, its members' and its +/// fills' and strokes' raster effects included). With `knockout`, the coverage of that art is knocked out +/// of the image, which then only holds what the effects add around it (a shadow to go under the +/// vector object). The document's raster effects settings add room around it and finish its pixels. +/// `None` when it paints nothing, when the area it covers overflows `f64` or the scale is not +/// positive, or when its PNG can't be encoded. +pub(crate) fn effect_image(out: &mut Document, whole: &Node, knockout: Option<&Node>, scale: f64) -> Option { + let (region, scale) = effect_region(out, whole, scale)?; + let look = out.raster_effects.clone(); // Anti-alias off: hard edges (the effects themselves stay smooth). let anti_alias = if look.anti_alias { AntiAlias::Art } else { AntiAlias::None }; let mut img = render(out, vec![whole.clone()], region, scale, anti_alias); @@ -311,6 +319,19 @@ pub(crate) fn raster_image(d: &mut Document, n: &Node, below: bool, members: boo if !below && let Some(image) = rasterize_effect_image(d, n) { return Some(image); } + let whole = effect_art(n, below, members); + let bare = below.then(|| { + let mut b = whole.clone(); + strip_raster(&mut b, false); + b + }); + effect_image(d, &whole, bare.as_ref(), image_scale(d, n)) +} + +/// The art [`raster_image`] renders the raster effects of `n` from with `below` and `members`: +/// `n` without its transparency, a group's or layer's members without their raster effects when +/// both are set. +fn effect_art(n: &Node, below: bool, members: bool) -> Node { let mut whole = n.clone(); (whole.opacity, whole.blend) = (1.0, Default::default()); whole.extras_mut().mask = None; @@ -319,17 +340,39 @@ pub(crate) fn raster_image(d: &mut Document, n: &Node, below: bool, members: boo strip_raster(Arc::make_mut(c), true); } } - let bare = below.then(|| { - let mut b = whole.clone(); - strip_raster(&mut b, false); - b - }); - // A Rasterize effect at a finer resolution than the document's is rendered at its own. - let scale = raster_fx(n) - .iter() - .filter_map(|fx| if let RasterFx::Rasterize(r) = fx { r.ppi } else { None }) - .fold(effects_scale(d), |s, ppi| s.max(ppi / 72.0)); - effect_image(d, &whole, bare.as_ref(), scale) + whole +} + +/// Pixels per point of the image of the raster effects of `n`: the document's raster effects +/// resolution, or a Rasterize effect's finer one, which is rendered at its own. +fn image_scale(d: &Document, n: &Node) -> f64 { + raster_fx(n).iter().filter_map(|fx| if let RasterFx::Rasterize(r) = fx { r.ppi } else { None }).fold(effects_scale(d), |s, ppi| s.max(ppi / 72.0)) +} + +/// The pixels of the image [`raster_image`] makes of the raster effects of `n` in `d` with `below` +/// and `members`, as [`effect_image`] sizes it, or at the resolution and with the room around the +/// art of the object's own Rasterize effect when that is its only one ([`rasterize_effect_image`]); +/// 0 when it paints nothing. +pub(crate) fn raster_pixels(d: &Document, n: &Node, below: bool, members: bool) -> u64 { + if !below && let Some((art, r, _)) = rasterize_effect_art(d, n) { + // Measured as Object › Rasterize measures it. + let scale = r.ppi.unwrap_or(d.raster_effects_ppi) / 72.0; + let side = f64::from(vectorcraft_render::MAX_RASTER_SIDE); + let size = vectorcraft_render::drawn_bounds(d, &art).map(|b| { + let b = b.inflate(r.add_around, r.add_around); + ((b.width() * scale).ceil().max(1.0), (b.height() * scale).ceil().max(1.0)) + }); + // Past Object › Rasterize's limits that image is not made, and the effect's image is. + if let Some((w, h)) = size + && w * h <= super::menucmds::MAX_PIXELS + && w <= side + && h <= side + { + return (w * h) as u64; + } + } + effect_region(d, &effect_art(n, below, members), image_scale(d, n)) + .map_or(0, |(r, scale)| ((r.width() * scale).round() * (r.height() * scale).round()) as u64) } /// The image Object › Rasterize makes of `n` with the options of `n`'s Effect › Rasterize, when @@ -339,15 +382,7 @@ pub(crate) fn raster_image(d: &mut Document, n: &Node, below: bool, members: boo /// the image is made of the art before them and moved by them, as the canvas draws it. `None` /// otherwise, when those Transform effects flatten the image, or when the image can't be made. fn rasterize_effect_image(d: &mut Document, n: &Node) -> Option { - let [RasterFx::Rasterize(r)] = raster_fx(n)[..] else { return None }; - let staged = vectorcraft_render::rasterize_stage(d, n); - if let Some((_, map)) = &staged - && !(map.determinant().is_finite() && map.determinant().abs() > 1e-12) - { - return None; - } - let n = staged.as_ref().map_or(n, |(stage, _)| stage); - let at = n.appearance.effects.iter().position(|e| e.visible && e.id == effects::RASTERIZE)?; + let (whole, r, map) = rasterize_effect_art(d, n)?; let p = json!({ "ppi": r.ppi.unwrap_or(d.raster_effects_ppi), "colorModel": r.color_model.id(), @@ -356,20 +391,39 @@ fn rasterize_effect_image(d: &mut Document, n: &Node) -> Option { "clippingMask": r.clipping_mask, "addAround": r.add_around, }); - let mut whole = n.clone(); - whole.appearance.effects.remove(at); - (whole.opacity, whole.blend) = (1.0, Default::default()); - whole.extras_mut().mask = None; // shortcut: expanded Rasterize effects stay RGB, as the object keeps its own opacity mask and the // image's transparency would need one too; upgrade when CMYK images carry alpha. let image = super::menucmds::rasterize_art(d, vec![whole], &p, "object.rasterize", false).ok()?; let mut image = image.into_node(d); - if let Some((_, map)) = staged { + if let Some(map) = map { image.transform(map, false); } Some(image) } +/// What [`rasterize_effect_image`] makes its image of: `n`, or the art before the Transform effects +/// that move the image, without the Rasterize effect and without its transparency; that effect's +/// options; and the map those Transform effects move the image by. `None` when `n` has another +/// raster effect, when the Rasterize effect is not its own, or when those Transform effects +/// flatten the image. +fn rasterize_effect_art(d: &Document, n: &Node) -> Option<(Node, effects::Rasterize, Option)> { + let [RasterFx::Rasterize(r)] = raster_fx(n)[..] else { return None }; + let staged = vectorcraft_render::rasterize_stage(d, n); + if let Some((_, map)) = &staged + && !(map.determinant().is_finite() && map.determinant().abs() > 1e-12) + { + return None; + } + let (stage, map) = staged.map_or((None, None), |(stage, map)| (Some(stage), Some(map))); + let n = stage.as_ref().unwrap_or(n); + let at = n.appearance.effects.iter().position(|e| e.visible && e.id == effects::RASTERIZE)?; + let mut whole = n.clone(); + whole.appearance.effects.remove(at); + (whole.opacity, whole.blend) = (1.0, Default::default()); + whole.extras_mut().mask = None; + Some((whole, r, map)) +} + /// `v` (an object without its raster effects) replaced by `image` of the object with them: the /// image takes its place with its id, name and transparency (a layer keeps the image as its only /// member). diff --git a/crates/engine/src/tests/expand.rs b/crates/engine/src/tests/expand.rs index e4bfa26b2f..0cc0106351 100644 --- a/crates/engine/src/tests/expand.rs +++ b/crates/engine/src/tests/expand.rs @@ -455,10 +455,11 @@ fn a_symbol_instance_fill_shadow_shadows_its_filled_art() { assert!(expandable(&s), "the fill's shadow can be expanded"); run(&mut s, "effect.expandAppearance", json!({})); - let ch = node(&s, id).children().cloned().expect("the instance becomes a group"); + let n = node(&s, id); + let ch = n.children().cloned().expect("the instance becomes a group"); assert!(matches!(ch[0].kind, NodeKind::Image(_)), "the shadow is an image under the art: {}", ch[0].kind_label()); - assert!(matches!(ch[1].kind, NodeKind::SymbolInstance { .. }), "the art stays an instance: {}", ch[1].kind_label()); - no_effects_left(&ch[1]); + n.walk(&mut |part| assert!(!matches!(part.kind, NodeKind::SymbolInstance { .. }), "the art is no longer an instance")); + no_effects_left(&n); let after = render(&s); assert!(differing(&before, &after, 24) < 400, "expanding changed {} pixels", differing(&before, &after, 24)); run(&mut s, "edit.undo", json!({})); @@ -508,6 +509,311 @@ fn a_nested_symbol_instance_takes_the_outer_fill_shadow() { assert!(dark(render(&s).pixel(165, 100)), "the inner art casts the shadow: {:?}", render(&s).pixel(165, 100)); } +/// An instance of an Inner symbol of the square, with a new fill without paint on top that `inner` +/// gives effects, placed in the art of an Outer symbol; the Outer instance is selected, with a new +/// fill without paint on top. Returns the Outer instance and its new row's index. +fn nested_with_row(s: &mut Session, inner: impl FnOnce(&mut Session, NodeId, usize)) -> (NodeId, usize) { + let (inner_id, inner_row) = instance_with_row(s, "Inner", true); + inner(s, inner_id, inner_row); + let id = NodeId(run(s, "symbol.new", json!({"name": "Outer"}))["id"].as_u64().unwrap()); + run(s, "appearance.addFill", json!({"ids": [id.0]})); + let row = node(s, id).appearance.items.len() - 1; + run(s, "appearance.setItem", json!({"ids": [id.0], "index": row, "none": true})); + (id, row) +} + +/// The symbol instances and the images in `n`. +fn instances_and_images(n: &Node) -> (usize, usize) { + let mut found = (0, 0); + n.walk(&mut |part| match part.kind { + NodeKind::SymbolInstance { .. } => found.0 += 1, + NodeKind::Image(_) => found.1 += 1, + _ => {} + }); + found +} + +/// Replace the art of every symbol with an empty group. +fn empty_symbols(s: &mut Session) { + let d = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc); + for (i, sym) in d.symbols.iter_mut().enumerate() { + sym.art = std::sync::Arc::new(Node::group(NodeId(91_000 + i as u64), vec![])); + } +} + +/// When the outer instance's art expands, an instance in it whose own fill has a shadow becomes art +/// too, the shadow an image under it: no instance or effect is left, the look stays, and the result +/// no longer follows either symbol. +#[test] +fn a_nested_instance_fill_shadow_becomes_an_image_when_the_outer_art_expands() { + let mut s = session(); + let (id, row) = nested_with_row(&mut s, shadow_row); + offset_row(&mut s, id, row, 10.0); + let before = render(&s); + assert!(dark(before.pixel(175, 100)), "the inner art casts its shadow: {:?}", before.pixel(175, 100)); + + run(&mut s, "effect.expandAppearance", json!({})); + let n = node(&s, id); + let (instances, images) = instances_and_images(&n); + assert_eq!(instances, 0, "the outer and inner instances become art"); + assert!(images >= 1, "the inner shadow is an image"); + no_effects_left(&n); + let after = render(&s); + assert!(differing(&before, &after, 24) < 400, "expanding changed {} pixels", differing(&before, &after, 24)); + empty_symbols(&mut s); + assert_eq!(differing(&after, &render(&s), 0), 0, "the expanded art no longer follows the symbols"); +} + +/// A shadow on the outer instance's fill alone: the instance becomes its art over the shadow's +/// image, and an instance in that art with a shadow of its own becomes art and an image in turn, in +/// one undo step. +#[test] +fn an_outer_fill_shadow_expands_the_instance_and_reaches_the_nested_art() { + let mut s = session(); + let (id, row) = nested_with_row(&mut s, shadow_row); + shadow_row(&mut s, id, row); + let before = render(&s); + assert!(expandable(&s)); + + run(&mut s, "effect.expandAppearance", json!({})); + let n = node(&s, id); + let (instances, images) = instances_and_images(&n); + assert_eq!(instances, 0, "the outer and inner instances become art"); + assert!(images >= 2, "the outer and inner shadows are images: {images}"); + no_effects_left(&n); + let after = render(&s); + assert!(differing(&before, &after, 24) < 400, "expanding changed {} pixels", differing(&before, &after, 24)); + + run(&mut s, "edit.undo", json!({})); + assert!(matches!(node(&s, id).kind, NodeKind::SymbolInstance { .. }), "one undo gives the instance back"); + run(&mut s, "edit.redo", json!({})); + empty_symbols(&mut s); + assert_eq!(differing(&after, &render(&s), 0), 0, "the expanded art no longer follows the symbols"); +} + +/// A blur on the nested instance's fill: the nested instance becomes the image. +#[test] +fn a_nested_instance_fill_blur_becomes_an_image_when_the_outer_art_expands() { + let mut s = session(); + let blur = |s: &mut Session, id: NodeId, row: usize| { + run(s, "effect.apply", json!({"ids": [id.0], "item": row, "effect": "blur.gaussian", "params": {"radius": 3}})); + }; + let (id, row) = nested_with_row(&mut s, blur); + offset_row(&mut s, id, row, 10.0); + let before = render(&s); + + run(&mut s, "effect.expandAppearance", json!({})); + let n = node(&s, id); + let (instances, images) = instances_and_images(&n); + assert_eq!(instances, 0, "the outer and inner instances become art"); + assert_eq!(images, 1, "the blurred inner art is one image"); + no_effects_left(&n); + let after = render(&s); + assert!(differing(&before, &after, 24) < 400, "expanding changed {} pixels", differing(&before, &after, 24)); +} + +/// A blue rectangle from x 140 to 200, drawn first, so a shadow right of the square falls on it. +fn blue_backdrop(s: &mut Session) { + run(s, "shape.rectangle", json!({"x": 140, "y": 0, "width": 60, "height": 200})); + run(s, "paint.setFill", json!({"color": "#0000ff"})); +} + +/// A red Drop Shadow 20 pt to the right on row `row` of instance `id`, with no blur, painting with `mode`. +fn red_shadow_row(s: &mut Session, id: NodeId, row: usize, mode: &str) { + let params = json!({"x": 20, "y": 0, "blur": 0, "opacity": 100, "mode": mode, "color": "#ff0000"}); + run(s, "effect.apply", json!({"ids": [id.0], "item": row, "effect": "stylize.dropShadow", "params": params})); +} + +/// The blend modes of the images in `n`, in the order the walk visits them. +fn image_modes(n: &Node) -> Vec { + let mut modes = vec![]; + n.walk(&mut |part| { + if matches!(part.kind, NodeKind::Image(_)) { + modes.push(part.blend); + } + }); + modes +} + +/// A Multiply shadow on the nested instance's fill: its image multiplies with the blue art below +/// as the shadow did, rather than painting red over it. +#[test] +fn a_nested_instance_multiply_shadow_image_keeps_its_mode() { + let mut s = session(); + blue_backdrop(&mut s); + let (id, row) = nested_with_row(&mut s, |s, id, row| red_shadow_row(s, id, row, "multiply")); + offset_row(&mut s, id, row, 10.0); + let before = render(&s); + assert!(dark(before.pixel(170, 100)), "red multiplied with blue is dark: {:?}", before.pixel(170, 100)); + + run(&mut s, "effect.expandAppearance", json!({})); + let n = node(&s, id); + assert_eq!(instances_and_images(&n).0, 0, "the outer and inner instances become art"); + assert_eq!(image_modes(&n), [BlendMode::Multiply]); + no_effects_left(&n); + let after = render(&s); + assert!(dark(after.pixel(170, 100)), "the image multiplies with the blue art: {:?}", after.pixel(170, 100)); + assert!(differing(&before, &after, 24) < 400, "expanding changed {} pixels", differing(&before, &after, 24)); +} + +/// A Multiply shadow on an instance's own fill: the image under its art paints with Multiply. +#[test] +fn an_instance_multiply_shadow_image_keeps_its_mode() { + let mut s = session(); + blue_backdrop(&mut s); + let (id, row) = instance_with_row(&mut s, "Square", true); + red_shadow_row(&mut s, id, row, "multiply"); + let before = render(&s); + assert!(dark(before.pixel(160, 100)), "red multiplied with blue is dark: {:?}", before.pixel(160, 100)); + + run(&mut s, "effect.expandAppearance", json!({})); + let n = node(&s, id); + assert_eq!(image_modes(&n), [BlendMode::Multiply]); + let after = render(&s); + assert!(dark(after.pixel(160, 100)), "the image multiplies with the blue art: {:?}", after.pixel(160, 100)); + assert!(differing(&before, &after, 24) < 400, "expanding changed {} pixels", differing(&before, &after, 24)); +} + +/// A shadow on a hidden fill of the nested instance draws nothing, and expanding makes no image of it. +#[test] +fn a_hidden_nested_instance_fill_shadow_makes_no_image() { + let mut s = session(); + let hidden = |s: &mut Session, id: NodeId, row: usize| { + shadow_row(s, id, row); + run(s, "appearance.setItem", json!({"ids": [id.0], "index": row, "visible": false})); + }; + let (id, row) = nested_with_row(&mut s, hidden); + offset_row(&mut s, id, row, 10.0); + assert!(!dark(render(&s).pixel(175, 100)), "the hidden fill casts no shadow"); + + run(&mut s, "effect.expandAppearance", json!({})); + let n = node(&s, id); + assert_eq!(instances_and_images(&n), (0, 0), "the instances become art without an image"); + no_effects_left(&n); +} + +/// A nested instance with a shadow whose symbol is missing stays as it is while the outer art +/// expands around it. +#[test] +fn a_nested_instance_of_a_missing_symbol_stays_an_instance() { + let mut s = session(); + let (id, row) = nested_with_row(&mut s, shadow_row); + offset_row(&mut s, id, row, 10.0); + { + let d = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc); + d.symbols.retain(|sym| sym.name != "Inner"); + } + run(&mut s, "effect.expandAppearance", json!({})); + let n = node(&s, id); + assert_eq!(instances_and_images(&n), (1, 0), "the inner instance stays, without an image"); +} + +/// 1,100 blurred instances in the outer art, far fewer objects than the symbol limit: one Expand +/// Appearance makes 1,024 images of them, and the other 76 stay instances with their blur, which +/// the result reports. +#[test] +fn nested_instance_raster_effects_stop_at_the_image_limit() { + let mut s = session(); + // Images of a pixel or two each. + run(&mut s, "document.rasterEffectsSettings", json!({"resolution": 1})); + let blur = |s: &mut Session, id: NodeId, row: usize| { + run(s, "effect.apply", json!({"ids": [id.0], "item": row, "effect": "blur.gaussian", "params": {"radius": 3}})); + }; + let (id, row) = nested_with_row(&mut s, blur); + offset_row(&mut s, id, row, 10.0); + { + let d = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc); + let outer = d.symbols.iter().position(|sym| sym.name == "Outer").unwrap(); + let inner = (*d.symbols[outer].art).clone(); + assert!(matches!(inner.kind, NodeKind::SymbolInstance { .. }), "the outer art is the inner instance"); + let copies = (0..1_100) + .map(|_| { + let mut copy = inner.clone(); + copy.id = d.alloc_id(); + std::sync::Arc::new(copy) + }) + .collect(); + d.symbols[outer].art = std::sync::Arc::new(Node::group(d.alloc_id(), copies)); + } + + let r = run(&mut s, "effect.expandAppearance", json!({})); + assert_eq!(r["rasterLeft"], 76, "{r}"); + assert!(r["warning"].as_str().is_some_and(|w| w.contains("1,024 images")), "{r}"); + let n = node(&s, id); + assert_eq!(instances_and_images(&n), (76, 1_024), "1,024 instances become images and the rest stay"); + n.walk(&mut |part| { + if matches!(part.kind, NodeKind::SymbolInstance { .. }) { + assert!(part.appearance.items.iter().any(|i| i.effects().iter().any(|e| e.id == "blur.gaussian")), "a left instance keeps its blur"); + } + }); +} + +/// Gives `id` a color adjustment and a blur, puts it in a group above 1,024 blurred squares, which +/// take every image one Expand Appearance makes, and expands the group. Returns `id` as it was +/// before expanding. +fn adjusted_and_left_by_the_image_limit(s: &mut Session, id: NodeId) -> Node { + // Images of a pixel or two each. + run(s, "document.rasterEffectsSettings", json!({"resolution": 1})); + run(s, "effect.apply", json!({"ids": [id.0], "item": null, "effect": "adjust.hueSaturation", "params": {"hue": 120}})); + run(s, "effect.apply", json!({"ids": [id.0], "item": null, "effect": "blur.gaussian", "params": {"radius": 3}})); + let sq = NodeId(run(s, "shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20}))["id"].as_u64().unwrap()); + run(s, "effect.apply", json!({"ids": [sq.0], "item": null, "effect": "blur.gaussian", "params": {"radius": 3}})); + let before = node(s, id); + let group = { + let d = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc); + let blurred = d.node(sq).unwrap().clone(); + d.remove(sq).unwrap(); + let mut members: Vec<_> = (0..1_024) + .map(|_| { + let mut copy = blurred.clone(); + copy.id = d.alloc_id(); + std::sync::Arc::new(copy) + }) + .collect(); + members.push(std::sync::Arc::new(before.clone())); + let group = d.alloc_id(); + *d.node_mut(id).unwrap() = Node::group(group, members); + group + }; + + let r = run(s, "effect.expandAppearance", json!({"ids": [group.0]})); + assert_eq!(r["rasterLeft"], 1, "{r}"); + before +} + +/// A symbol instance with a color adjustment and a blur, left by the image limit, stays an instance +/// of its symbol, with both effects. +#[test] +fn a_color_adjusted_instance_left_by_the_image_limit_stays_an_instance() { + let mut s = session(); + run(&mut s, "shape.rectangle", json!({"x": 50, "y": 50, "width": 100, "height": 100})); + run(&mut s, "paint.setFill", json!({"color": "#ff0000"})); + let id = NodeId(run(&mut s, "symbol.new", json!({"name": "Adjusted Square"}))["id"].as_u64().unwrap()); + let before = adjusted_and_left_by_the_image_limit(&mut s, id); + assert!(matches!(before.kind, NodeKind::SymbolInstance { .. })); + assert_eq!(node(&s, id), before, "the instance stays as it is, with its adjustment and blur"); +} + +/// An embedded image with a color adjustment and a blur, left by the image limit, stays as it is, +/// and the document keeps no recolored copy of its pixels. +#[test] +fn a_color_adjusted_image_left_by_the_image_limit_adds_no_pixels() { + let mut s = session(); + let mut png = vec![]; + image::RgbaImage::from_pixel(30, 30, image::Rgba([255, 0, 0, 255])) + .write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png) + .unwrap(); + let r = run(&mut s, "file.place", json!({"name": "red.png", "dataBase64": vectorcraft_format::base64_encode(&png), "at": [100, 100]})); + let id = NodeId(r["ids"][0].as_u64().unwrap()); + let images: Vec = s.doc().unwrap().doc.images.keys().cloned().collect(); + let before = adjusted_and_left_by_the_image_limit(&mut s, id); + assert!(matches!(before.kind, NodeKind::Image(_))); + assert_eq!(node(&s, id), before, "the image stays as it is, with its adjustment and blur"); + // Besides the squares' images, the document holds the image's pixels alone. + let after: Vec = s.doc().unwrap().doc.images.keys().filter(|k| !k.starts_with("raster-effect-")).cloned().collect(); + assert_eq!(after, images, "no recolored copy stays in the document"); +} + /// Export draws a symbol instance's fill shadow on the filled shapes of its art: baking leaves the /// shadow on the art's fill, not its stroke, and PDF export makes an image of it. #[test] diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index e053838d17..681af6ff23 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -5873,6 +5873,7 @@ liquify-list-end {0}, {1} {0} i {1} @msg every numbered name for {name} is taken in the document's folder tots els noms numerats per a {name} estan ocupats a la carpeta del document @msg every search thread stopped on an internal error (please report this bug) tots els fils de cerca s’han aturat per un error intern (informeu d’aquest error) @msg Expand Appearance: the selection has a basic appearance Expandeix l’aparença: la selecció té una aparença bàsica +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all alguns efectes ràster no s’han convertit en imatges: ocuparien més de 1.024 imatges o 256 megapíxels en total @msg Expand: no brush strokes selected Expandeix: no s’ha seleccionat cap traç de pinzell @msg Expand: no gradient fills Expandeix: no hi ha farciments de degradat @msg Expand: nothing to expand Expandeix: no hi ha res per expandir diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 66dae3a50f..4fb57767b2 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -4918,6 +4918,7 @@ liquify-list-end {0}, {1} {0} a {1} @msg Divide Objects Below: select exactly one path Rozdělit objekty pod: vyberte právě jednu cestu @msg Downloaded {what} Staženo: {what} @msg Expand Appearance: the selection has a basic appearance Rozložit vzhled: výběr má základní vzhled +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all některé rastrové efekty nebyly převedeny na obrazy: zabraly by více než 1 024 obrazů nebo celkem 256 megapixelů @msg Expand: no brush strokes selected Rozložit: nejsou vybrány žádné tahy štětcem @msg Expand: no gradient fills Rozložit: žádné přechodové výplně @msg Expand: nothing to expand Rozložit: není co rozložit diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index e684315e41..c1b6115338 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -7127,6 +7127,7 @@ imageTrace Outline Kontur @msg Divide Objects Below: select exactly one path Opdel objekter nedenunder: markér præcis én kurve @msg Downloaded {what} Downloadede {what} @msg Expand Appearance: the selection has a basic appearance Udvid udseende: markeringen har et grundlæggende udseende +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all nogle rastereffekter blev ikke lavet om til billeder: de ville kræve mere end 1.024 billeder eller i alt 256 megapixel @msg Expand: no brush strokes selected Udvid: ingen penselstrøg er markeret @msg Expand: no gradient fills Udvid: ingen gradientfyld @msg Expand: nothing to expand Udvid: intet at udvide diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index aa836a4e37..e5013cdc7e 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -4520,6 +4520,7 @@ liquify-list-end {0}, {1} {0} und {1} @msg Divide Objects Below: select exactly one path Darunterliegende Objekte aufteilen: Wählen Sie genau einen Pfad aus @msg Downloaded {what} {what} heruntergeladen @msg Expand Appearance: the selection has a basic appearance Aussehen umwandeln: Die Auswahl hat ein einfaches Aussehen +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all einige Rastereffekte wurden nicht in Bilder umgewandelt: Sie würden mehr als 1.024 Bilder oder insgesamt 256 Megapixel benötigen @msg Expand: no brush strokes selected Umwandeln: keine Pinselkonturen ausgewählt @msg Expand: no gradient fills Umwandeln: keine Verlaufsflächen @msg Expand: nothing to expand Umwandeln: nichts umzuwandeln diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 2ac4b76fd1..8bf685fe3e 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -2617,6 +2617,7 @@ liquify-list-end {0}, {1} {0} και {1} @msg Divide Objects Below: select exactly one path Διαίρεση αντικειμένων από κάτω: επιλέξτε ακριβώς μία διαδρομή @msg Downloaded {what} Έγινε λήψη του {what} @msg Expand Appearance: the selection has a basic appearance Επέκταση εμφάνισης: η επιλογή έχει βασική εμφάνιση +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all ορισμένα εφέ ράστερ δεν μετατράπηκαν σε εικόνες: θα χρειάζονταν περισσότερες από 1.024 εικόνες ή συνολικά 256 megapixel @msg Expand: no brush strokes selected Επέκταση: δεν επιλέχθηκαν πινελιές @msg Expand: no gradient fills Επέκταση: δεν υπάρχουν γεμίσματα ντεγκραντέ @msg Expand: nothing to expand Επέκταση: δεν υπάρχει περιεχόμενο προς επέκταση diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index cb8c027b04..08b45ea653 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -4622,6 +4622,7 @@ liquify-list-end {0}, {1} {0}, {1} @msg Divide Objects Below: select exactly one path Dividir objetos inferiores: selecciona exactamente un trazado @msg Downloaded {what} Se descargó {what} @msg Expand Appearance: the selection has a basic appearance Expandir apariencia: la selección tiene una apariencia básica +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all algunos efectos ráster no se convirtieron en imágenes: ocuparían más de 1024 imágenes o 256 megapíxeles en total @msg Expand: no brush strokes selected Expandir: no hay trazos de pincel seleccionados @msg Expand: no gradient fills Expandir: no hay rellenos de degradado @msg Expand: nothing to expand Expandir: no hay nada que expandir diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index f7e5abd7a4..d06653b10b 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -4855,6 +4855,7 @@ liquify-list-end {0}, {1} {0} ja {1} @msg Divide Objects Below: select exactly one path Jaa alla olevat objektit: valitse tasan yksi polku @msg Downloaded {what} Ladattiin {what} @msg Expand Appearance: the selection has a basic appearance Laajenna ulkoasu: valinnalla on perusulkoasu +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all joitakin rasteritehosteita ei muunnettu kuviksi: ne veisivät yli 1 024 kuvaa tai yhteensä 256 megapikseliä @msg Expand: no brush strokes selected Laajenna: sivellinviivoja ei ole valittu @msg Expand: no gradient fills Laajenna: ei liukuväritäyttöjä @msg Expand: nothing to expand Laajenna: ei laajennettavaa diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 4cdff15959..7b20509dec 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -4587,6 +4587,7 @@ liquify-list-end {0}, {1} {0} et {1} @msg select a path sélectionnez un tracé @msg Divide Objects Below: select exactly one path Diviser les objets inférieurs : sélectionnez exactement un tracé @msg Downloaded {what} {what} téléchargé +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all certains effets pixellisés n’ont pas été convertis en images, car ils occuperaient plus de 1024 images ou 256 mégapixels au total @msg Expand Appearance: the selection has a basic appearance Décomposer l’aspect : la sélection a un aspect de base @msg Expand: no brush strokes selected Décomposer : aucun contour de forme sélectionné @msg Expand: no gradient fills Décomposer : aucun fond en dégradé diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index 1852c62a69..3700c12ea0 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -7064,6 +7064,7 @@ liquify-list-end {0}, {1} {0} और {1} @msg every search thread stopped on an internal error (please report this bug) प्रत्येक खोज धागा एक आंतरिक त्रुटि पर बंद कर दिया (कृपया इस बग की रिपोर्ट करें) @msg exit isolation mode first पहले अलगाव मोड से बाहर निकलें @msg Expand Appearance: the selection has a basic appearance उपस्थिति का विस्तार: सिलेक्शन में एक बुनियादी उपस्थिति है +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all कुछ रास्टर इफ़ेक्ट इमेज में नहीं बदले गए: उनके लिए 1,024 से अधिक इमेज या कुल 256 मेगापिक्सेल लगते @msg Expand: no brush strokes selected विस्तार: सिलेक्टेड कोई ब्रश स्ट्रोक नहीं @msg Expand: no gradient fills एक्सपैंड: कोई ग्रेडिएंट फ़िल नहीं @msg Expand: nothing to expand विस्तार: विस्तार करने के लिए कुछ नहीं diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index a86c7cb66a..97cca4d824 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -5440,6 +5440,7 @@ liquify-list-end {0}, {1} {0} és {1} @msg the art of a graph design in a graph series is drawn again from the design: edit the design to change it egy diagram adatsorában a diagramminta grafikája a mintából rajzolódik újra: a módosításához szerkeszd a mintát @msg every search thread stopped on an internal error (please report this bug) minden keresési szál belső hibával leállt (kérjük, jelentsd ezt a hibát) @msg Expand Appearance: the selection has a basic appearance Megjelenés kibontása: a kijelölésnek alapmegjelenése van +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all néhány raszteres effektus nem lett képpé alakítva: több mint 1024 képet vagy összesen 256 megapixelt foglalnának @msg Expand: no brush strokes selected Kibontás: nincs kijelölt ecsetvonás @msg Expand: no gradient fills Kibontás: nincs színátmenetes kitöltés @msg Expand: nothing to expand Kibontás: nincs mit kibontani diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 08ba5b23b0..a235a66f46 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -4650,6 +4650,7 @@ liquify-list-end {0}, {1} {0} e {1} @msg Divide Objects Below: select exactly one path Dividi oggetti sottostanti: seleziona esattamente un tracciato @msg Downloaded {what} Scaricato {what} @msg Expand Appearance: the selection has a basic appearance Espandi aspetto: la selezione ha un aspetto di base +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all alcuni effetti raster non sono stati trasformati in immagini: richiederebbero più di 1.024 immagini o 256 megapixel in totale @msg Expand: no brush strokes selected Espandi: nessuna traccia di pennello selezionata @msg Expand: no gradient fills Espandi: nessun riempimento con sfumatura @msg Expand: nothing to expand Espandi: niente da espandere diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 365eb75902..1a841b64e0 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -4619,6 +4619,7 @@ swatch Bright Violet ビビッドバイオレット @msg no history to clear 消去するヒストリーがありません @msg no history state {v} ヒストリーの状態 {v} はありません @msg Expand Appearance: the selection has a basic appearance アピアランスを分割: 選択範囲は基本アピアランスです +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all 一部のラスター効果は画像になりませんでした: 1,024 枚または合計 256 メガピクセルを超えるためです @msg select (or target) objects whose appearance isn't basic 基本アピアランスではないオブジェクトを選択するか、ターゲットに指定してください @msg {C}: no effect at index {from} {C}: インデックス {from} に効果がありません @msg Expand: no gradient fills 拡張: グラデーションの塗りがありません diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index ca131c94be..57f51229b9 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -6341,6 +6341,7 @@ font-technology Variable ცვლადი @msg Divide Objects Below: select exactly one path ქვედა ობიექტების დაყოფა: მონიშნეთ ზუსტად ერთი ტრაექტორია @msg Downloaded {what} ჩამოტვირთულია: {what} @msg Expand Appearance: the selection has a basic appearance იერსახის გაშლა: მონიშნულს საბაზისო იერსახე აქვს +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all ზოგიერთი რასტრული ეფექტი გამოსახულებად არ გადაიქცა: მათ დასჭირდებოდა 1024-ზე მეტი გამოსახულება ან ჯამში 256 მეგაპიქსელი @msg Expand: no brush strokes selected გაშლა: ფუნჯის შტრიხები მონიშნული არ არის @msg Expand: no gradient fills გაშლა: გრადიენტული შევსებები არ არის @msg Expand: nothing to expand გაშლა: გასაშლელი არაფერია diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 0034fda4c0..ae5b6fd0d4 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -4546,6 +4546,7 @@ theme Appearance 외관 @msg no history to clear 지울 히스토리가 없습니다 @msg no history state {v} 히스토리 상태 {v}이(가) 없습니다 @msg Expand Appearance: the selection has a basic appearance 모양새 확장: 선택 항목은 기본 모양새입니다 +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all 일부 래스터 효과는 이미지로 만들지 않았습니다: 이미지 1,024개 또는 총 256메가픽셀을 넘기 때문입니다 @msg select (or target) objects whose appearance isn't basic 모양새가 기본이 아닌 개체를 선택(또는 대상 지정)하세요 @msg {C}: no effect at index {from} {C}: 인덱스 {from}에 효과가 없습니다 @msg Expand: no gradient fills 확장: 그레이디언트 칠이 없습니다 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 6490fbf2bf..df58efb647 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -5022,6 +5022,7 @@ imageTrace Outline Contour @msg Divide Objects Below: select exactly one path Objecten eronder verdelen: selecteer precies één pad @msg Downloaded {what} {what} gedownload @msg Expand Appearance: the selection has a basic appearance Vormgeving uitbreiden: de selectie heeft een basisvormgeving +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all sommige rastereffecten zijn niet omgezet in afbeeldingen: ze zouden meer dan 1.024 afbeeldingen of in totaal 256 megapixel nodig hebben @msg Expand: no brush strokes selected Uitbreiden: geen penseelstreken geselecteerd @msg Expand: no gradient fills Uitbreiden: geen verloopvullingen @msg Expand: nothing to expand Uitbreiden: niets om uit te breiden diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index eece5f5568..a8d62360b6 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -4741,6 +4741,7 @@ liquify-list-end {0}, {1} {0} i {1} @msg Divide Objects Below: select exactly one path Podziel obiekty poniżej: zaznacz dokładnie jedną ścieżkę @msg Downloaded {what} Pobrano {what} @msg Expand Appearance: the selection has a basic appearance Rozszerz wygląd: zaznaczenie ma wygląd podstawowy +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all niektóre efekty rastrowe nie zostały zamienione na obrazy: zajęłyby więcej niż 1024 obrazy lub łącznie 256 megapikseli @msg Expand: no brush strokes selected Rozszerz: nie zaznaczono pociągnięć pędzla @msg Expand: no gradient fills Rozszerz: brak wypełnień gradientem @msg Expand: nothing to expand Rozszerz: nie ma czego rozszerzać diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index ce33c3daaf..a3095a4e6f 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -3938,6 +3938,7 @@ axis Both Ambos @msg Divide Objects Below: select exactly one path Dividir objetos abaixo: selecione exatamente um traçado @msg Downloaded {what} {what} baixado @msg Expand Appearance: the selection has a basic appearance Expandir aparência: a seleção tem uma aparência básica +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all alguns efeitos de raster não foram transformados em imagens: ocupariam mais de 1.024 imagens ou 256 megapixels no total @msg Expand: no brush strokes selected Expandir: nenhum traço de pincel selecionado @msg Expand: no gradient fills Expandir: nenhum preenchimento em gradiente @msg Expand: nothing to expand Expandir: nada para expandir diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index ce49d271c4..88fbd4a8d1 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -4646,6 +4646,7 @@ liquify-list-end {0}, {1} {0} и {1} @msg Divide Objects Below: select exactly one path Разделение объектов ниже: выделите ровно один контур @msg Downloaded {what} Скачано: {what} @msg Expand Appearance: the selection has a basic appearance Разбор оформления: у выделения основное оформление +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all некоторые растровые эффекты не преобразованы в изображения: для них нужно больше 1024 изображений или 256 мегапикселей в сумме @msg Expand: no brush strokes selected Разбор: не выделены мазки кисти @msg Expand: no gradient fills Разбор: нет градиентных заливок @msg Expand: nothing to expand Разбор: нечего разбирать diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index f80e7a7eec..53d4b76911 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -4532,6 +4532,7 @@ liquify-list-end {0}, {1} {0} och {1} @msg Divide Objects Below: select exactly one path Dela objekt under: markera exakt en bana @msg Downloaded {what} Hämtade {what} @msg Expand Appearance: the selection has a basic appearance Expandera utseende: markeringen har ett grundläggande utseende +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all vissa rastereffekter gjordes inte om till bilder: de skulle kräva mer än 1 024 bilder eller totalt 256 megapixlar @msg Expand: no brush strokes selected Expandera: inga penseldrag är markerade @msg Expand: no gradient fills Expandera: inga gradientfyllningar @msg Expand: nothing to expand Expandera: ingenting att expandera diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index a4c7c3d06f..8c6e0a1817 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -4364,6 +4364,7 @@ liquify-list-end {0}, {1} {0} ve {1} @msg Divide Objects Below: select exactly one path Aşağıdaki Nesneleri Böl: tam olarak bir yol seçin @msg Downloaded {what} {what} indirildi @msg Expand Appearance: the selection has a basic appearance Görünümü Genişlet: seçimin temel bir görünümü vardır +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all bazı raster efektleri görüntüye dönüştürülmedi: toplamda 1.024'ten fazla görüntü veya 256 megapiksel gerektirirlerdi @msg Expand: no brush strokes selected Genişlet: seçili fırça darbesi yok @msg Expand: no gradient fills Genişlet: degrade dolgu yok @msg Expand: nothing to expand Genişlet: genişletilecek bir şey yok diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index c13541bd00..cafa0ac4e6 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -4634,6 +4634,7 @@ liquify-list-end {0}, {1} {0} і {1} @msg Divide Objects Below: select exactly one path Поділ об’єктів нижче: виділіть рівно один контур @msg Downloaded {what} Завантажено: {what} @msg Expand Appearance: the selection has a basic appearance Розбір оформлення: виділення основне оформлення +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all деякі растрові ефекти не перетворено на зображення: для них потрібно понад 1024 зображення або загалом 256 мегапікселів @msg Expand: no brush strokes selected Розбір: не виділено мазки пензлі @msg Expand: no gradient fills Розбір: немає градієнтних заливок @msg Expand: nothing to expand Розбір: нема чого розбирати diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index e080e20ea8..b20f0e50e9 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -5115,6 +5115,7 @@ liquify-list-end {0}, {1} {0} và {1} @msg every numbered name for {name} is taken in the document's folder mọi tên đánh số cho {name} đã được dùng trong thư mục tài liệu @msg every search thread stopped on an internal error (please report this bug) mọi luồng tìm kiếm đã dừng do lỗi nội bộ (vui lòng báo cáo lỗi này) @msg Expand Appearance: the selection has a basic appearance Mở rộng diện mạo: vùng chọn có diện mạo cơ bản +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all một số hiệu ứng raster không được chuyển thành hình ảnh: chúng sẽ cần hơn 1.024 hình ảnh hoặc tổng cộng 256 megapixel @msg Expand: no brush strokes selected Mở rộng: chưa chọn nét cọ @msg Expand: no gradient fills Mở rộng: không có tô chuyển sắc @msg Expand: nothing to expand Mở rộng: không có gì để mở rộng diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 1d0f080e73..2e8d59058f 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -4320,6 +4320,7 @@ imageTrace Outline 轮廓 @msg no history to clear 没有可清除的历史记录 @msg no history state {v} 没有历史记录状态 {v} @msg Expand Appearance: the selection has a basic appearance 扩展外观:所选对象只有基本外观 +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all 部分栅格效果未转换为图像:它们会超过 1,024 个图像或总计 256 兆像素 @msg select (or target) objects whose appearance isn't basic 请选择 (或定位) 外观不是基本外观的对象 @msg {C}: no effect at index {from} {C}:索引 {from} 处没有效果 @msg Expand: no gradient fills 扩展:没有渐变填色 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 3753443567..40ca7edd00 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -1953,6 +1953,7 @@ file-filter Templates 範本 @msg no history to clear 沒有可清除的步驟記錄 @msg no history state {v} 沒有步驟記錄 {v} @msg Expand Appearance: the selection has a basic appearance 展開外觀:選取範圍只有基本外觀 +@msg some raster effects were not made into images: they would take more than 1,024 images or 256 megapixels in all 部分點陣效果未轉換為影像:它們會超過 1,024 個影像或總計 256 百萬像素 @msg select (or target) objects whose appearance isn't basic 請選取 (或指定目標) 外觀不是基本外觀的物件 @msg {C}: no effect at index {from} {C}:索引 {from} 處沒有效果 @msg Expand: no gradient fills 展開:沒有漸層填色 diff --git a/docs/mcp.md b/docs/mcp.md index 373aa97ac0..4d7a8104ee 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -5387,11 +5387,19 @@ the object with the image). Type with a geometry effect (Outline Object included is outlined; type that has no fills or strokes of its own and whose only effects are shadows or outer glows stays type, with the image under it. A group's or layer's own fills and strokes become objects among its members, and its members are expanded too. A symbol instance whose topmost fill or topmost stroke is visible, has an opacity above 0 -and has a geometry effect becomes a group of its art: that fill's effects reshape the filled shapes of the art and that -stroke's effects reshape its stroked shapes, which keep their colors, as the canvas draws them (VectorCraft's own -rule); the instance's other fills and strokes are dropped. A raster effect on that fill or stroke draws on the filled -or stroked shapes of the art, and expanding makes it an image as for other objects; with no geometry effect, the -instance stays an instance over a shadow or glow image, and a blur, feather or inner glow replaces it with the image. +and has a geometry or raster effect becomes a group of its art: that fill's effects reshape the filled shapes of the +art and that stroke's effects reshape its stroked shapes, which keep their colors, as the canvas draws them +(VectorCraft's own rule); the instance's other fills and strokes are dropped. A raster effect on that fill or stroke +draws on the filled or stroked shapes of the art, and expanding makes it an image as for other objects: a shadow or +glow image goes under the art, and a blur, feather or inner glow replaces the instance with the image. A symbol +instance in the art whose topmost fill or stroke has a geometry or raster effect, its own or one the outer instance +passes on, becomes its art and image the same way, and so do the instances in that art (VectorCraft's own rule). +Before, an instance whose fill or stroke had only a shadow or glow stayed an instance over the image, and a raster +effect on an instance in the art stayed live. +One Expand Appearance makes at most 1,024 images of raster effects, holding 256 megapixels in all (VectorCraft's own +limits). An object or symbol instance whose image would go past them stays as it is, with its effects and the objects +in it; the result then carries a `warning` and `rasterLeft`, the number of objects left so, and when nothing else +expands the command fails with the same message. A legacy `.ai` save notes it the same way. The result is `{ids}`; when an image in the art can't be decoded, the images made from raster effects do not show it, and the result also carries the `warning` that Flatten Transparency gives. A path's strokes stay strokes, as the diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index c634d6e3ff..3910725358 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1732,6 +1732,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur EMF, WMF and SVG export write the same symbol art the same way: an instance of a symbol whose art, or the art of a symbol nested in it, has such effects is written as that art placed by the instance and then baked, so a square that a Transform effect moves 100 pt right draws 100 pt right of where the instance places it at any scale or rotation, and art the effect moves onto the artboard is written. EMF and SVG clip 9-slice cells and WMF does not, as each places other instances. In SVG those instances use no ``, and instances of symbols without such effects still share one; named objects in a symbol's art take no ids there, as in an instance with its own copy of the art, so two instances do not write the same id; with Hidden Layers on, hidden instances are placed too and written hidden. An SVG instance nested in another instance's art is shared through `` only when the transform it is drawn with, the outer instances' included, keeps the shared art as the canvas draws it, so a nested stroke keeps its weight in a scaled instance. Preserve Editing still embeds the document with its live effects. Before, these exports wrote the art without its effects (metafile `tests::import::symbol_art_effects_are_written_where_they_draw`; SVG `symbols_layers::symbol_art_effects_are_written_where_the_canvas_draws_them`, `a_kept_hidden_instance_is_written_with_its_symbols_effects`, `instances_written_as_their_art_give_its_names_no_id`, `a_nested_instance_is_shared_only_under_the_transform_it_is_drawn_with`; effects `bake::placing_symbols_skips_instances_the_export_leaves_out`). When an export bakes a symbol instance with geometry effects inside the art of another such instance, it counts the art the inner instance bakes to, the copies its symbol's effects make included, against the 262,144 objects of symbol art one export bakes that way; it counted only the symbol's art before its effects. An instance whose baked art would pass that count stays an instance with its effects, and the art baked for it still counts against the instances after it. These are VectorCraft's own limits (effects `bake::nested_reshape_counts_baked_art`, `nested_reshape_refusal_keeps_its_work_counted`, `nested_reshape_refused_siblings_bake_once`, `nested_reshape_counts_successful_descendants_once`). A raster effect (Drop Shadow, Outer Glow, Gaussian Blur and the other effects that paint pixels) on a symbol instance's topmost fill draws on each filled shape of the symbol's art, and one on its topmost stroke draws on each stroked shape, after any geometry effects listed before it, under the same rules as geometry effects: only a visible fill or stroke with an opacity above 0 counts, a group's own fills and strokes in the art take the effect, and an instance inside the art passes it on. Each shape gets its own shadow or glow, which is VectorCraft's own rule. The canvas, Use Preview Bounds and the drawn bounds, SVG and PDF export draw it, and Object › Expand Appearance is enabled for such an instance and makes the effect an image at the document's raster effects resolution, in one undo step (engine `expand::a_symbol_instance_fill_shadow_shadows_its_filled_art`, `a_symbol_instance_stroke_shadow_shadows_only_its_stroked_art`, `a_symbol_instance_fill_shadow_follows_the_fill_offset_before_it`, `a_nested_symbol_instance_takes_the_outer_fill_shadow`, `export_draws_a_symbol_instance_fill_shadow`). Existing documents with a raster effect on a symbol instance's fill or stroke draw differently: before, the effect drew nothing. + Object › Expand Appearance turns a symbol instance whose topmost fill or stroke has only raster effects into its art as well, with the effect's image under the art (a shadow or glow) or in its place (a blur, feather or inner glow). A symbol instance inside the art whose topmost fill or stroke has a geometry or raster effect, its own or one the outer instance passes on, becomes its art and image the same way, and so do the instances in that art, within the nesting and symbol art limits; an instance of a missing symbol stays an instance. One Expand Appearance makes at most 1,024 images of raster effects, holding 256 megapixels in all (VectorCraft's own limits); an object or instance whose image would go past them stays as it is, with its raster effects, and the result reports how many with `rasterLeft` and a warning. Within those limits no live instance or raster effect is left from those effects, so the result no longer changes with the symbols; an instance left by the image limits still follows its symbol. The help page describes Expand Appearance turning appearance attributes into objects, and the help page describes expanding an effect into permanent raster data; expanding nested instances this way is VectorCraft's own rule (engine `expand::a_nested_instance_fill_shadow_becomes_an_image_when_the_outer_art_expands`, `an_outer_fill_shadow_expands_the_instance_and_reaches_the_nested_art`, `a_nested_instance_fill_blur_becomes_an_image_when_the_outer_art_expands`, `a_hidden_nested_instance_fill_shadow_makes_no_image`, `a_nested_instance_of_a_missing_symbol_stays_an_instance`, `nested_instance_raster_effects_stop_at_the_image_limit`). Before, an instance whose fill or stroke had only a shadow or glow stayed an instance over the image, and a raster effect on an instance in the art stayed live. The Appearance panel's inline effect editor labels each parameter as the effect dialogs' generic fields do, without the colon ("Max. Radius", "Channel 1", "Create New Fields by"). Roughen's and Zig Zag's Points, Offset Path's Joins, Inner Glow's Source and the menus of Radial Blur, Smart Blur, Sprayed Strokes, Glass, Mezzotint, Halftone Pattern, Grain, Texturizer and De-Interlace are dropdowns with the dialog's labels that send the dialog's values, and a plug-in's choice is a dropdown of the plug-in's values. Revolve's edge, Extrude & Bevel's bevel, every Warp style's orientation, Rasterize's Color Model, Background and Anti-aliasing and the channel of Levels and Curves are dropdowns too, with the labels their own dialogs show. `effect.apply` and `effect.setParams` refuse a Levels or Curves `channel` other than `rgb`, `red`, `green` or `blue` (or `r`, `g` and `b`, in any letter case). Object › Expand Appearance keeps each stroke of a path a stroke (weight, caps, joins, dashes, arrowheads, alignment and width profile) on a copy of the path with the geometry effects baked in, and Object › Expand… is dimmed, with a tooltip, while the selection has appearance attributes, so a stroked line with Zig Zag becomes a stroked zig-zag line and only Expand then outlines it, the two steps the [Expand objects](https://helpx.adobe.com/illustrator/desktop/manage-objects/arrange-objects/expand-objects.html) help page describes (#3089). Brushed strokes still become their brush art; `object.expand` still bakes and outlines in one step for agents.