Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Integration: #754 IDML keeps Basic Feather choke and corners (FeatherSetting ChokeAmount, CornerType); zh Sharp is 锐利

aiongg66146fd8661a
diff --git a/crates/idml/src/export.rs b/crates/idml/src/export.rs
index e3826e769..407eebcc7 100644
--- a/crates/idml/src/export.rs
+++ b/crates/idml/src/export.rs
@@ -1986,7 +1986,18 @@ impl<'a> Ex<'a> {
);
}
if e.feather > 0.0 || all {
- out.push(El::new("FeatherSetting").attr("Mode", if e.feather > 0.0 { "Standard" } else { "None" }).attr("Width", num(e.feather)));
+ let corners = match e.feather_options.corners {
+ designcraft_doc::FeatherCorners::Sharp => "Sharp",
+ designcraft_doc::FeatherCorners::Rounded => "Rounded",
+ designcraft_doc::FeatherCorners::Diffused => "Diffusion",
+ };
+ out.push(
+ El::new("FeatherSetting")
+ .attr("Mode", if e.feather > 0.0 { "Standard" } else { "None" })
+ .attr("Width", num(e.feather))
+ .attr("ChokeAmount", num(e.feather_options.choke))
+ .attr("CornerType", corners),
+ );
}
out
}
diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rs
index cac3815ee..7e1457802 100644
--- a/crates/idml/src/import.rs
+++ b/crates/idml/src/import.rs
@@ -2475,6 +2475,12 @@ impl<'r> Importer<'r> {
&& f.get("Mode").is_some_and(|m| m != "None")
{
fx.feather = f.num("Width").unwrap_or(9.0);
+ fx.feather_options.choke = finite(f.num("ChokeAmount")).unwrap_or(0.0).clamp(0.0, 100.0);
+ fx.feather_options.corners = match f.get("CornerType") {
+ Some("Sharp") => designcraft_doc::FeatherCorners::Sharp,
+ Some("Rounded") => designcraft_doc::FeatherCorners::Rounded,
+ _ => designcraft_doc::FeatherCorners::Diffused,
+ };
}
if let Some(g) = t.find("GradientFeatherSetting")
&& g.boolean("Applied") == Some(true)
diff --git a/crates/idml/src/tests.rs b/crates/idml/src/tests.rs
index c74fbde9f..a2e0196ea 100644
--- a/crates/idml/src/tests.rs
+++ b/crates/idml/src/tests.rs
@@ -3591,3 +3591,25 @@ fn object_style_effects_import_by_category_and_based_on() {
assert!(fx("Off").is_none());
assert!(!fx("Loop").unwrap().drop_shadow.on);
}
+
+#[test]
+fn feather_choke_and_corners_round_trip() {
+ use designcraft_doc::{Effects, FeatherCorners, FeatherOptions, Item, ItemId, ObjectStyle};
+ let mut d = Document::new(&NewDocument::default());
+ let lid = d.default_layer();
+ let feathers = [(6.0, 40.0, FeatherCorners::Sharp), (4.0, 0.0, FeatherCorners::Rounded), (3.0, 12.5, FeatherCorners::Diffused)];
+ let fx = |(w, choke, corners): (f64, f64, FeatherCorners)| Effects { feather: w, feather_options: FeatherOptions { choke, corners }, ..Default::default() };
+ for (i, f) in feathers.into_iter().enumerate() {
+ let x = 40.0 + 120.0 * i as f64;
+ let mut it = Item::new(ItemId(d.alloc()), lid, Shape::Rectangle, shapes::rectangle(Rect::new(x, 40.0, x + 100.0, 140.0)));
+ it.effects = fx(f);
+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();
+ }
+ let styled = fx((5.0, 25.0, FeatherCorners::Rounded));
+ d.styles_mut().object.push(ObjectStyle { name: "Soft".into(), effects: Some(styled.clone()), ..Default::default() });
+ let back = import_idml(&export_idml(&d)).unwrap();
+ let got: Vec<_> = back.spreads[0].items.iter().map(|i| i.effects.clone()).collect();
+ assert_eq!(got, feathers.map(fx));
+ let style = back.styles.object.iter().find(|s| s.name == "Soft").and_then(|s| s.effects.clone()).unwrap();
+ assert_eq!((style.feather, style.feather_options), (styled.feather, styled.feather_options));
+}
diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs
index 37297d8c4..c93f3448e 100644
--- a/crates/ui-egui/src/i18n.rs
+++ b/crates/ui-egui/src/i18n.rs
@@ -78,7 +78,7 @@ const TABLE: &[(&str, [&str; 5])] = &[
("Softer", ["Weicher", "Plus flou", "Más suave", "さらにソフトに", "柔和"]),
("Precise", ["Präzise", "Précis", "Precisa", "精細", "精确"]),
("Corners:", ["Ecken:", "Angles :", "Esquinas:", "角:", "角点:"]),
- ("Sharp", ["Spitz", "Vifs", "Nítidas", "シャープ", "锐化"]),
+ ("Sharp", ["Spitz", "Vifs", "Nítidas", "シャープ", "锐利"]),
("Diffused", ["Weich", "Diffus", "Difusas", "拡散", "扩散"]),
("Reverse Path", ["Pfadrichtung umkehren", "Inverser le tracé", "Invertir trazado", "パスの方向反転", "反转路径"]),
("Set Anchor", ["Ankerpunkt festlegen", "Définir le point d’ancrage", "Definir punto de ancla", "アンカーポイントを設定", "设置锚点"]),