DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
fix(render): A group's gradient feather fades the group, on screen and in PDF
moppeeer6f4fa3e56da6
diff --git a/ROADMAP.md b/ROADMAP.mdindex 8a0f82071..0e1e59ea0 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -153,6 +153,7 @@ Newest first.- **2026-10-12** · The Effects panel shows the level its settings apply to ("Group: Color Dodge 100%") and, as in InDesign, Isolate Blending and Knockout Group for a selected group. No readiness percentage change.- **2026-10-11** · Properties gains InDesign's Pathfinder section (Add, Subtract, Intersect, Exclude Overlap, Minus Back) with several objects selected; section titles and icon buttons have accessible names. No readiness percentage change.- **2026-10-12** · The Eyedropper samples a placed image: clicking the photo with text (or objects) selected fills them with the image's colour under the pointer, as an unnamed colour (`color.sample`), as in InDesign. Images on locked layers can be sampled. No readiness percentage change.+- **2026-10-12** · A gradient feather on a group fades the group as one, on screen and in PDF. Before, the screen ignored it, and PDF masked the group with a box of zero size because a group has no path of its own. No readiness percentage change.- **2026-10-12** · Words in capitals hyphenate like capitalized words (FERRUM COM-MODI), as in InDesign; Hyphenate Capitalized Words off keeps them whole. No readiness percentage change.- **2026-10-11** · `transform.move {copy}`, Edit › Duplicate and Step and Repeat return the copies' ids, so a script can go on with them. No readiness percentage change.- **2026-10-11** · `object.fill` and `object.stroke` refuse a swatch name the document doesn't have (it painted nothing) and suggest the name meant (`Paper` → `[Paper]`). No readiness percentage change.diff --git a/crates/doc/src/item.rs b/crates/doc/src/item.rsindex 0a701998e..80b3f2f6d 100644--- a/crates/doc/src/item.rs+++ b/crates/doc/src/item.rs@@ -1105,6 +1105,17 @@ impl Item {self.path.bounds().unwrap_or(Rect::ZERO)}+ /// The box a gradient feather spans, in item space: the path's bounds, or a group's objects'+ /// (a group has no path of its own).+ pub fn feather_bounds(&self) -> Rect {+ if self.is_group()+ && let Content::Group { items } = &self.content+ {+ return items.iter().map(|c| c.bounds()).reduce(|a, b| a.union(b)).unwrap_or(Rect::ZERO);+ }+ self.inner_bounds()+ }+/// Spread-space geometric bounds (axis-aligned box of the transformed path; groups: union)./// A group (its bounds are its children's). A frame holding pasted-into items is not.pub fn is_group(&self) -> bool {diff --git a/crates/engine/src/cmd/paths.rs b/crates/engine/src/cmd/paths.rsindex b9d479067..976e892b9 100644--- a/crates/engine/src/cmd/paths.rs+++ b/crates/engine/src/cmd/paths.rs@@ -435,6 +435,39 @@ mod tests {assert!(t.contains("/SMask") || t.contains("/Luminosity"), "a soft mask");}+ #[test]+ fn a_groups_gradient_feather_fades_it_on_screen_and_in_pdf() {+ let mut s = Session::new();+ s.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();+ let mut ids = vec![];+ for rect in [[100, 100, 200, 200], [200, 100, 300, 200]] {+ let id = s.execute("frame.create", &json!({"rect": rect})).unwrap()["id"].as_u64().unwrap();+ s.execute("object.fill", &json!({"ids": [id], "swatch": "[Black]"})).unwrap();+ ids.push(id);+ }+ let g = s.execute("object.group", &json!({"ids": ids})).unwrap()["id"].as_u64().unwrap();+ // The Gradient Feather tool's drag, then by angle (a group has no path of its own: the+ // gradient spans its objects).+ for p in [json!({"ids": [g], "from": [100, 150], "to": [300, 150]}), json!({"ids": [g], "angle": 0})] {+ s.execute("object.gradientFeather", &p).unwrap();+ let d = s.doc().unwrap().doc.clone();+ let mut rr = designcraft_render::Renderer::new();+ rr.threads = 0;+ let img = rr.render_page(&d, &s.cache, 0, 1.0, false, &Default::default()).unwrap();+ let (l, m, r) = (img.pixel(105, 150)[0], img.pixel(200, 150)[0], img.pixel(295, 150)[0]);+ assert!(l < 60 && m > l + 40 && r > 220, "{p}: fades left to right on screen: {l} {m} {r}");+ let pdf = designcraft_pdf::export_pdf(&d, &s.cache, &Default::default()).unwrap();+ let pm = designcraft_render::render_pdf_page(&pdf, 0, 400).unwrap();+ // Over white paper.+ let at = |x: usize, y: usize| {+ let c = pm.data()[y * pm.width() as usize + x];+ c.r as u32 + 255 - c.a as u32+ };+ let (l, m, r) = (at(105, 150), at(200, 150), at(295, 150));+ assert!(l < 60 && m > l + 40 && r > 220, "{p}: fades left to right in PDF: {l} {m} {r}");+ }+ }+#[test]fn create_outlines_turns_text_into_paths() {let mut s = Session::new();diff --git a/crates/pdf/src/export.rs b/crates/pdf/src/export.rsindex dcf8abb83..3627fd954 100644--- a/crates/pdf/src/export.rs+++ b/crates/pdf/src/export.rs@@ -757,7 +757,7 @@ impl Exporter<'_> {}// Gradient feather: a luminosity mask (white = opaque) over the object.let xf = parent * it.xf;- let (p0, p1) = gf.points(it.inner_bounds());+ let (p0, p1) = gf.points(it.feather_bounds());let gray = |a: f32| -> krilla::color::Color { luma::Color::new((a.clamp(0.0, 1.0) * 255.0).round() as u8).into() };let stops = vec![Stop { offset: NormalizedF32::ZERO, color: gray(gf.start), opacity: NormalizedF32::ONE },@@ -791,7 +791,15 @@ impl Exporter<'_> {}.into()};- let area = it.inner_bounds().inflate(it.stroke.extent() + 4.0, it.stroke.extent() + 4.0);+ // A group's mask covers its objects (it has no path of its own), with room for text and+ // strokes past their frames.+ let area = if it.is_group() {+ let b = it.feather_bounds();+ let pad = 36.0 + 0.25 * b.width().max(b.height());+ b.inflate(pad, pad)+ } else {+ it.inner_bounds().inflate(it.stroke.extent() + 4.0, it.stroke.extent() + 4.0)+ };let mut sb = s.stream_builder();let mut ms = sb.surface();ms.push_transform(&tf(xf));diff --git a/crates/render/src/fx.rs b/crates/render/src/fx.rsindex 6b29516f4..0e1ffd565 100644--- a/crates/render/src/fx.rs+++ b/crates/render/src/fx.rs@@ -64,6 +64,27 @@ fn shadow(sigma: f64, color: peniko::Color) -> Filter {})}+/// Keep what was drawn in the current layer as much as `it`'s gradient feather says, over `area`+/// (item space; past the gradient's ends its end opacities carry on).+pub(crate) fn gradient_feather_mask(ctx: &mut RenderContext, f: &Frame, it: &Item, xf: Affine, area: Rect) {+ let gf = &it.effects.gradient_feather;+ let (p0, p1) = gf.points(it.feather_bounds());+ let stop = |o: f32, a: f32| peniko::ColorStop::from((o, peniko::Color::from_rgba8(0, 0, 0, (a.clamp(0.0, 1.0) * 255.0).round() as u8)));+ let stops = [stop(0.0, gf.start), stop(1.0, gf.end)];+ let grad = if gf.radial {+ peniko::Gradient::new_radial(p0, (p1 - p0).hypot().max(1e-3) as f32).with_stops(stops.as_slice())+ } else {+ peniko::Gradient::new_linear(p0, p1).with_stops(stops.as_slice())+ };+ ctx.set_transform(Affine::IDENTITY);+ ctx.push_layer(None, Some(BlendMode::new(Mix::Normal, Compose::DestIn)), None, None, None);+ ctx.set_transform(f.view * xf);+ ctx.set_paint(grad);+ ctx.fill_rect(&area);+ ctx.reset_paint_transform();+ ctx.pop_layer();+}+impl Renderer {/// Draw an item with soft effects: below-effects, the (feathered) body, inner shadow.pub(crate) fn draw_item_fx(&mut self, ctx: &mut RenderContext, f: &Frame, it: &Item, bp: &BezPath, xf: Affine, page: Option<usize>) {@@ -170,22 +191,8 @@ impl Renderer {}}if gf.on {- let (p0, p1) = gf.points(it.inner_bounds());- let stop = |o: f32, a: f32| peniko::ColorStop::from((o, peniko::Color::from_rgba8(0, 0, 0, (a.clamp(0.0, 1.0) * 255.0).round() as u8)));- let stops = [stop(0.0, gf.start), stop(1.0, gf.end)];- let grad = if gf.radial {- peniko::Gradient::new_radial(p0, (p1 - p0).hypot().max(1e-3) as f32).with_stops(stops.as_slice())- } else {- peniko::Gradient::new_linear(p0, p1).with_stops(stops.as_slice())- };- ctx.set_transform(Affine::IDENTITY);- ctx.push_layer(None, Some(BlendMode::new(Mix::Normal, Compose::DestIn)), None, None, None);- ctx.set_transform(f.view * xf);- ctx.set_paint(grad);let area = if xf.determinant().abs() > 1e-12 { xf.inverse().transform_rect_bbox(reach) } else { it.inner_bounds() };- ctx.fill_rect(&area.inflate(4.0, 4.0));- ctx.reset_paint_transform();- ctx.pop_layer();+ gradient_feather_mask(ctx, f, it, xf, area.inflate(4.0, 4.0));}if gf.on || directional {ctx.pop_layer();diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rsindex 2cc5c548f..ea942c2c8 100644--- a/crates/render/src/lib.rs+++ b/crates/render/src/lib.rs@@ -476,6 +476,12 @@ impl Renderer {ctx.set_transform(Affine::IDENTITY);ctx.push_layer(None, Some(blend_mode(it.blend)), Some(it.opacity), None, None);}+ // Gradient feather: the group's objects drawn together, then faded as one.+ let feather = it.effects.gradient_feather.on && f.opts.quality != DisplayQuality::Fast;+ if feather {+ ctx.set_transform(Affine::IDENTITY);+ ctx.push_layer(None, None, None, None, None);+ }if it.knockout {// Knockout: each object first clears its area of those behind it, so it composites// with the group's backdrop rather than with its siblings.@@ -495,6 +501,13 @@ impl Renderer {self.draw_item(ctx, f, c, xf, page);}}+ if feather {+ // Generous: text and strokes reach past their frames.+ let b = it.feather_bounds();+ let pad = 36.0 + 0.25 * b.width().max(b.height());+ fx::gradient_feather_mask(ctx, f, it, xf, b.inflate(pad, pad));+ ctx.pop_layer();+ }if layered {ctx.pop_layer();}