Skip to content

Truly independent web browser

LibWeb: Make feComposite’s out keep the in image, not in2

sideshowbarkerb3d69ebb2b5a
diff --git a/Libraries/LibWeb/Rust/src/painting/svg_filter.rs b/Libraries/LibWeb/Rust/src/painting/svg_filter.rs
index be4a3b3b1d1..887adf5f2aa 100644
--- a/Libraries/LibWeb/Rust/src/painting/svg_filter.rs
+++ b/Libraries/LibWeb/Rust/src/painting/svg_filter.rs
@@ -721,10 +721,12 @@ impl SvgFilterGraphBuilder {
}
}
+// https://drafts.fxtf.org/filter-effects-1/#feCompositeElement
+// The 'in' image is the source of each Porter-Duff operation, and the 'in2' image its destination.
fn composite_operator_to_blend_mode(composite_operator: u8) -> CompositingAndBlendingOperator {
match composite_operator {
COMPOSITE_OPERATOR_IN => CompositingAndBlendingOperator::SourceIn,
- COMPOSITE_OPERATOR_OUT => CompositingAndBlendingOperator::DestinationOut,
+ COMPOSITE_OPERATOR_OUT => CompositingAndBlendingOperator::SourceOut,
COMPOSITE_OPERATOR_ATOP => CompositingAndBlendingOperator::SourceATop,
COMPOSITE_OPERATOR_XOR => CompositingAndBlendingOperator::Xor,
COMPOSITE_OPERATOR_LIGHTER => CompositingAndBlendingOperator::Lighter,
diff --git a/Tests/LibWeb/Ref/expected/svg-fecomposite-out-ref.html b/Tests/LibWeb/Ref/expected/svg-fecomposite-out-ref.html
new file mode 100644
index 00000000000..cd9dde9dd9d
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/svg-fecomposite-out-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<style>
+ body {
+ margin: 0;
+ }
+</style>
+<svg width="300" height="150">
+ <rect x="10" y="90" width="40" height="20" fill="black" />
+ <rect x="80" y="50" width="40" height="20" fill="black" />
+</svg>
+<p style="margin: 0 10px; font: 0/0 serif"><span style="display: inline-block; width: 40px; height: 40px; position: relative"><span style="position: absolute; top: 40px; width: 40px; height: 20px; background: black"></span></span></p>
diff --git a/Tests/LibWeb/Ref/input/svg-fecomposite-out.html b/Tests/LibWeb/Ref/input/svg-fecomposite-out.html
new file mode 100644
index 00000000000..31a15691eb4
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/svg-fecomposite-out.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/svg-fecomposite-out-ref.html" />
+<style>
+ body {
+ margin: 0;
+ }
+</style>
+<svg width="300" height="150">
+ <filter id="drop-band" x="-1" y="-1" width="3" height="3">
+ <feOffset in="SourceAlpha" dy="20" result="shifted" />
+ <!-- What's left of the shifted copy where the original isn't: a band along its bottom. -->
+ <feComposite in="shifted" in2="SourceAlpha" operator="out" />
+ </filter>
+ <filter id="top-band" x="-1" y="-1" width="3" height="3">
+ <feOffset in="SourceAlpha" dy="20" result="shifted" />
+ <!-- What's left of the original where the shifted copy isn't: a band along its top. -->
+ <feComposite in="SourceAlpha" in2="shifted" operator="out" />
+ </filter>
+ <rect x="10" y="50" width="40" height="40" fill="blue" filter="url(#drop-band)" />
+ <rect x="80" y="50" width="40" height="40" fill="blue" filter="url(#top-band)" />
+</svg>
+<p style="margin: 0 10px; font: 0/0 serif"><span style="display: inline-block; width: 40px; height: 40px; background: blue; filter: url(#drop-band)"></span></p>