@@ -35,6 +35,7 @@ let arcTolerance;
35
35
* tolerance: number,
36
36
* },
37
37
* straightCurves: boolean,
38
+ * convertToQ: boolean,
38
39
* lineShorthands: boolean,
39
40
* convertToZ: boolean,
40
41
* curveSmoothShorthands: boolean,
@@ -86,6 +87,7 @@ exports.fn = (root, params) => {
86
87
tolerance : 0.5 , // percentage of radius
87
88
} ,
88
89
straightCurves = true ,
90
+ convertToQ = true ,
89
91
lineShorthands = true ,
90
92
convertToZ = true ,
91
93
curveSmoothShorthands = true ,
@@ -109,6 +111,7 @@ exports.fn = (root, params) => {
109
111
applyTransformsStroked,
110
112
makeArcs,
111
113
straightCurves,
114
+ convertToQ,
112
115
lineShorthands,
113
116
convertToZ,
114
117
curveSmoothShorthands,
@@ -674,6 +677,44 @@ function filters(
674
677
}
675
678
}
676
679
680
+ // degree-lower c to q when possible
681
+ // m 0 12 C 4 4 8 4 12 12 → M 0 12 Q 6 0 12 12
682
+ if ( params . convertToQ && command == 'c' ) {
683
+ const x1 =
684
+ // @ts -ignore
685
+ 0.75 * ( item . base [ 0 ] + data [ 0 ] ) - 0.25 * item . base [ 0 ] ;
686
+ const x2 =
687
+ // @ts -ignore
688
+ 0.75 * ( item . base [ 0 ] + data [ 2 ] ) - 0.25 * ( item . base [ 0 ] + data [ 4 ] ) ;
689
+ if ( Math . abs ( x1 - x2 ) < error * 2 ) {
690
+ const y1 =
691
+ // @ts -ignore
692
+ 0.75 * ( item . base [ 1 ] + data [ 1 ] ) - 0.25 * item . base [ 1 ] ;
693
+ const y2 =
694
+ // @ts -ignore
695
+ 0.75 * ( item . base [ 1 ] + data [ 3 ] ) - 0.25 * ( item . base [ 1 ] + data [ 5 ] ) ;
696
+ if ( Math . abs ( y1 - y2 ) < error * 2 ) {
697
+ const newData = data . slice ( ) ;
698
+ newData . splice (
699
+ 0 ,
700
+ 4 ,
701
+ // @ts -ignore
702
+ x1 + x2 - item . base [ 0 ] ,
703
+ // @ts -ignore
704
+ y1 + y2 - item . base [ 1 ] ,
705
+ ) ;
706
+ roundData ( newData ) ;
707
+ const originalLength = cleanupOutData ( data , params ) . length ,
708
+ newLength = cleanupOutData ( newData , params ) . length ;
709
+ if ( newLength < originalLength ) {
710
+ command = 'q' ;
711
+ data = newData ;
712
+ if ( next && next . command == 's' ) makeLonghand ( next , data ) ; // fix up next curve
713
+ }
714
+ }
715
+ }
716
+ }
717
+
677
718
// horizontal and vertical line shorthands
678
719
// l 50 0 → h 50
679
720
// l 0 50 → v 50
0 commit comments