diff options
author | RazrFalcon <razrfalcon@gmail.com> | 2019-01-05 19:09:28 +0200 |
---|---|---|
committer | RazrFalcon <razrfalcon@gmail.com> | 2019-01-05 22:20:56 +0200 |
commit | 9d3eb6fae7ef75941aa53ec1c081339ee22d46c7 (patch) | |
tree | 3fcca63e7868f298a14e6064a7a4994f3239c474 /usvg/src/preproc/prepare_text_decoration.rs | |
parent | d5f97660ec818e6cc1a9ebecdb1c0c813ec568cd (diff) |
Refactoring.
Diffstat (limited to 'usvg/src/preproc/prepare_text_decoration.rs')
-rw-r--r-- | usvg/src/preproc/prepare_text_decoration.rs | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/usvg/src/preproc/prepare_text_decoration.rs b/usvg/src/preproc/prepare_text_decoration.rs deleted file mode 100644 index 433fbc6..0000000 --- a/usvg/src/preproc/prepare_text_decoration.rs +++ /dev/null @@ -1,54 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -use super::prelude::*; - - -// <g fill="red" text-decoration="underline"> -// <g fill="blue" text-decoration="overline"> -// <text fill="green" text-decoration="line-through">Text</text> -// </g> -// </g> -// -// In this example 'text' element will have all decorators enabled, but color -// will be green for all of them. -// -// There is no simpler way to express 'text-decoration' property -// without groups than collect all the options to the string. -// It's not by the SVG spec, but easier than keeping all the groups. -pub fn prepare_text_decoration(doc: &mut Document) { - for mut node in doc.root().descendants().filter(|n| n.is_tag_name(EId::Text)) { - let mut td = String::new(); - if has_attr(&node, "underline") { - td.push_str("underline;"); - } - - if has_attr(&node, "overline") { - td.push_str("overline;"); - } - - if has_attr(&node, "line-through") { - td.push_str("line-through;"); - } - - if !td.is_empty() { - td.pop(); - node.set_attribute((AId::TextDecoration, td)); - } - } -} - -fn has_attr(root: &Node, decoration_id: &str) -> bool { - for (_, node) in root.ancestors().svg() { - let attrs = node.attributes(); - - if let Some(text) = attrs.get_str(AId::TextDecoration) { - if text == decoration_id { - return true; - } - } - } - - false -} |