Commit 9da06f68 authored by RazrFalcon's avatar RazrFalcon

(usvg) Fixed style attributes resolving on the root 'svg' element.

parent 0057b195
......@@ -26,6 +26,7 @@ This changelog also contains important changes in dependencies.
- (usvg) Coordinates resolving when units are `userSpaceOnUse`.
- (usvg) Groups regrouping. Caused an incorrect rendering of `clipPath`
that had `filter` on a child.
- (usvg) Style attributes resolving on the root `svg` element.
- (qt-backend) Stroking of LineTo specified as CurveTo.
- (svgdom) `stroke-miterlimit` attribute parsing.
- (svgdom) `length` and `number` attribute types parsing.
......
e-use-024.svg
a-opacity-007.svg
e-clipPath-041.svg
e-clipPath-042.svg
e-filter-060.svg
e-use-024.svg
a-opacity-007.svg
e-clipPath-041.svg
e-clipPath-042.svg
e-filter-060.svg
......@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `color` on `use` resolving.
- Coordinates resolving when units are `userSpaceOnUse`.
- Groups regrouping.
- Style attributes resolving on the root `svg` element.
### Removed
- `Rect::transform`.
......
......@@ -135,6 +135,8 @@ pub fn prepare_doc(doc: &mut svgdom::Document, opt: &Options) {
remove_non_svg_data(doc);
remove_descriptive_elements(doc);
resolve_root_style_attributes(doc, svg);
fix_links(doc);
fix_xlinks(doc);
......
......@@ -4,6 +4,38 @@
use super::prelude::*;
/// Resolves the root `svg` element attributes.
///
/// In the `usvg`, the root `svg` element can't have any style attributes,
/// so we have to create a new root group and move all non-inheritable attributes into it.
pub fn resolve_root_style_attributes(doc: &mut Document, svg: &mut Node) {
// Create a new group only when needed.
let has_any =
svg.has_attribute(AId::ClipPath)
|| svg.has_attribute(AId::Filter)
|| svg.has_attribute(AId::Mask)
|| svg.has_attribute(AId::Opacity)
|| svg.has_attribute(AId::Transform);
if !has_any {
return;
}
let mut g = doc.create_element(EId::G);
let children: Vec<_> = svg.children().collect();
for child in children {
g.append(child);
}
svg.append(g.clone());
svg.move_attribute_to(AId::ClipPath, &mut g);
svg.move_attribute_to(AId::Filter, &mut g);
svg.move_attribute_to(AId::Mask, &mut g);
svg.move_attribute_to(AId::Opacity, &mut g);
svg.move_attribute_to(AId::Transform, &mut g);
}
pub fn resolve_style_attributes(doc: &Document, opt: &Options) {
resolve_inherit(&doc.root(), opt);
......
......@@ -243,11 +243,17 @@ impl AppendTransform for Node {
}
pub trait CopyAttribute {
pub trait AttributeExt {
fn move_attribute_to(&mut self, aid: AId, to: &mut Self);
fn copy_attribute_to(&self, aid: AId, to: &mut Self);
}
impl CopyAttribute for Node {
impl AttributeExt for Node {
fn move_attribute_to(&mut self, aid: AId, to: &mut Self) {
self.copy_attribute_to(aid, to);
self.remove_attribute(aid);
}
fn copy_attribute_to(&self, aid: AId, to: &mut Self) {
match self.attributes().get(aid) {
Some(attr) => to.set_attribute(attr.clone()),
......
......@@ -945,3 +945,7 @@ e-clipPath-040,5f852d84
e-filter-058,afb4ad06
e-filter-059,ce17a45f
e-use-024,967b9e79
a-opacity-007,3e792210
e-clipPath-041,108b66ef
e-clipPath-042,108b66ef
e-filter-060,7fbfbc22
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment