@@ -114,7 +114,7 @@ function parse(){
114
114
return $ this ->data = $ data ;
115
115
}
116
116
117
- public function getSVGPath (){
117
+ public function getSVGContours (){
118
118
$ path = "" ;
119
119
120
120
$ points = $ this ->data ["points " ];
@@ -126,7 +126,7 @@ public function getSVGPath(){
126
126
$ count ++;
127
127
128
128
if ($ points [$ i ]["endOfContour " ]) {
129
- $ path .= $ this ->addContourToPath ($ points , $ firstIndex , $ count );
129
+ $ path .= $ this ->getSVGPath ($ points , $ firstIndex , $ count );
130
130
$ firstIndex = $ i + 1 ;
131
131
$ count = 0 ;
132
132
}
@@ -140,42 +140,45 @@ public function parseSVGPath($path) {
140
140
return $ matches [0 ];
141
141
}
142
142
143
- protected function addContourToPath ($ points , $ startIndex , $ count ) {
143
+ protected function getSVGPath ($ points , $ startIndex , $ count ) {
144
144
$ offset = 0 ;
145
145
$ path = "" ;
146
146
147
147
while ($ offset < $ count ) {
148
- $ point_m1 = $ points [ ($ offset == 0 ) ? ($ startIndex +$ count -1 ) : $ startIndex +($ offset -1 )%$ count ];
149
- $ point = $ points [ $ startIndex + $ offset %$ count ];
148
+ $ point = $ points [ $ startIndex + $ offset %$ count ];
150
149
$ point_p1 = $ points [ $ startIndex + ($ offset +1 )%$ count ];
151
- $ point_p2 = $ points [ $ startIndex + ($ offset +2 )%$ count ];
152
150
153
151
if ($ offset == 0 ) {
154
152
$ path .= "M {$ point ['x ' ]}, {$ point ['y ' ]} " ;
155
153
}
156
154
157
- if ($ point ["onCurve " ] && $ point_p1 ["onCurve " ]) {
158
- $ path .= "L {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]} " ;
159
- $ offset ++;
160
- }
161
- else if ($ point ["onCurve " ] && !$ point_p1 ["onCurve " ] && $ point_p2 ["onCurve " ]){
162
- $ path .= "Q {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]}, {$ point_p2 ['x ' ]}, {$ point_p2 ['y ' ]} " ;
163
- $ offset += 2 ;
164
- }
165
- else if ($ point ["onCurve " ] && !$ point_p1 ["onCurve " ] && !$ point_p2 ["onCurve " ]){
166
- $ path .= "Q {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]}, " .$ this ->midValue ($ point_p1 ['x ' ], $ point_p2 ['x ' ]).", " .$ this ->midValue ($ point_p1 ['y ' ], $ point_p2 ['y ' ])." " ;
167
- $ offset += 2 ;
168
- }
169
- else if (!$ point ["onCurve " ] && !$ point_p1 ["onCurve " ]) {
170
- $ path .= "Q {$ point ['x ' ]}, {$ point ['y ' ]}, " .$ this ->midValue ($ point ['x ' ], $ point_p1 ['x ' ]).", " .$ this ->midValue ($ point ['y ' ], $ point_p1 ['y ' ])." " ;
171
- $ offset ++;
172
- }
173
- else if (!$ point ["onCurve " ] && $ point_p1 ["onCurve " ]) {
174
- $ path .= "Q {$ point ['x ' ]}, {$ point ['y ' ]}, {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]} " ;
175
- $ offset ++;
176
- }
155
+ if ($ point ["onCurve " ]) {
156
+ if ($ point_p1 ["onCurve " ]) {
157
+ $ path .= "L {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]} " ;
158
+ $ offset ++;
159
+ }
160
+ else {
161
+ $ point_p2 = $ points [ $ startIndex + ($ offset +2 )%$ count ];
162
+
163
+ if ($ point_p2 ["onCurve " ]){
164
+ $ path .= "Q {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]}, {$ point_p2 ['x ' ]}, {$ point_p2 ['y ' ]} " ;
165
+ }
166
+ else {
167
+ $ path .= "Q {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]}, " .$ this ->midValue ($ point_p1 ['x ' ], $ point_p2 ['x ' ]).", " .$ this ->midValue ($ point_p1 ['y ' ], $ point_p2 ['y ' ])." " ;
168
+ }
169
+
170
+ $ offset += 2 ;
171
+ }
172
+ }
177
173
else {
178
- break ;
174
+ if ($ point_p1 ["onCurve " ]) {
175
+ $ path .= "Q {$ point ['x ' ]}, {$ point ['y ' ]}, {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]} " ;
176
+ }
177
+ else {
178
+ $ path .= "Q {$ point ['x ' ]}, {$ point ['y ' ]}, " .$ this ->midValue ($ point ['x ' ], $ point_p1 ['x ' ]).", " .$ this ->midValue ($ point ['y ' ], $ point_p1 ['y ' ])." " ;
179
+ }
180
+
181
+ $ offset ++;
179
182
}
180
183
}
181
184
0 commit comments