├── .travis.yml ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.rst └── src └── lib.rs /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | sudo: false 3 | 4 | # run builds for all the trains (and more) 5 | rust: 6 | - stable 7 | - nightly 8 | branches: 9 | only: 10 | - master 11 | 12 | # load travis-cargo 13 | before_script: 14 | - | 15 | pip install 'travis-cargo<0.2' --user && 16 | export PATH=$HOME/.local/bin:$PATH 17 | 18 | # the main build 19 | script: 20 | - | 21 | travis-cargo build && 22 | travis-cargo --only nightly test && 23 | travis-cargo bench && 24 | travis-cargo doc 25 | 26 | env: 27 | global: 28 | # override the default `--features unstable` used for the nightly branch (optional) 29 | - TRAVIS_CARGO_NIGHTLY_FEATURE="" 30 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "simplesvg" 3 | version = "0.4.0" 4 | authors = ["bluss"] 5 | license = "MIT/Apache-2.0" 6 | 7 | repository = "https://github.com/bluss/simplesvg" 8 | documentation = "https://docs.rs/simplesvg/" 9 | description = "Very simple drawing/diagramming library with svg output." 10 | 11 | keywords = ["svg", "draw", "graphics"] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | simplesvg 2 | ========= 3 | 4 | Very simple drawing/diagramming library with svg output. 5 | 6 | Please read the `API documentation here`__ 7 | 8 | __ https://docs.rs/simplesvg/ 9 | 10 | |build_status|_ |crates|_ 11 | 12 | .. |build_status| image:: https://travis-ci.org/bluss/simplesvg.svg?branch=master 13 | .. _build_status: https://travis-ci.org/bluss/simplesvg 14 | 15 | .. |crates| image:: http://meritbadge.herokuapp.com/simplesvg 16 | .. _crates: https://crates.io/crates/simplesvg 17 | 18 | 19 | Recent Changes 20 | -------------- 21 | 22 | - 0.4.0 23 | 24 | - Fix circle and ellipse drawing 25 | - Add ability to use "none" as color 26 | 27 | - 0.3.1 28 | 29 | - Update doc link 30 | 31 | - 0.3.0 32 | 33 | - Transformations are now an ordered sequence. 34 | The sequence .rotate(x).translate(x, y) behaves as if the transformations 35 | are nested like `` ``. 36 | 37 | License 38 | ======= 39 | 40 | Dual-licensed to be compatible with the Rust project. 41 | 42 | Licensed under the Apache License, Version 2.0 43 | http://www.apache.org/licenses/LICENSE-2.0 or the MIT license 44 | http://opensource.org/licenses/MIT, at your 45 | option. This file may not be copied, modified, or distributed 46 | except according to those terms. 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Very simple drawing/diagramming library with SVG output. 2 | //! 3 | //! Use `Fig` to build the figure and `Svg` to render the output to SVG. 4 | //! 5 | //! `Svg` implements `std::fmt::Display` and `ToString` for output purposes. 6 | #![doc(html_root_url="https://docs.rs/simplesvg/0.4/")] 7 | #![warn(variant_size_differences)] 8 | use std::fmt; 9 | use std::fmt::Display; 10 | use std::rc::Rc; 11 | 12 | #[test] 13 | fn test() { 14 | let fig = Fig::Rect(10., 10., 200., 100.) 15 | .styled(Attr::default().fill(Color(0xff, 0, 0))); 16 | let text = Fig::Text(0., 20., "".to_string()); 17 | let c = Fig::Circle(20., 20., 100.); 18 | println!("{}", Svg(vec![fig, text, c], 500, 600)); 19 | } 20 | 21 | #[test] 22 | fn koch() { 23 | // Koch snowflake fractal 24 | let w = 500.; 25 | let mut fig = Fig::Line(0., 0., w, 0.); 26 | for _ in 0..5 { 27 | let f = fig.shared(); 28 | let mut v = Vec::new(); 29 | v.push(f.clone()); 30 | v.push(f.clone().transformed(Trans::default().rotate(60.).translate(w, 0.))); 31 | v.push(f.clone().transformed(Trans::default().scale_x_y(1., -1.).rotate(120.).translate(2. * w, 0.))); 32 | v.push(f.clone().transformed(Trans::default().translate(2. * w, 0.))); 33 | fig = Fig::Multiple(v).transformed(Trans::default().scale(0.333)); 34 | } 35 | fig = fig.styled(Attr::default().stroke(Color(0, 0, 0)).stroke_width(100.)); 36 | println!("{}", Svg(vec![fig], w as u32, w as u32)); 37 | } 38 | 39 | 40 | /// Color 41 | #[derive(Copy, Clone, Debug)] 42 | pub enum ColorAttr { 43 | Color(u8, u8, u8), 44 | ColorNone, 45 | } 46 | 47 | /// The default color is `ColorNone` 48 | impl Default for ColorAttr { 49 | fn default() -> Self { ColorNone } 50 | } 51 | 52 | pub use ColorAttr::*; 53 | 54 | /// Style attributes 55 | #[derive(Clone, Debug, Default)] 56 | pub struct Attr { 57 | pub fill: Option, 58 | pub stroke: Option, 59 | pub stroke_width: Option, 60 | pub opacity: Option, 61 | pub font_family: Option<&'static str>, 62 | _incomplete: (), 63 | } 64 | 65 | impl Attr { 66 | pub fn fill(mut self, c: ColorAttr) -> Self { 67 | self.fill = Some(c); 68 | self 69 | } 70 | pub fn stroke(mut self, c: ColorAttr) -> Self { 71 | self.stroke = Some(c); 72 | self 73 | } 74 | pub fn stroke_width(mut self, c: f32) -> Self { 75 | self.stroke_width = Some(c); 76 | self 77 | } 78 | pub fn opacity(mut self, c: f32) -> Self { 79 | self.opacity = Some(c); 80 | self 81 | } 82 | pub fn font_family(mut self, c: &'static str) -> Self { 83 | self.font_family = Some(c); 84 | self 85 | } 86 | } 87 | 88 | /// Transformations. 89 | /// 90 | /// Transformations are emitted in the order they were specified. 91 | #[derive(Clone, Debug, Default)] 92 | pub struct Trans { 93 | transforms: Vec, 94 | } 95 | 96 | #[derive(Clone, Debug)] 97 | enum Transform { 98 | Translate(f32, f32), 99 | Scale(f32, f32), 100 | Rotate(f32), 101 | } 102 | use Transform::*; 103 | 104 | impl Trans { 105 | fn push(mut self, t: Transform) -> Self { 106 | self.transforms.push(t); 107 | self 108 | } 109 | 110 | pub fn translate(self, x: f32, y: f32) -> Self { 111 | self.push(Translate(x, y)) 112 | } 113 | 114 | pub fn rotate(self, x: f32) -> Self { 115 | self.push(Rotate(x)) 116 | } 117 | 118 | pub fn scale(self, x: f32) -> Self { 119 | self.push(Scale(x, x)) 120 | } 121 | 122 | pub fn scale_x_y(self, x: f32, y: f32) -> Self { 123 | self.push(Scale(x, y)) 124 | } 125 | } 126 | 127 | /// Figure parts 128 | #[derive(Clone, Debug)] 129 | pub enum Fig { 130 | /// `x`, `y`, `width`, `height` 131 | Rect(f32, f32, f32, f32), 132 | /// `cx`, `cy`, `radius` 133 | Circle(f32, f32, f32), 134 | /// `cx`, `cy`, `rx`, `ry` 135 | Ellipse(f32, f32, f32, f32), 136 | /// `x1`, `y1`, `x2`, `y2` 137 | Line(f32, f32, f32, f32), 138 | /// Text element, `x`, `y`, `text` 139 | Text(f32, f32, String), 140 | /// With style attributes 141 | Styled(Attr, Box), 142 | /// With transformations 143 | Transformed(Trans, Box), 144 | /// A bunch of figure parts 145 | Multiple(Vec), 146 | /// Shared figure part. 147 | Shared(Rc), 148 | #[doc(hidden)] 149 | __Incomplete(internal::Void), 150 | } 151 | 152 | mod internal { 153 | #[doc(hidden)] 154 | #[derive(Clone, Debug)] 155 | pub enum Void {} 156 | } 157 | 158 | impl Fig { 159 | /// Apply style from `attr`. 160 | pub fn styled(self, attr: Attr) -> Self { 161 | Fig::Styled(attr, Box::new(self)) 162 | } 163 | 164 | /// Apply transformations from `trans` 165 | pub fn transformed(self, trans: Trans) -> Self { 166 | Fig::Transformed(trans, Box::new(self)) 167 | } 168 | 169 | /// Turn self into a `Fig::Shared`. 170 | pub fn shared(self) -> Self { 171 | if let Fig::Shared(_) = self { 172 | self 173 | } else { 174 | Fig::Shared(Rc::new(self)) 175 | } 176 | } 177 | } 178 | 179 | /// SVG image object. 180 | /// 181 | /// The image object is a list of figures and the width and height 182 | /// of the bounding box. 183 | #[derive(Clone, Debug)] 184 | pub struct Svg(pub Vec, pub u32, pub u32); 185 | 186 | 187 | impl Display for Svg { 188 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 189 | try!(writeln!(f, r##""##, 190 | self.1, self.2)); 191 | for elt in &self.0 { 192 | try!(write!(f, "{}", elt)); 193 | } 194 | try!(writeln!(f, r##""##)); 195 | Ok(()) 196 | } 197 | } 198 | 199 | struct XmlEscape<'a>(&'a str); 200 | 201 | impl<'a> Display for XmlEscape<'a> { 202 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 203 | let s = self.0; 204 | for ch in s.chars() { 205 | match ch { 206 | '<' => try!(write!(f, "<")), 207 | '>' => try!(write!(f, ">")), 208 | '&' => try!(write!(f, "&")), 209 | c => try!(write!(f, "{}", c)), 210 | } 211 | } 212 | Ok(()) 213 | } 214 | } 215 | 216 | impl Display for Fig { 217 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 218 | match *self { 219 | Fig::Styled(ref attr, ref fig) => { 220 | try!(writeln!(f, r##""##, attr)); 221 | try!(write!(f, "{}", fig)); 222 | try!(writeln!(f, "")); 223 | } 224 | Fig::Transformed(ref trans, ref fig) => { 225 | try!(writeln!(f, r##""##, trans)); 226 | try!(write!(f, "{}", fig)); 227 | try!(writeln!(f, "")); 228 | } 229 | Fig::Rect(x, y, w, h) => { 230 | try!(writeln!(f, r#""#, 231 | x, y, w, h)); 232 | } 233 | Fig::Line(x1, y1, x2, y2) => { 234 | try!(writeln!(f, r#""#, 235 | x1, y1, x2, y2)); 236 | } 237 | Fig::Circle(x, y, r) => { 238 | try!(writeln!(f, r#""#, x, y, r)); 239 | } 240 | Fig::Ellipse(x, y, rx, ry) => { 241 | try!(writeln!(f, r#""#, 242 | x, y, rx, ry)); 243 | } 244 | Fig::Text(x, y, ref s) => { 245 | try!(writeln!(f, r#"{}"#, 246 | x, y, XmlEscape(s))); 247 | } 248 | Fig::Multiple(ref figs) => { 249 | for elt in figs { 250 | try!(write!(f, "{}", elt)); 251 | } 252 | } 253 | Fig::Shared(ref fig) => { 254 | try!(write!(f, "{}", **fig)); 255 | } 256 | Fig::__Incomplete(ref void) => match *void { } // unreachable 257 | } 258 | Ok(()) 259 | } 260 | } 261 | 262 | impl Display for ColorAttr { 263 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 264 | match *self { 265 | Color(r, g, b) => write!(f, "#{:02x}{:02x}{:02x}", r, g, b), 266 | ColorNone => write!(f, "none"), 267 | } 268 | } 269 | } 270 | 271 | impl Display for Attr { 272 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 273 | // `;` are separators 274 | if let Some(c) = self.fill { 275 | try!(write!(f, "fill:{};", c)); 276 | } 277 | if let Some(c) = self.stroke { 278 | try!(write!(f, "stroke:{};", c)); 279 | } 280 | if let Some(v) = self.stroke_width { 281 | try!(write!(f, "stroke-width:{};", v)); 282 | } 283 | if let Some(v) = self.opacity { 284 | try!(write!(f, "opacity:{};", v)); 285 | } 286 | if let Some(v) = self.font_family { 287 | try!(write!(f, "font-family:{};", v)); 288 | } 289 | Ok(()) 290 | } 291 | } 292 | 293 | impl Display for Trans { 294 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 295 | // spaces are separators 296 | // transforms are applied reverse of the order they were pushed 297 | // to the vector. 298 | for transform in self.transforms.iter().rev() { 299 | match *transform { 300 | Translate(x, y) => try!(write!(f, "translate({}, {}) ", x, y)), 301 | Rotate(x) => try!(write!(f, "rotate({}) ", x)), 302 | Scale(x, y) => { 303 | if x == y { 304 | try!(write!(f, "scale({}) ", x)); 305 | } else { 306 | try!(write!(f, "scale({}, {}) ", x, y)); 307 | } 308 | } 309 | } 310 | } 311 | Ok(()) 312 | } 313 | } 314 | --------------------------------------------------------------------------------