svgcleaner 0.8.0

svgcleaner could help you to clean up yours SVG files from the unnecessary data.
Documentation
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
diff --git a/Cargo.toml b/Cargo.toml
index 4b98ce6..a9e0970 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,9 +11,9 @@ readme = "README.md"
 
 [dependencies]
 # latest
-svgdom = { git = "https://github.com/RazrFalcon/libsvgdom.git" }
+# svgdom = { git = "https://github.com/RazrFalcon/libsvgdom.git" }
 # local copy
-# svgdom = { path = "../svgdom" }
+svgdom = { path = "../svgdom" }
 # from crates
 # svgdom = "0.2.0"
 
diff --git a/src/cli.rs b/src/cli.rs
index 1b1a31e..3ca2766 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -66,6 +66,7 @@ pub enum Key {
     PathsToRelative,
     RemoveUnusedSegments,
     ConvertSegments,
+    ApplyTransformToPaths,
     TrimPaths,
     JoinArcToFlags,
     RemoveDuplCmdInPaths,
@@ -130,6 +131,7 @@ pub static KEYS: &'static KeysData<'static> = &KeysData(&[
     "paths-to-relative",
     "remove-unused-segments",
     "convert-segments",
+    "apply-transform-to-paths",
     "trim-paths",
     "join-arcto-flags",
     "remove-dupl-cmd-in-paths",
@@ -214,6 +216,7 @@ pub fn prepare_app<'a, 'b>() -> App<'a, 'b> {
         .arg(gen_flag!(Key::PathsToRelative, "true"))
         .arg(gen_flag!(Key::RemoveUnusedSegments, "true"))
         .arg(gen_flag!(Key::ConvertSegments, "true"))
+        .arg(gen_flag!(Key::ApplyTransformToPaths, "true"))
         .arg(gen_flag!(Key::TrimPaths, "true"))
         .arg(gen_flag!(Key::JoinArcToFlags, "false"))
         .arg(gen_flag!(Key::RemoveDuplCmdInPaths, "true"))
@@ -308,6 +311,10 @@ pub fn check_values(args: &ArgMatches) -> bool {
         return false;
     }
 
+    // if !check_value(args, Key::PathsToRelative, Key::ApplyTransformToPaths) {
+    //     return false;
+    // }
+
     true
 }
 
diff --git a/src/task/apply_transforms/gradients.rs b/src/task/apply_transforms/gradients.rs
index 0222c4c..ff496a9 100644
--- a/src/task/apply_transforms/gradients.rs
+++ b/src/task/apply_transforms/gradients.rs
@@ -20,10 +20,10 @@
 **
 ****************************************************************************/
 
-use task::short::{EId, AId, Unit};
+use task::short::{EId, AId};
+use super::utils;
 
-use svgdom::{Document, Node};
-use svgdom::types::{Length};
+use svgdom::Document;
 
 pub fn apply_transform_to_gradients(doc: &Document) {
     let iter = doc.descendants().svg()
@@ -58,73 +58,26 @@ pub fn apply_transform_to_gradients(doc: &Document) {
 
         let ts = *node.attribute_value(AId::GradientTransform).unwrap().as_transform().unwrap();
 
-        // If transform has non-proportional scale - we should skip it,
-        // because it can be applied only to a raster.
-        if ts.has_scale() && !ts.has_proportional_scale() {
+        if !utils::is_valid_transform(&ts) {
             continue;
         }
 
-        // If transform has skew part - we should skip it,
-        // because it can be applied only to a raster.
-        if ts.has_skew() {
+        if !utils::is_valid_coords(&node) {
             continue;
         }
 
         if node.is_tag_name(EId::LinearGradient) {
-            let x1 = get_coord(&node, AId::X1);
-            let y1 = get_coord(&node, AId::Y1);
-
-            let x2 = get_coord(&node, AId::X2);
-            let y2 = get_coord(&node, AId::Y2);
-
-            // We can apply transform only to coordinates with px/none units.
-            if    x1.unit != Unit::None || y1.unit != Unit::None
-               || x2.unit != Unit::None || y2.unit != Unit::None {
-                continue;
-            }
-
-            {
-                let (x, y) = ts.apply(x1.num, y1.num);
-                node.set_attribute(AId::X1, (x, Unit::None));
-                node.set_attribute(AId::Y1, (y, Unit::None));
-            }
-
-            {
-                let (x, y) = ts.apply(x2.num, y2.num);
-                node.set_attribute(AId::X2, (x, Unit::None));
-                node.set_attribute(AId::Y2, (y, Unit::None));
-            }
+            let mut attrs = node.attributes_mut();
+            utils::scale_pos_coord(&mut attrs, AId::X1, AId::Y1, &ts);
+            utils::scale_pos_coord(&mut attrs, AId::X2, AId::Y2, &ts);
         } else {
-            let cx = get_coord(&node, AId::Cx);
-            let cy = get_coord(&node, AId::Cy);
-
-            let fx = get_coord(&node, AId::Fx);
-            let fy = get_coord(&node, AId::Fy);
-
-            let r = get_coord(&node, AId::R);
+            let mut attrs = node.attributes_mut();
+            utils::scale_pos_coord(&mut attrs, AId::Cx, AId::Cy, &ts);
+            utils::scale_pos_coord(&mut attrs, AId::Fx, AId::Fy, &ts);
 
-            // We can apply transform only to coordinates with px/none units.
-            if    cx.unit != Unit::None || cy.unit != Unit::None
-               || fx.unit != Unit::None || fy.unit != Unit::None
-               || r.unit  != Unit::None {
-                continue;
-            }
-
-            {
-                let (x, y) = ts.apply(cx.num, cy.num);
-                node.set_attribute(AId::Cx, (x, Unit::None));
-                node.set_attribute(AId::Cy, (y, Unit::None));
-            }
-
-            {
-                let (x, y) = ts.apply(fx.num, fy.num);
-                node.set_attribute(AId::Fx, (x, Unit::None));
-                node.set_attribute(AId::Fy, (y, Unit::None));
-            }
-
-            {
+            if ts.has_scale() {
                 let (sx, _) = ts.get_scale();
-                node.set_attribute(AId::R, (r.num * sx, Unit::None));
+                utils::scale_coord(&mut attrs, AId::R, &sx);
             }
         }
 
@@ -132,10 +85,6 @@ pub fn apply_transform_to_gradients(doc: &Document) {
     }
 }
 
-fn get_coord(node: &Node, aid: AId) -> Length {
-    *node.attribute_value(aid).unwrap().as_length().unwrap()
-}
-
 #[cfg(test)]
 mod tests {
     use super::*;
diff --git a/src/task/apply_transforms/mod.rs b/src/task/apply_transforms/mod.rs
index 6a9d8dd..b157623 100644
--- a/src/task/apply_transforms/mod.rs
+++ b/src/task/apply_transforms/mod.rs
@@ -25,3 +25,119 @@ pub use self::shapes::apply_transform_to_shapes;
 
 mod gradients;
 mod shapes;
+
+pub mod utils {
+    use task::short::{EId, AId, Unit};
+
+    use svgdom::{Node, Attributes, AttributeValue};
+    use svgdom::types::{Length, Transform};
+
+    // TODO: remove
+    pub fn has_valid_transform(node: &Node) -> bool {
+        if !node.has_attribute(AId::Transform) {
+            return true;
+        }
+
+        let ts = get_ts(node);
+        is_valid_transform(&ts)
+    }
+
+    pub fn is_valid_transform(ts: &Transform) -> bool {
+        // If transform has non-proportional scale - we should skip it,
+        // because it can be applied only to a raster.
+        if ts.has_scale() && !ts.has_proportional_scale() {
+            return false;
+        }
+
+        // TODO: is rotate supported?
+
+        // If transform has skew part - we should skip it,
+        // because it can be applied only to a raster.
+        if ts.has_skew() {
+            return false;
+        }
+
+        return true;
+    }
+
+    // Element shouldn't have any linked elements, because they also must be transformed.
+    // TODO: process 'fill', 'stroke' and 'filter' linked elements only if they
+    //       used only by this element.
+    pub fn is_valid_attrs(node: &Node) -> bool {
+        let attrs = node.attributes();
+
+        if let Some(&AttributeValue::FuncLink(_)) = attrs.get_value(AId::Fill) {
+            return false;
+        }
+
+        if let Some(&AttributeValue::FuncLink(_)) = attrs.get_value(AId::Stroke) {
+            return false;
+        }
+
+        if let Some(&AttributeValue::FuncLink(_)) = attrs.get_value(AId::Filter) {
+            return false;
+        }
+
+        if attrs.contains(AId::Mask) || attrs.contains(AId::ClipPath) {
+            return false;
+        }
+
+        return true;
+    }
+
+    // We can process only coordinates without units.
+    pub fn is_valid_coords(node: &Node) -> bool {
+        match node.tag_id().unwrap() {
+            EId::Rect =>    _is_valid_coords(node, &[AId::X, AId::Y]),
+            EId::Circle =>  _is_valid_coords(node, &[AId::Cx, AId::Cy]),
+            EId::Ellipse => _is_valid_coords(node, &[AId::Cx, AId::Cy]),
+            EId::Line =>    _is_valid_coords(node, &[AId::X1, AId::Y1, AId::X2, AId::Y2]),
+            EId::LinearGradient => _is_valid_coords(node, &[AId::X1, AId::Y1, AId::X2, AId::Y2]),
+            EId::RadialGradient => _is_valid_coords(node, &[AId::Cx, AId::Cy, AId::Fx, AId::Fy, AId::R]),
+            _ => false,
+        }
+    }
+
+    fn _is_valid_coords(node: &Node, attr_ids: &[AId]) -> bool {
+        let attrs = node.attributes();
+
+        fn is_valid_coord(attrs: &Attributes, aid: AId) -> bool {
+            if let Some(&AttributeValue::Length(v)) = attrs.get_value(aid) {
+                v.unit == Unit::None
+            } else {
+                true
+            }
+        }
+
+        for id in attr_ids {
+            if !is_valid_coord(&attrs, *id) {
+                return false;
+            }
+        }
+
+        true
+    }
+
+    // TODO: rename to transform_coords
+    pub fn scale_pos_coord(attrs: &mut Attributes, aid_x: AId, aid_y: AId, ts: &Transform) {
+        let x = get_value!(attrs, Length, aid_x, Length::zero());
+        let y = get_value!(attrs, Length, aid_y, Length::zero());
+
+        debug_assert!(x.unit == Unit::None);
+        debug_assert!(y.unit == Unit::None);
+
+        let (nx, ny) = ts.apply(x.num, y.num);
+        attrs.insert_from(aid_x, (nx, Unit::None));
+        attrs.insert_from(aid_y, (ny, Unit::None));
+    }
+
+    pub fn scale_coord(attrs: &mut Attributes, aid: AId, scale_factor: &f64) {
+        if let Some(&mut AttributeValue::Length(ref mut len)) = attrs.get_value_mut(aid) {
+            len.num *= *scale_factor;
+        }
+    }
+
+    pub fn get_ts(node: &Node) -> Transform {
+        *node.attribute_value(AId::Transform).unwrap().as_transform().unwrap()
+    }
+}
diff --git a/src/task/apply_transforms/shapes.rs b/src/task/apply_transforms/shapes.rs
index 0fc5219..43fcc72 100644
--- a/src/task/apply_transforms/shapes.rs
+++ b/src/task/apply_transforms/shapes.rs
@@ -20,10 +20,11 @@
 **
 ****************************************************************************/
 
-use task::short::{EId, AId, Unit};
+use task::short::{EId, AId};
+use super::utils;
 
-use svgdom::{Document, Node, Attributes, AttributeValue};
-use svgdom::types::{Length, Transform};
+use svgdom::{Document, Node, Attributes};
+use svgdom::types::{Transform};
 
 pub fn apply_transform_to_shapes(doc: &Document) {
     // If group has transform and contains only valid shapes
@@ -35,7 +36,7 @@ pub fn apply_transform_to_shapes(doc: &Document) {
                                                   && n.has_attribute(AId::Transform));
 
     for node in iter {
-        if !is_valid_transform(&node) || !is_valid_attrs(&node) {
+        if !utils::has_valid_transform(&node) || !utils::is_valid_attrs(&node) {
             continue;
         }
 
@@ -49,16 +50,19 @@ pub fn apply_transform_to_shapes(doc: &Document) {
                 _ => false,
             };
 
-            flag && is_valid_transform(&n) && is_valid_attrs(&n) && is_valid_coords(&n)
+               flag
+            && utils::has_valid_transform(&n)
+            && utils::is_valid_attrs(&n)
+            && utils::is_valid_coords(&n)
         }) {
-            let ts = get_ts(&node);
+            let ts = utils::get_ts(&node);
 
             // apply group's transform to children
             for child in node.children().svg() {
                 if child.has_attribute(AId::Transform) {
                     // we should multiply transform matrices
                     let mut ts1 = ts.clone();
-                    let ts2 = get_ts(&child);
+                    let ts2 = utils::get_ts(&child);
                     ts1.append(&ts2);
                     child.set_attribute(AId::Transform, ts1);
                 } else {
@@ -89,11 +93,13 @@ pub fn apply_transform_to_shapes(doc: &Document) {
 fn process<F>(node: &Node, func: F)
     where F : Fn(&mut Attributes, &Transform)
 {
-    if !is_valid_transform(node) || !is_valid_attrs(node) || !is_valid_coords(node) {
+    if    !utils::has_valid_transform(node)
+       || !utils::is_valid_attrs(node)
+       || !utils::is_valid_coords(node) {
         return;
     }
 
-    let ts = get_ts(node);
+    let ts = utils::get_ts(node);
 
     {
         let mut attrs = node.attributes_mut();
@@ -110,150 +116,50 @@ fn process<F>(node: &Node, func: F)
 
 fn process_rect(node: &Node) {
     process(node, |mut attrs, ts| {
-        scale_pos_coord(&mut attrs, AId::X, AId::Y, &ts);
+        utils::scale_pos_coord(&mut attrs, AId::X, AId::Y, &ts);
 
         if ts.has_scale() {
             let (sx, _) = ts.get_scale();
 
-            scale_coord(&mut attrs, AId::Width, &sx);
-            scale_coord(&mut attrs, AId::Height, &sx);
+            utils::scale_coord(&mut attrs, AId::Width, &sx);
+            utils::scale_coord(&mut attrs, AId::Height, &sx);
 
-            scale_coord(&mut attrs, AId::Rx, &sx);
-            scale_coord(&mut attrs, AId::Ry, &sx);
+            utils::scale_coord(&mut attrs, AId::Rx, &sx);
+            utils::scale_coord(&mut attrs, AId::Ry, &sx);
         }
     });
 }
 
 fn process_circle(node: &Node) {
     process(node, |mut attrs, ts| {
-        scale_pos_coord(&mut attrs, AId::Cx, AId::Cy, &ts);
+        utils::scale_pos_coord(&mut attrs, AId::Cx, AId::Cy, &ts);
 
         if ts.has_scale() {
             let (sx, _) = ts.get_scale();
-            scale_coord(&mut attrs, AId::R, &sx);
+            utils::scale_coord(&mut attrs, AId::R, &sx);
         }
     });
 }
 
 fn process_ellipse(node: &Node) {
     process(node, |mut attrs, ts| {
-        scale_pos_coord(&mut attrs, AId::Cx, AId::Cy, &ts);
+        utils::scale_pos_coord(&mut attrs, AId::Cx, AId::Cy, &ts);
 
         if ts.has_scale() {
             let (sx, _) = ts.get_scale();
-            scale_coord(&mut attrs, AId::Rx, &sx);
-            scale_coord(&mut attrs, AId::Ry, &sx);
+            utils::scale_coord(&mut attrs, AId::Rx, &sx);
+            utils::scale_coord(&mut attrs, AId::Ry, &sx);
         }
     });
 }
 
 fn process_line(node: &Node) {
     process(node, |mut attrs, ts| {
-        scale_pos_coord(&mut attrs, AId::X1, AId::Y1, &ts);
-        scale_pos_coord(&mut attrs, AId::X2, AId::Y2, &ts);
+        utils::scale_pos_coord(&mut attrs, AId::X1, AId::Y1, &ts);
+        utils::scale_pos_coord(&mut attrs, AId::X2, AId::Y2, &ts);
     });
 }
 
-fn is_valid_transform(node: &Node) -> bool {
-    if !node.has_attribute(AId::Transform) {
-        return true;
-    }
-
-    let ts = get_ts(node);
-
-    // If transform has non-proportional scale - we should skip it,
-    // because it can be applied only to a raster.
-    if ts.has_scale() && !ts.has_proportional_scale() {
-        return false;
-    }
-
-    // If transform has skew part - we should skip it,
-    // because it can be applied only to a raster.
-    if ts.has_skew() {
-        return false;
-    }
-
-    return true;
-}
-
-// Element shouldn't have any linked elements, because they also must be transformed.
-// TODO: process 'fill', 'stroke' and 'filter' linked elements only if they
-//       used only by this element.
-fn is_valid_attrs(node: &Node) -> bool {
-    let attrs = node.attributes();
-
-    if let Some(&AttributeValue::FuncLink(_)) = attrs.get_value(AId::Fill) {
-        return false;
-    }
-
-    if let Some(&AttributeValue::FuncLink(_)) = attrs.get_value(AId::Stroke) {
-        return false;
-    }
-
-    if let Some(&AttributeValue::FuncLink(_)) = attrs.get_value(AId::Filter) {
-        return false;
-    }
-
-    if attrs.contains(AId::Mask) || attrs.contains(AId::ClipPath) {
-        return false;
-    }
-
-    return true;
-}
-
-// We can process only coordinates without units.
-fn is_valid_coords(node: &Node) -> bool {
-    match node.tag_id().unwrap() {
-        EId::Rect =>    _is_valid_coords(node, &[AId::X, AId::Y]),
-        EId::Circle =>  _is_valid_coords(node, &[AId::Cx, AId::Cy]),
-        EId::Ellipse => _is_valid_coords(node, &[AId::Cx, AId::Cy]),
-        EId::Line =>    _is_valid_coords(node, &[AId::X1, AId::Y1, AId::X2, AId::Y2]),
-        _ => false,
-    }
-}
-
-fn _is_valid_coords(node: &Node, attr_ids: &[AId]) -> bool {
-    let attrs = node.attributes();
-
-    fn is_valid_coord(attrs: &Attributes, aid: AId) -> bool {
-        if let Some(&AttributeValue::Length(v)) = attrs.get_value(aid) {
-            v.unit == Unit::None
-        } else {
-            true
-        }
-    }
-
-    for id in attr_ids {
-        if !is_valid_coord(&attrs, *id) {
-            return false;
-        }
-    }
-
-    true
-}
-
-fn scale_pos_coord(attrs: &mut Attributes, aid_x: AId, aid_y: AId, ts: &Transform) {
-    let x = get_value!(attrs, Length, aid_x, Length::zero());
-    let y = get_value!(attrs, Length, aid_y, Length::zero());
-
-    debug_assert!(x.unit == Unit::None);
-    debug_assert!(y.unit == Unit::None);
-
-    let (nx, ny) = ts.apply(x.num, y.num);
-    attrs.insert_from(aid_x, (nx, Unit::None));
-    attrs.insert_from(aid_y, (ny, Unit::None));
-}
-
-fn scale_coord(attrs: &mut Attributes, aid: AId, scale_factor: &f64) {
-    if let Some(&mut AttributeValue::Length(ref mut len)) = attrs.get_value_mut(aid) {
-        len.num *= *scale_factor;
-    }
-}
-
-fn get_ts(node: &Node) -> Transform {
-    *node.attribute_value(AId::Transform).unwrap().as_transform().unwrap()
-}
-
 #[cfg(test)]
 mod tests {
     use super::*;
diff --git a/src/task/paths/apply_transform.rs b/src/task/paths/apply_transform.rs
index 630792d..384be01 100644
--- a/src/task/paths/apply_transform.rs
+++ b/src/task/paths/apply_transform.rs
@@ -20,17 +20,80 @@
 **
 ****************************************************************************/
 
-// use std::cmp::Ordering;
-// use svgdom::types::path::{Path, Segment, SegmentData};
-// use svgdom::types::{FuzzyEq, FuzzyOrd};
+use svgdom::types::path::{Path, SegmentData};
+use svgdom::types::{Transform};
 
-// use super::utils;
+pub fn apply_transform(path: &mut Path, ts: &Transform) {
+    println!("transform path");
 
-pub fn apply_transform(path: &mut Path) {
+    let (sx, _) = ts.get_scale();
 
+    for seg in path.d.iter_mut() {
+        match *seg.data_mut() {
+              SegmentData::MoveTo { ref mut x, ref mut y }
+            | SegmentData::LineTo { ref mut x, ref mut y }
+            | SegmentData::SmoothQuadratic { ref mut x, ref mut y } => {
+                ts.apply_ref(x, y);
+            }
+
+            SegmentData::HorizontalLineTo { ref mut x } => {
+                ts.apply_ref(x, &mut 0.0);
+            }
+
+            SegmentData::VerticalLineTo { ref mut y } => {
+                ts.apply_ref(&mut 0.0, y);
+            }
+
+            SegmentData::CurveTo { ref mut x1, ref mut y1, ref mut x2, ref mut y2, ref mut x, ref mut y } => {
+                ts.apply_ref(x1, y1);
+                ts.apply_ref(x2, y2);
+                ts.apply_ref(x,  y);
+            }
+
+            SegmentData::SmoothCurveTo { ref mut x2, ref mut y2, ref mut x, ref mut y } => {
+                ts.apply_ref(x2, y2);
+                ts.apply_ref(x,  y);
+            }
+
+            SegmentData::Quadratic { ref mut x1, ref mut y1, ref mut x, ref mut y } => {
+                ts.apply_ref(x1, y1);
+                ts.apply_ref(x,  y);
+            }
+
+            SegmentData::EllipticalArc { ref mut rx, ref mut ry, ref mut x, ref mut y, .. } => {
+                *rx *= sx;
+                *ry *= sx;
+
+                ts.apply_ref(x,  y);
+            }
+
+            SegmentData::ClosePath => {}
+        }
+    }
 }
 
 #[cfg(test)]
 mod tests {
     use super::*;
+    use svgdom::FromStream;
+    use svgdom::types::path::Path;
+    use svgdom::types::Transform;
+
+    macro_rules! test {
+        ($name:ident, $in_path:expr, $in_ts:expr, $out_text:expr) => (
+            #[test]
+            fn $name() {
+                let mut path = Path::from_data($in_path).unwrap();
+                path.conv_to_absolute();
+
+                let ts = Transform::from_data($in_ts).unwrap();
+
+                apply_transform(&mut path, &ts);
+                assert_eq_text!(path.to_string(), $out_text);
+            }
+        )
+    }
+
+    test!(apply_1, b"M 10 20 L 30 40", b"translate(10 20)",
+                    "M 20 40 L 40 60");
 }
diff --git a/src/task/paths/mod.rs b/src/task/paths/mod.rs
index e1a55db..baef1f3 100644
--- a/src/task/paths/mod.rs
+++ b/src/task/paths/mod.rs
@@ -24,11 +24,14 @@ use clap::ArgMatches;
 
 use svgdom::{Document, AttributeValue};
 use svgdom::types::path::Path;
+use svgdom::types::{Transform};
 
 use task::short::{EId, AId};
+use task::apply_transforms::utils as ts_utils;
 use cli;
 use cli::{Key};
 
+mod apply_transform;
 mod conv_segments;
 mod rm_unused;
 
@@ -40,14 +43,37 @@ pub fn process_paths(doc: &Document, args: &ArgMatches) {
         let has_marker = node.has_attributes(&[AId::Marker, AId::MarkerStart,
                                                AId::MarkerMid, AId::MarkerEnd]);
 
+
+        let mut ts = None;
+        // if cli::get_flag(args, Key::ApplyTransformToPaths) {
+        //     if node.has_attribute(AId::Transform) {
+        //         let tsl = ts_utils::get_ts(&node);
+
+        //         if    ts_utils::is_valid_transform(&tsl)
+        //            && ts_utils::is_valid_attrs(&node) {
+        //             ts = Some(tsl);
+
+        //             println!("{:?}", node);
+
+        //             node.remove_attribute(AId::Transform);
+
+        //             if tsl.has_scale() {
+        //                 // we must update 'stroke-width' if transform had scale part in it
+        //                 let (sx, _) = tsl.get_scale();
+        //                 ::task::utils::recalc_stroke_width(&node, sx);
+        //             }
+        //         }
+        //     }
+        // }
+
         let mut attrs = node.attributes_mut();
         if let Some(&mut AttributeValue::Path(ref mut path)) = attrs.get_value_mut(AId::D) {
-            process_path(path, has_marker, args);
+            process_path(path, has_marker, ts, args);
         }
     }
 }
 
-fn process_path(path: &mut Path, has_marker: bool, args: &ArgMatches) {
+fn process_path(path: &mut Path, has_marker: bool, ts: Option<Transform>, args: &ArgMatches) {
     path.conv_to_absolute();
 
     if cli::get_flag(args, Key::ConvertSegments) {
@@ -58,6 +84,10 @@ fn process_path(path: &mut Path, has_marker: bool, args: &ArgMatches) {
         rm_unused::remove_unused_segments(path);
     }
 
+    // if let Some(ref ts) = ts {
+    //     apply_transform::apply_transform(path, ts);
+    // }
+
     path.conv_to_relative();
 
     // TODO: estimate path length
@@ -73,6 +103,7 @@ fn process_path(path: &mut Path, has_marker: bool, args: &ArgMatches) {
 mod utils {
     use svgdom::types::path::{Path};
 
+    // TODO: replace with macro
     pub fn resolve_x(path: &Path, start: usize) -> f64 {
         // VerticalLineTo does not have `x` coordinate, so we have to find it in previous segments
         let mut i = start;
diff --git a/src/task/resolve_use.rs b/src/task/resolve_use.rs
index a158294..f8bd26b 100644
--- a/src/task/resolve_use.rs
+++ b/src/task/resolve_use.rs
@@ -78,9 +78,10 @@ pub fn resolve_use(doc: &Document) {
                     continue;
                 }
 
-                let ts = get_value!(attrs, Transform, AId::Transform, Transform::default());
+                let mut ts = get_value!(attrs, Transform, AId::Transform, Transform::default());
+                ts.translate(x.num, y.num);
 
-                attrs.insert_from(AId::Transform, ts.translate(x.num, y.num));
+                attrs.insert_from(AId::Transform, ts);
                 attrs.remove(AId::X);
                 attrs.remove(AId::Y);
             }
diff --git a/src/task/rm_elems.rs b/src/task/rm_elems.rs
index e67c6ae..08467ed 100644
--- a/src/task/rm_elems.rs
+++ b/src/task/rm_elems.rs
@@ -24,6 +24,7 @@ use super::short::EId;
 
 use svgdom::Document;
 
+// TODO: to mod::utils
 pub fn remove_element(doc: &Document, id: EId) {
     doc.drain(|n| n.is_tag_name(id));
 }
@@ -44,6 +45,8 @@ mod tests {
         )
     }
 
+    // TODO: this tests should be in svgdom
+
     test!(rm_1, ElementId::Title,
 b"<svg>
     <title/>
diff --git a/tools/files-testing/data/oxygen.json b/tools/files-testing/data/oxygen.json
index 59fa823..7fc5dfb 100644
--- a/tools/files-testing/data/oxygen.json
+++ b/tools/files-testing/data/oxygen.json
@@ -37,18 +37,10 @@
             "valid_ae": 1941
         },
         {
-            "name": "actions/small/48x48/view-bank-account.svg",
-            "valid_ae": 1661
-        },
-        {
             "name": "actions/small/48x48/view-loan.svg",
             "valid_ae": 1925
         },
         {
-            "name": "actions/small/48x48/view-bank-account-checking.svg",
-            "valid_ae": 1536
-        },
-        {
             "name": "devices/small/16x16/camera-photo.svg",
             "valid_ae": 1379
         },
@@ -129,10 +121,6 @@
             "valid_ae": 1860
         },
         {
-            "name": "status/user-busy.svg",
-            "valid_ae": 1083
-        },
-        {
             "name": "status/user-away-extended.svg",
             "valid_ae": 1860
         },
@@ -141,14 +129,6 @@
             "valid_ae": 1091
         },
         {
-            "name": "status/user-offline.svg",
-            "valid_ae": 1083
-        },
-        {
-            "name": "status/user-online.svg",
-            "valid_ae": 1221
-        },
-        {
             "name": "categories/applications-toys.svg",
             "valid_ae": 1153
         },
@@ -189,10 +169,6 @@
             "valid_ae": 1336
         },
         {
-            "name": "actions/small/22x22/edit-image-face-recognize.svg",
-            "valid_ae": 1162
-        },
-        {
             "name": "actions/small/22x22/edit-image-face-add.svg",
             "valid_ae": 1152
         },
@@ -544,6 +520,158 @@
         {
             "name": "mimetypes/small/48x48/image-svg+xml-compressed.svg",
             "valid_ae": 170179
+        },
+        {
+            "name": "status/user-busy.svg",
+            "valid_ae": 1345
+        },
+        {
+            "name": "status/user-offline.svg",
+            "valid_ae": 1345
+        },
+        {
+            "name": "status/user-online.svg",
+            "valid_ae": 1483
+        },
+        {
+            "name": "categories/small/22x22/preferences-desktop-personal.svg",
+            "valid_ae": 570
+        },
+        {
+            "name": "actions/small/22x22/edit-image-face-recognize.svg",
+            "valid_ae": 1235
+        },
+        {
+            "name": "actions/small/48x48/view-bank-account.svg",
+            "valid_ae": 1662
+        },
+        {
+            "name": "actions/small/48x48/view-bank-account-checking.svg",
+            "valid_ae": 1537
+        },
+        {
+            "name": "actions/edit-bomb.svg",
+            "valid_ae": 1366
+        },
+        {
+            "name": "devices/secure-card.svg",
+            "valid_ae": 420
+        },
+        {
+            "name": "devices/small/32x32/secure-card.svg",
+            "valid_ae": 677
+        },
+        {
+            "name": "devices/small/48x48/secure-card.svg",
+            "valid_ae": 611
+        },
+        {
+            "name": "emotes/face-uncertain.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/face-surprise.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/face-wink.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/face-smile-big.svg",
+            "valid_ae": 13393
+        },
+        {
+            "name": "emotes/face-sad.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/face-plain.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/small/16x16/face-uncertain.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/small/16x16/face-smile-big.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/small/16x16/face-sad.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/small/16x16/face-kiss.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/small/16x16/face-angel.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/small/16x16/face-raspberry.svg",
+            "valid_ae": 13187
+        },
+        {
+            "name": "emotes/small/16x16/face-laugh.svg",
+            "valid_ae": 13452
+        },
+        {
+            "name": "emotes/small/22x22/face-uncertain.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/small/22x22/face-smile-big.svg",
+            "valid_ae": 13833
+        },
+        {
+            "name": "emotes/small/22x22/face-sad.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/small/22x22/face-kiss.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/small/22x22/face-angel.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/small/22x22/face-raspberry.svg",
+            "valid_ae": 13356
+        },
+        {
+            "name": "emotes/small/22x22/face-laugh.svg",
+            "valid_ae": 13510
+        },
+        {
+            "name": "emotes/face-smile.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/face-kiss.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/face-angel.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/face-embarrassed.svg",
+            "valid_ae": 14450
+        },
+        {
+            "name": "emotes/face-raspberry.svg",
+            "valid_ae": 13921
+        },
+        {
+            "name": "emotes/face-laugh.svg",
+            "valid_ae": 12892
+        },
+        {
+            "name": "mimetypes/small/16x16/text-x-hex.svg",
+            "valid_ae": 901
         }
     ],
     "ignore": [
diff --git a/tools/stats/src/main.rs b/tools/stats/src/main.rs
index c8f6e88..179ed4e 100644
--- a/tools/stats/src/main.rs
+++ b/tools/stats/src/main.rs
@@ -329,6 +329,7 @@ fn clean_with_new_cleaner(exe_path: &str, in_path: &str, out_path: &str) -> bool
                 .arg(in_path)
                 .arg(out_path)
                 .arg("--copy-on-error=true")
+                // .arg("--apply-transform-to-paths=false")
                 .arg("--quiet=true")
                 .output();