mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 13:15:12 +00:00
SVG Filters: a turned filter measures box units against its box, and export keeps it only where import can
In a turned or skewed user space, the source is drawn onto the filter's canvas pixels first and cut to the pixels it draws there, so the image lies along the user space's axes. A region in objectBoundingBox units (the default filterUnits) and primitive lengths with primitiveUnits="objectBoundingBox" are then measured against the object's box in that user space instead of the raster's box turned into it. SVG export and the image fallback keep a filter live only when SVG import can store its user space again: scale and axes together can scale it past 0.001 to 1000 points to a unit while each is valid alone (scale 1000 with axes [2, 0, 0, 2]). Such an object is written as an image. Import and export share the user-space check.
This commit is contained in:
@@ -475,7 +475,7 @@ fn imaged(n: &Node, which: Which) -> bool {
|
||||
&& effects::svg_filter::writes_live(&n.appearance.effects)
|
||||
&& fx
|
||||
.iter()
|
||||
.any(|f| matches!(f, RasterFx::Pixel(effects::PixelFx::Svg(s)) if (!s.measured() || fx.len() == 1) && s.writes_as_svg11()));
|
||||
.any(|f| matches!(f, RasterFx::Pixel(effects::PixelFx::Svg(s)) if (!s.measured() || fx.len() == 1) && s.writes_as_svg11() && s.opens_again()));
|
||||
(pixels > 0 && !live)
|
||||
|| (fx.iter().any(|f| matches!(f, RasterFx::DropShadow { darkness: Some(_), .. })) && (cmyk || !simple_rgb_shadow_source(n, &fx)))
|
||||
}
|
||||
|
||||
@@ -551,6 +551,26 @@ fn svg_export_keeps_a_measured_region_only_on_the_object_alone() {
|
||||
assert!(after.contains("<image") && !after.contains("<feOffset dx=\"3\""), "{after}");
|
||||
}
|
||||
|
||||
/// SVG export keeps a filter live only in a user space SVG import stores again: `scale` 1000 with
|
||||
/// `axes` that double it scales the user space 2000 times, past what import holds, so the object is
|
||||
/// written as an image instead of a filter that would be left out when the file is opened.
|
||||
#[test]
|
||||
fn svg_export_writes_an_image_for_a_user_space_import_cannot_store() {
|
||||
let hue = r#"<filter id="Hue"><feColorMatrix type="hueRotate" values="90"/></filter>"#;
|
||||
for (scale, axes, live) in [(2.0, json!([2, 0, 0, 2]), true), (1000.0, json!([2, 0, 0, 2]), false)] {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 10.0);
|
||||
run(&mut s, "effect.apply", json!({"effect": "svg.filter", "ids": [a.0], "params": {"xml": hue, "scale": scale, "axes": axes}}));
|
||||
let out = svg(&mut s);
|
||||
assert_eq!((out.contains("<feColorMatrix"), out.contains("<image")), (live, !live), "scale {scale}: {out}");
|
||||
let (back, warnings) = vectorcraft_svg::import_with_report(&out).unwrap();
|
||||
assert!(warnings.is_empty(), "scale {scale}: {warnings:?}");
|
||||
let mut kept = 0;
|
||||
back.walk(|n| kept += n.appearance.effects.iter().filter(|e| e.id == "svg.filter").count());
|
||||
assert_eq!(kept, usize::from(live), "scale {scale}: {out}");
|
||||
}
|
||||
}
|
||||
|
||||
/// SVG export writes a filter rebuilt from its filter elements and filter attributes, not the XML
|
||||
/// the effect holds.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user