Accepting request 746227 from 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 (forwarded request 746179 from favogt)

OBS-URL: https://build.opensuse.org/request/show/746227
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/librsvg?expand=0&rev=95
This commit is contained in:
Dominique Leuenberger 2019-11-10 21:05:42 +00:00 committed by Git OBS Bridge
commit 71911290fa
5 changed files with 325 additions and 2 deletions

View File

@ -0,0 +1,60 @@
From 00795b4d94858be229da7e47c046f9f2bf3f579c Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Wed, 6 Nov 2019 17:13:15 -0600
Subject: [PATCH 1/3] croco.rs: Add struct definition for CRSimpleSel
---
rsvg_internals/src/croco.rs | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/rsvg_internals/src/croco.rs b/rsvg_internals/src/croco.rs
index 892aca9b..21ac8051 100644
--- a/rsvg_internals/src/croco.rs
+++ b/rsvg_internals/src/croco.rs
@@ -6,9 +6,9 @@ use libc;
// Opaque types from libcroco, or those which we only manipulate through libcroco functions
pub type CRString = gpointer;
-pub type CRSimpleSel = gpointer;
pub type CRParser = gpointer;
pub type CRTerm = gpointer;
+pub type CRAdditionalSel = gpointer;
pub type CRStatus = u32;
@@ -22,9 +22,22 @@ pub struct CRParsingLocation {
pub byte_offset: libc::c_uint,
}
+#[repr(C)]
+pub struct CRSimpleSel {
+ pub type_mask: libc::c_int,
+ pub is_case_sentive: gboolean,
+ pub name: CRString,
+ pub combinator: libc::c_int,
+ pub add_sel: CRAdditionalSel,
+ pub specificity: libc::c_ulong,
+ pub next: *mut CRSimpleSel,
+ pub prev: *mut CRSimpleSel,
+ pub location: CRParsingLocation,
+}
+
#[repr(C)]
pub struct CRSelector {
- pub simple_sel: CRSimpleSel,
+ pub simple_sel: *mut CRSimpleSel,
pub next: *mut CRSelector,
pub prev: *mut CRSelector,
@@ -91,7 +104,7 @@ extern "C" {
pub fn cr_selector_ref(a_this: *mut CRSelector);
pub fn cr_selector_unref(a_this: *mut CRSelector) -> gboolean;
- pub fn cr_simple_sel_to_string(a_this: CRSimpleSel) -> *mut libc::c_char;
+ pub fn cr_simple_sel_to_string(a_this: *mut CRSimpleSel) -> *mut libc::c_char;
pub fn cr_string_peek_raw_str(a_this: CRString) -> *const libc::c_char;
--
2.23.0

View File

@ -0,0 +1,166 @@
From 5796011ea5232783ee89e8467a76656873a3f7b4 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Wed, 6 Nov 2019 17:59:53 -0600
Subject: [PATCH 2/3] Compute the specificity of CSS selectors
And remove the unused function CssRules::lookup()
---
rsvg_internals/src/croco.rs | 2 ++
rsvg_internals/src/css.rs | 44 ++++++++++++++++++++++---------------
2 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/rsvg_internals/src/croco.rs b/rsvg_internals/src/croco.rs
index 21ac8051..7bee041d 100644
--- a/rsvg_internals/src/croco.rs
+++ b/rsvg_internals/src/croco.rs
@@ -11,6 +11,7 @@ pub type CRTerm = gpointer;
pub type CRAdditionalSel = gpointer;
pub type CRStatus = u32;
+pub const CR_OK: u32 = 0;
pub type CREncoding = u32;
pub const CR_UTF_8: CREncoding = 5;
@@ -105,6 +106,7 @@ extern "C" {
pub fn cr_selector_unref(a_this: *mut CRSelector) -> gboolean;
pub fn cr_simple_sel_to_string(a_this: *mut CRSimpleSel) -> *mut libc::c_char;
+ pub fn cr_simple_sel_compute_specificity(a_this: *mut CRSimpleSel) -> CRStatus;
pub fn cr_string_peek_raw_str(a_this: CRString) -> *const libc::c_char;
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index 2bb4a3b9..c8ae072c 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -73,11 +73,17 @@ impl<'i> AtRuleParser<'i> for DeclParser {
}
#[derive(Clone, Hash, PartialEq, Eq)]
-pub struct Selector(String);
+pub struct Selector {
+ name: String,
+ specificity: u64,
+}
impl Selector {
- fn new(s: &str) -> Selector {
- Selector(s.to_string())
+ fn new(s: &str, specificity: u64) -> Selector {
+ Selector {
+ name: s.to_string(),
+ specificity,
+ }
}
}
@@ -196,10 +202,6 @@ impl CssRules {
decl_list.add_declaration(declaration);
}
- pub fn lookup(&self, selector: &str) -> Option<&DeclarationList> {
- self.get_declarations(&Selector::new(selector))
- }
-
pub fn get_declarations(&self, selector: &Selector) -> Option<&DeclarationList> {
self.selectors_to_declarations.get(selector)
}
@@ -219,12 +221,12 @@ impl CssRules {
let id = node_data.get_id();
// *
- if *selector == Selector::new("*") {
+ if selector.name == "*" {
return true;
}
// tag
- if *selector == Selector::new(element_name) {
+ if selector.name == element_name {
return true;
}
@@ -234,7 +236,7 @@ impl CssRules {
// tag.class#id
if let Some(id) = id {
let target = format!("{}.{}#{}", element_name, cls, id);
- if *selector == Selector::new(&target) {
+ if selector.name == target {
return true;
}
}
@@ -242,20 +244,20 @@ impl CssRules {
// .class#id
if let Some(id) = id {
let target = format!(".{}#{}", cls, id);
- if *selector == Selector::new(&target) {
+ if selector.name == target {
return true;
}
}
// tag.class
let target = format!("{}.{}", element_name, cls);
- if *selector == Selector::new(&target) {
+ if selector.name == target {
return true;
}
// didn't find anything more specific, just apply the class style
let target = format!(".{}", cls);
- if *selector == Selector::new(&target) {
+ if selector.name == target {
return true;
}
}
@@ -265,13 +267,13 @@ impl CssRules {
if let Some(id) = id {
// id
let target = format!("#{}", id);
- if *selector == Selector::new(&target) {
+ if selector.name == target {
return true;
}
// tag#id
let target = format!("{}#{}", element_name, id);
- if *selector == Selector::new(&target) {
+ if selector.name == target {
return true;
}
}
@@ -375,7 +377,15 @@ unsafe extern "C" fn css_property(
while !cur_sel.is_null() {
let simple_sel = (*cur_sel).simple_sel;
+ cur_sel = (*cur_sel).next;
+
if !simple_sel.is_null() {
+ if cr_simple_sel_compute_specificity(simple_sel) != CR_OK {
+ continue;
+ }
+
+ let specificity = u64::from((*simple_sel).specificity);
+
let raw_selector_name = cr_simple_sel_to_string(simple_sel) as *mut libc::c_char;
if !raw_selector_name.is_null() {
@@ -405,14 +415,12 @@ unsafe extern "C" fn css_property(
handler_data
.css_rules
- .add_declaration(Selector::new(&selector_name), declaration);
+ .add_declaration(Selector::new(&selector_name, specificity), declaration);
}
Err(_) => (), // invalid property name or invalid value; ignore
}
}
}
-
- cur_sel = (*cur_sel).next;
}
}
--
2.23.0

View File

@ -0,0 +1,81 @@
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

View File

@ -1,3 +1,17 @@
-------------------------------------------------------------------
Thu Nov 7 07:51:06 UTC 2019 - Fabian Vogt <fvogt@suse.com>
- 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
-------------------------------------------------------------------
Wed Nov 6 01:24:01 UTC 2019 - Yifan Jiang <yfjiang@suse.com>
- Remove BuildRequires rust-std. The replacement rust-std-static
is already required by rust.
-------------------------------------------------------------------
Wed Oct 23 14:46:43 UTC 2019 - Bjørn Lie <bjorn.lie@gmail.com>

View File

@ -28,12 +28,14 @@ Group: Development/Libraries/C and C++
URL: https://wiki.gnome.org/Projects/LibRsvg
Source0: https://download.gnome.org/sources/librsvg/2.46/%{name}-%{version}.tar.xz
Source99: baselibs.conf
# PATCH-FIX-UPSTREAM https://gitlab.gnome.org/GNOME/librsvg/issues/525
Patch1: 0001-croco.rs-Add-struct-definition-for-CRSimpleSel.patch
Patch2: 0002-Compute-the-specificity-of-CSS-selectors.patch
Patch3: 0003-525-Consider-specificity-when-applying-CSS-selector-.patch
BuildRequires: cargo
BuildRequires: gobject-introspection-devel
BuildRequires: pkgconfig
BuildRequires: rust >= 1.34
BuildRequires: rust-std
BuildRequires: vala
BuildRequires: pkgconfig(cairo) >= 1.16.0
BuildRequires: pkgconfig(cairo-png) >= 1.2.0