1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
/// Options used during writing SVG paths. pub struct WriteOptionsPaths { /// Use compact path notation /// /// SVG allow us to remove some symbols from path notation without breaking parsing. /// /// Example: /// /// `M 10 -20 A 5.5 0.3 -4 1 1 0 -0.1` -> `M10-20A5.5.3-4 1 1 0-.1` /// /// Default: disabled pub use_compact_notation: bool, /// Join ArcTo flags. /// /// Elliptical arc curve segment has flags parameters, which can have values of `0` or `1`. /// Since we have fixed-width values, we can skip spaces between them. /// /// Example: /// /// `A 5 5 30 1 1 10 10` -> `A 5 5 30 1110 10` /// /// Default: disabled /// /// **Note:** Sadly, but most of the viewers doesn't support such notation, /// even throw it's valid by SVG spec. pub join_arc_to_flags: bool, /// Remove duplicated commands. /// /// If segment has same type as previous - we can skip command specifier. /// /// Example: /// /// `M 10 10 L 20 20 L 30 30 L 40 40` -> `M 10 10 L 20 20 30 30 40 40` /// /// Default: disabled pub remove_duplicated_commands: bool, } /// Options used during writing numbers. pub struct WriteOptionsNumbers { /// Set numeric precision for coordinates attributes, like: x, y, width, height, etc. /// /// Range: 1..8 /// /// Default: 6 pub precision_coordinates: u8, /// Set numeric precision for transform values: a, b, c, d. /// /// Range: 1..8 /// /// Default: 8 pub precision_transforms: u8, /// Remove leading zero from numbers. /// /// Example: /// /// `0.1` -> `.1`, `-0.1` -> `-.1` /// /// Default: disabled pub remove_leading_zero: bool, } /// Options used during writing SVG transforms. pub struct WriteOptionsTransforms { /// Simplify transform matrices into short equivalent when possible. /// /// If not set - all transform will be saved as 'matrix'. /// /// Examples: /// /// ```text /// matrix(1 0 0 1 10 20) -> translate(10 20) /// matrix(1 0 0 1 10 0) -> translate(10) /// matrix(2 0 0 3 0 0) -> scale(2 3) /// matrix(2 0 0 2 0 0) -> scale(2) /// matrix(0 1 -1 0 0 0) -> rotate(-90) /// ``` /// /// Default: disabled pub simplify_matrix: bool, // TODO: compact notation } /// Options used during writing. pub struct WriteOptions { // TODO: Sort attributes alphabetically /// Set XML nodes indention. /// /// Range: -1..4 (-1 indicates no spaces and new lines) /// /// Example: /// /// Before: /// /// ```text /// <svg> /// <rect fill="red"/> /// </svg> /// /// ``` /// /// After: /// /// ```text /// <svg><rect fill="red"/></svg> /// ``` /// /// Default: 4 pub indent: i8, /// Use single quote marks instead of double quote. /// /// Example: /// /// ```text /// <rect fill="red"/> /// <rect fill='red'/> /// ``` /// /// Default: disabled pub use_single_quote: bool, /// Use #RGB color notation when possible. /// /// By default all colors written using #RRGGBB notation. /// /// Example: /// /// `#ff0000` -> `#f00`, `#000000` -> `#000`, `#00aa00` -> `#0a0` /// /// Default: disabled pub trim_hex_colors: bool, /// Write hidden attributes. /// /// libsvgdom support invisible attributes, which can be dumped to output using this option. /// /// See `svgdom::Attribute` documentation. /// /// Default: disabled pub write_hidden_attributes: bool, /// Numbers options. /// /// See `WriteOptionsNumbers` documentation. pub numbers: WriteOptionsNumbers, /// Paths options. /// /// See `WriteOptionsPaths` documentation. pub paths: WriteOptionsPaths, /// Transforms options. /// /// See `WriteOptionsTransforms` documentation. pub transforms: WriteOptionsTransforms, } impl Default for WriteOptions { fn default() -> WriteOptions { WriteOptions { indent: 4, use_single_quote: false, trim_hex_colors: false, write_hidden_attributes: false, numbers: WriteOptionsNumbers { precision_coordinates: 6, precision_transforms: 8, remove_leading_zero: false, }, paths: WriteOptionsPaths { use_compact_notation: false, join_arc_to_flags: false, remove_duplicated_commands: false, }, transforms: WriteOptionsTransforms { simplify_matrix: false, }, } } }