Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.

Commit

Permalink
Added removal of the transform attribute with a default value.
Browse files Browse the repository at this point in the history
  • Loading branch information
RazrFalcon committed Apr 9, 2018
1 parent 5927867 commit 6ebc2df
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http:https://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http:https://semver.org/).

## [Unreleased]
### Added
- Removal of the `transform` attribute with a default value.

### Fixed
- Attributes resolving during the `defs` regrouping.

Expand Down
2 changes: 2 additions & 0 deletions src/cleaner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ pub fn clean_doc(
remove_empty_defs(doc);
fix_xmlns_attribute(doc, options.remove_xmlns_xlink_attribute);

remove_default_transform(doc);

// NOTE: Must be run at last, since it breaks the linking.
join_style_attributes(doc, options.join_style_attributes, opt);

Expand Down
10 changes: 6 additions & 4 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ pub use self::group_defs::group_defs;
pub use self::join_style_attrs::join_style_attributes;
pub use self::merge_gradients::merge_gradients;
pub use self::preclean_checks::preclean_checks;
pub use self::rm_default_attrs::remove_default_attributes;
pub use self::rm_dupl_defs::*;
pub use self::regroup_gradient_stops::regroup_gradient_stops;
pub use self::resolve_inherit::resolve_inherit;
pub use self::resolve_gradients::*;
pub use self::resolve_inherit::resolve_inherit;
pub use self::resolve_use::resolve_use;
pub use self::rm_default_attrs::remove_default_attributes;
pub use self::rm_default_transform::remove_default_transform;
pub use self::rm_dupl_defs::*;
pub use self::rm_elems::remove_element;
pub use self::rm_gradient_attrs::remove_gradient_attributes;
pub use self::rm_invalid_stops::remove_invalid_stops;
Expand Down Expand Up @@ -57,10 +58,11 @@ mod join_style_attrs;
mod merge_gradients;
mod preclean_checks;
mod regroup_gradient_stops;
mod resolve_inherit;
mod resolve_gradients;
mod resolve_inherit;
mod resolve_use;
mod rm_default_attrs;
mod rm_default_transform;
mod rm_dupl_defs;
mod rm_elems;
mod rm_gradient_attrs;
Expand Down
32 changes: 32 additions & 0 deletions src/task/rm_default_transform.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// svgcleaner could help you to clean up your SVG files
// from unnecessary data.
// Copyright (C) 2012-2018 Evgeniy Reizner
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

use svgdom::{Document, AttributeValue};

use task::short::AId;

pub fn remove_default_transform(doc: &Document) {
for mut node in doc.descendants() {
let av = node.attributes().get_value(AId::Transform).cloned();
if let Some(AttributeValue::Transform(ts)) = av {
if ts.is_default() {
node.remove_attribute(AId::Transform);
}
}
}
}

0 comments on commit 6ebc2df

Please sign in to comment.