librsvg/0003-525-Consider-specificity-when-applying-CSS-selector-.patch
Dominique Leuenberger 1ccad9b44d Accepting request 746179 from home:favogt:branches:GNOME:Factory
- Add patches to fix coloring of symbolic icons (glgo#GNOME/librsvg#525):
  * 0001-croco.rs-Add-struct-definition-for-CRSimpleSel.patch
  * 0002-Compute-the-specificity-of-CSS-selectors.patch
  * 0003-525-Consider-specificity-when-applying-CSS-selector-.patch

OBS-URL: https://build.opensuse.org/request/show/746179
OBS-URL: https://build.opensuse.org/package/show/GNOME:Factory/librsvg?expand=0&rev=164
2019-11-07 10:54:08 +00:00

82 lines
3.8 KiB
Diff

From 657d061bf66f1b289c8f915f21da82fa5915d920 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Wed, 6 Nov 2019 18:03:27 -0600
Subject: [PATCH 3/3] (#525): Consider specificity when applying CSS selector
matches
We still don't consider ordering of rules in stylesheets, but at least
we handle specificity for conflicting matches with this.
Fixes https://gitlab.gnome.org/GNOME/librsvg/issues/525
Without tests/fixtures/reftests/525-specificity-ref.png to avoid binary diff.
---
rsvg_internals/src/css.rs | 8 ++++--
tests/fixtures/reftests/525-specificity.svg | 27 +++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
create mode 100644 tests/fixtures/reftests/525-specificity.svg
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index c8ae072c..dee9e9ba 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -282,7 +282,7 @@ impl CssRules {
}
pub fn get_matches(&self, node_data: &NodeData) -> Vec<Selector> {
- self.selectors_to_declarations
+ let mut matches: Vec<_> = self.selectors_to_declarations
.iter()
.filter_map(|(selector, _)| {
if self.selector_matches_node(selector, node_data) {
@@ -292,7 +292,11 @@ impl CssRules {
}
})
.map(Selector::clone)
- .collect()
+ .collect();
+
+ matches.as_mut_slice().sort_by(|sel_a, sel_b| sel_a.specificity.cmp(&sel_b.specificity));
+
+ matches
}
}
diff --git a/tests/fixtures/reftests/525-specificity.svg b/tests/fixtures/reftests/525-specificity.svg
new file mode 100644
index 00000000..2fb1c525
--- /dev/null
+++ b/tests/fixtures/reftests/525-specificity.svg
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg version="1.1"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ width="16"
+ height="16">
+ <style type="text/css">
+ rect,circle,path {
+ fill: rgb(0,255,0) !important;
+ }
+ .warning {
+ fill: rgb(255,0,0) !important;
+ }
+ .error {
+ fill: rgb(0,255,0) !important;
+ }
+ .success {
+ fill: rgb(0,255,0) !important;
+ }
+ </style>
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
+ <path d="M6.5 0C2.922 0 0 2.922 0 6.5S2.922 13 6.5 13c.17 0 .333-.018.5-.031v-2.031c-.167.018-.327.062-.5.062A4.485 4.485 0 0 1 2 6.5C2 4.003 4.003 2 6.5 2S11 4.003 11 6.5c0 .173-.044.333-.063.5h2.032c.013-.167.031-.33.031-.5C13 2.922 10.078 0 6.5 0z" style="line-height:normal;-inkscape-font-specification:Sans;text-indent:0;text-align:start;text-decoration-line:none;text-transform:none;marker:none" color="#000" font-weight="400" font-size="xx-small" font-family="Sans" overflow="visible" fill="#2e3436"/>
+ <path d="M6.492 2.992A.5.5 0 0 0 6 3.5V6H4.5a.5.5 0 1 0 0 1h2a.5.5 0 0 0 .5-.5v-3a.5.5 0 0 0-.508-.508z" style="line-height:normal;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000;text-transform:none;text-orientation:mixed;shape-padding:0;isolation:auto;mix-blend-mode:normal" color="#000" font-weight="400" font-family="sans-serif" white-space="normal" overflow="visible" fill="#2e3436"/>
+ <path class="warning" d="M8.875 8.068a.861.861 0 0 0-.875.87v6.195a.86.86 0 0 0 .875.867h6.25a.86.86 0 0 0 .875-.867V8.938a.861.861 0 0 0-.875-.87zM11 9h2v2.5s0 .5-.5.5h-1c-.5 0-.5-.5-.5-.5zm.5 4h1c.277 0 .5.223.5.5v1c0 .277-.223.5-.5.5h-1a.499.499 0 0 1-.5-.5v-1c0-.277.223-.5.5-.5z" style="marker:none" color="#bebebe" overflow="visible" fill="#f57900"/>
+ </svg>
+
+</svg>
\ No newline at end of file
--
2.23.0