@scratch/scratch-svg-renderer 11.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.editorconfig +15 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +10 -0
  4. package/.gitattributes +38 -0
  5. package/.nvmrc +1 -0
  6. package/CHANGELOG.md +1300 -0
  7. package/LICENSE +12 -0
  8. package/README.md +89 -0
  9. package/TRADEMARK +1 -0
  10. package/commitlint.config.js +4 -0
  11. package/package.json +76 -0
  12. package/playground/index.html +132 -0
  13. package/playground/scratch-svg-renderer.js +17830 -0
  14. package/playground/scratch-svg-renderer.js.map +1 -0
  15. package/release.config.js +14 -0
  16. package/src/bitmap-adapter.js +156 -0
  17. package/src/fixup-svg-string.js +61 -0
  18. package/src/font-converter.js +38 -0
  19. package/src/font-inliner.js +50 -0
  20. package/src/index.js +22 -0
  21. package/src/load-svg-string.js +334 -0
  22. package/src/playground/index.html +132 -0
  23. package/src/sanitize-svg.js +104 -0
  24. package/src/serialize-svg-to-string.js +19 -0
  25. package/src/svg-element.js +71 -0
  26. package/src/svg-renderer.js +169 -0
  27. package/src/transform-applier.js +628 -0
  28. package/src/util/log.js +4 -0
  29. package/test/bitmapAdapter_getResized.js +102 -0
  30. package/test/fixtures/css-import.sanitized.svg +5 -0
  31. package/test/fixtures/css-import.svg +11 -0
  32. package/test/fixtures/embedded-cat-foo.sanitized.svg +3 -0
  33. package/test/fixtures/embedded-cat-foo.svg +3 -0
  34. package/test/fixtures/embedded-cat-xlink.svg +3 -0
  35. package/test/fixtures/hearts.svg +31 -0
  36. package/test/fixtures/invalid-cloud.svg +1 -0
  37. package/test/fixtures/metadata-body.svg +6 -0
  38. package/test/fixtures/metadata-onload.sanitized.svg +3 -0
  39. package/test/fixtures/metadata-onload.svg +7 -0
  40. package/test/fixtures/onload-script.svg +7 -0
  41. package/test/fixtures/red-and-white-carousel-pound-in-href.sanitized.svg +74 -0
  42. package/test/fixtures/red-and-white-carousel-pound-in-href.svg +74 -0
  43. package/test/fixtures/reserved-namespace.sanitized.svg +3 -0
  44. package/test/fixtures/reserved-namespace.svg +4 -0
  45. package/test/fixtures/scratch_cat_bitmap_within_svg.sanitized.svg +1 -0
  46. package/test/fixtures/scratch_cat_bitmap_within_svg.svg +1 -0
  47. package/test/fixtures/script.sanitized.svg +4 -0
  48. package/test/fixtures/script.svg +8 -0
  49. package/test/fixtures/svg-tag-prefixes.svg +37 -0
  50. package/test/fixup-svg-string.js +144 -0
  51. package/test/sanitize-svg.js +34 -0
  52. package/test/test-output/transform-applier-test.html +373 -0
  53. package/test/transform-applier.js +796 -0
  54. package/webpack.config.js +72 -0
@@ -0,0 +1,796 @@
1
+ // Test transform-applier
2
+
3
+ const test = require('tap').test;
4
+ const jsdom = require('jsdom');
5
+ const {JSDOM} = jsdom;
6
+ const transformStrokeWidths = require('../src/transform-applier');
7
+ const log = require('../src/util/log');
8
+
9
+ // PathData, absolute instructions only
10
+ const d = 'M -20 -20 0 10 ' +
11
+ 'L 5 5 H 10 V 10 ' +
12
+ 'C 10 10 20 10 15 25 ' +
13
+ 'S 15 30 15 40 ' +
14
+ 'Q 20 50 30 60 ' +
15
+ 'T 30 70 20 80 ' +
16
+ 'M 0 0 ' +
17
+ 'A 40 50 0 1 1 0 100 Z ';
18
+ // Path constructed specifically for testing elliptical arcs
19
+ const ellipticalPath = 'M10,300 l 50,-25 ' +
20
+ 'a25,25 -60 0,1 50,-25 l 50,-25 ' +
21
+ 'a25,50 -45 0,1 50,-25 l 50,-25 ' +
22
+ 'a25,75 -30 0,1 50,-25 l 50,-25 ' +
23
+ 'a25,100 -15 0,1 50,-25 l 50,-25 v 50 l -50,25 ' +
24
+ 'a25,25 60 1,1 -50,25 l -50,25 ' +
25
+ 'a25,50 45 1,1 -50,25 l -50,25 ' +
26
+ 'a25,75 30 1,1 -50,25 l -50,25 ' +
27
+ 'a25,100 15 1,1 -50,25 l -50,25 ';
28
+
29
+ // This path is tricky because all of its bounds lie outside
30
+ // the 2 given points
31
+ const trickyBoundsPath = 'M 40 40 A 30 50 -45 1,1 80 80';
32
+ // Because jsdom doesn't simulate SvgElement.getBBox(), we need to store
33
+ // the bounds for testing.
34
+ const trickyBoundsPathBounds = {
35
+ height: 82.46210479736328,
36
+ width: 82.46211242675781,
37
+ x: 36.26179885864258,
38
+ y: 1.2760814428329468
39
+ };
40
+
41
+ const {window} = new JSDOM();
42
+ const parser = new window.DOMParser();
43
+ const fs = require('fs');
44
+ const OUTPUT_COMPARISON_FILES = false;
45
+ let comparisonFileString = '';
46
+
47
+ const comparisonFileAppend = function (svgString, svgElement, name) {
48
+ if (!OUTPUT_COMPARISON_FILES) return;
49
+ const newSvgString = new window.XMLSerializer().serializeToString(svgElement);
50
+ comparisonFileString +=
51
+ `<p>${name}</p>
52
+ <div style="width: 500px; border-style: solid; border-width: 1px;">
53
+ ${svgString}
54
+ </div>
55
+ <div style="width: 500px; border-style: solid; border-width: 0 1px 1px 1px;">
56
+ ${newSvgString}
57
+ </div>`;
58
+ };
59
+
60
+ const outputComparisonFile = function () {
61
+ if (!OUTPUT_COMPARISON_FILES) return;
62
+ fs.writeFile(
63
+ `${__dirname}/test-output/transform-applier-test.html`,
64
+ `<!-- THIS IS A GENERATED FILE -->\n<html><body>${comparisonFileString}\n</body></html>`,
65
+ err => log.error(err)
66
+ );
67
+ };
68
+
69
+ // No transform attribute on the path
70
+ test('noTransformPath', t => {
71
+ const svgString =
72
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100">` +
73
+ `<path id="path" fill="#0000" stroke="red" stroke-width="1" d="${d}"/>` +
74
+ `</svg>`;
75
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
76
+ transformStrokeWidths(svgElement, window);
77
+ comparisonFileAppend(svgString, svgElement, 'noTransformPath');
78
+
79
+ t.equals(d, svgElement.getElementById('path').attributes.d.value);
80
+ t.false(svgElement.getElementById('path').attributes.transform);
81
+ t.end();
82
+ });
83
+
84
+ // No stroke width attribute on the path. Stroke width is 1 by default in SVG, so transform should increase it to 2.
85
+ test('transformedNoStrokeWidthPath', t => {
86
+ const svgString =
87
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100">` +
88
+ `<path id="path" transform="scale(2)" fill="#0000" stroke="red" d="${d}"/>` +
89
+ `</svg>`;
90
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
91
+ transformStrokeWidths(svgElement, window);
92
+ comparisonFileAppend(svgString, svgElement, 'noStrokeWidthPath');
93
+
94
+ t.equals('2', svgElement.getElementById('path').attributes['stroke-width'].value);
95
+ t.end();
96
+ });
97
+
98
+ // Transform is identity matrix
99
+ test('identityTransformPath', t => {
100
+ const svgString =
101
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100">` +
102
+ `<path transform="matrix(1 0 0 1 0 0)" id="path" fill="#0000" stroke="red" stroke-width="1" d="${d}"/>` +
103
+ `</svg>`;
104
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
105
+ transformStrokeWidths(svgElement, window);
106
+ comparisonFileAppend(svgString, svgElement, 'identityTransformPath');
107
+
108
+ t.equals(d, svgElement.getElementById('path').attributes.d.value);
109
+ t.false(svgElement.getElementById('path').attributes.transform);
110
+ t.end();
111
+ });
112
+
113
+ // Transform on a simple box
114
+ test('transformBox', t => {
115
+ const svgString =
116
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="250px" height="250px" viewBox="0 0 250 250">` +
117
+ `<path transform="matrix(20 0 0 10 45 45)" id="path" fill="#0000" stroke="red" stroke-width="1" ` +
118
+ `d="M0,0 h 10 v 10 h -10 z"/>` +
119
+ `</svg>`;
120
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
121
+ transformStrokeWidths(svgElement, window);
122
+ comparisonFileAppend(svgString, svgElement, 'transformBox');
123
+
124
+ const transformed = `M 45 45 L 245 45 L 245 145 L 45 145 Z `;
125
+ t.equals(transformed, svgElement.getElementById('path').attributes.d.value);
126
+ // Transform is integrated into path, so the attribute should be gone
127
+ t.false(svgElement.getElementById('path').attributes.transform);
128
+ const quadraticMean = Math.sqrt(((20 * 20) + (10 * 10)) / 2);
129
+ t.equals(`${quadraticMean}`, svgElement.getElementById('path').attributes['stroke-width'].value);
130
+ t.end();
131
+ });
132
+
133
+ // Transform is not identity matrix
134
+ test('transformPath', t => {
135
+ const svgString =
136
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="250px" height="250px" viewBox="0 0 250 250">` +
137
+ `<path transform="matrix(2 0 0 2 45 45)" id="path" fill="#0000" stroke="red" stroke-width="1" d="${d}"/>` +
138
+ `</svg>`;
139
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
140
+ transformStrokeWidths(svgElement, window);
141
+ comparisonFileAppend(svgString, svgElement, 'transformPath');
142
+
143
+ const doubled = 'M 5 5 L 45 65 L 55 55 L 65 55 L 65 65 C 65 65 85 65 75 95 C 65 125 75 105 75 125 ' +
144
+ 'Q 85 145 105 165 Q 125 185 105 185 Q 85 185 85 205 M 45 45 A 80 100 0 1 1 45 245 Z ';
145
+ t.equals(doubled, svgElement.getElementById('path').attributes.d.value);
146
+ // Transform is integrated into path, so the attribute should be gone
147
+ t.false(svgElement.getElementById('path').attributes.transform);
148
+ t.equals('2', svgElement.getElementById('path').attributes['stroke-width'].value);
149
+ t.end();
150
+ });
151
+
152
+ // Transform has multiple matrices that compose to identity matrix
153
+ test('composedTransformPathIdentity', t => {
154
+ const svgString =
155
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100">` +
156
+ `<path transform="matrix(.5,0,0,.5,0,0) matrix(2,0,0,2,0,0)" id="path" ` +
157
+ `fill="#0000" stroke="red" stroke-width="1" d="${d}"/>` +
158
+ `</svg>`;
159
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
160
+ transformStrokeWidths(svgElement, window);
161
+ comparisonFileAppend(svgString, svgElement, 'composedTransformPathIdentity');
162
+
163
+ t.equals(d, svgElement.getElementById('path').attributes.d.value);
164
+ t.false(svgElement.getElementById('path').attributes.transform);
165
+ t.end();
166
+ });
167
+
168
+ // Transform has multiple matrices that don't compose to identity
169
+ test('composedTransformPath', t => {
170
+ const svgString =
171
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="230px" height="230px" viewBox="-30 -30 200 200">` +
172
+ `<path transform="matrix(.5,0,0,.5,0,0) matrix(3,0,0,3,1,2)" id="path" ` +
173
+ `fill="#0000" stroke="red" stroke-width="1" d="${d}"/>` +
174
+ `</svg>`;
175
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
176
+ transformStrokeWidths(svgElement, window);
177
+ comparisonFileAppend(svgString, svgElement, 'composedTransformPath');
178
+
179
+ const transformedPath = 'M -29.5 -29 L 0.5 16 L 8 8.5 L 15.5 8.5 L 15.5 16 C 15.5 16 30.5 16 23 38.5 ' +
180
+ 'C 15.5 61 23 46 23 61 Q 30.5 76 45.5 91 Q 60.5 106 45.5 106 Q 30.5 106 30.5 121 M 0.5 1 ' +
181
+ 'A 60 75 0 1 1 0.5 151 Z ';
182
+ t.equals(transformedPath, svgElement.getElementById('path').attributes.d.value);
183
+ t.end();
184
+ });
185
+
186
+ // Transform is on parent group
187
+ test('parentTransformPath', t => {
188
+ const svgString =
189
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="300px" height="300px" viewBox="-50 -50 250 250">` +
190
+ `<g id="group" transform="matrix(2, 0, 0, 2, 0, 0)">` +
191
+ `<path id="path" fill="#0000" stroke="red" stroke-width="1" d="${d}"/>` +
192
+ `</g>` +
193
+ `</svg>`;
194
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
195
+ transformStrokeWidths(svgElement, window);
196
+ comparisonFileAppend(svgString, svgElement, 'parentTransformPath');
197
+
198
+ const doubled = 'M -40 -40 L 0 20 L 10 10 L 20 10 L 20 20 C 20 20 40 20 30 50 C 20 80 30 60 30 80 ' +
199
+ 'Q 40 100 60 120 Q 80 140 60 140 Q 40 140 40 160 M 0 0 A 80 100 0 1 1 0 200 Z ';
200
+ t.equals(doubled, svgElement.getElementById('path').attributes.d.value);
201
+ // Transform should be gone from both child and parent
202
+ t.false(svgElement.getElementById('group').attributes.transform);
203
+ t.false(svgElement.getElementById('path').attributes.transform);
204
+ t.equals('2', svgElement.getElementById('path').attributes['stroke-width'].value);
205
+ t.end();
206
+ });
207
+
208
+ // Nested path
209
+ test('nestedNoTransformPath', t => {
210
+ const svgString =
211
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100">` +
212
+ `<g>` +
213
+ `<path id="path" fill="#0000" stroke="red" stroke-width="1" d="${d}"/>` +
214
+ `</g>` +
215
+ `</svg>`;
216
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
217
+ transformStrokeWidths(svgElement, window);
218
+ comparisonFileAppend(svgString, svgElement, 'nestedNoTransformPath');
219
+
220
+ t.equals(d, svgElement.getElementById('path').attributes.d.value);
221
+ t.end();
222
+ });
223
+
224
+ // Transforms on parents and children
225
+ test('nestedTransformPath', t => {
226
+ const svgString =
227
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="300px" height="300px" viewBox="-40 -40 260 260">` +
228
+ `<g transform=" matrix(1.5 0 0 1.5 0 0) ">` +
229
+ `<g>` +
230
+ `<path transform="matrix(1.5,0,0,1.5,0,0)" id="path" fill="#0000" stroke="red" stroke-width="1" ` +
231
+ `d="${d}"/>` +
232
+ `</g>` +
233
+ `</g>` +
234
+ `</svg>`;
235
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
236
+ transformStrokeWidths(svgElement, window);
237
+ comparisonFileAppend(svgString, svgElement, 'nestedTransformPath');
238
+
239
+ const quartered = 'M -45 -45 L 0 22.5 L 11.25 11.25 L 22.5 11.25 L 22.5 22.5 C 22.5 22.5 45 22.5 33.75 56.25 ' +
240
+ 'C 22.5 90 33.75 67.5 33.75 90 Q 45 112.5 67.5 135 Q 90 157.5 67.5 157.5 Q 45 157.5 45 180 M 0 0 ' +
241
+ 'A 90 112.5 0 1 1 0 225 Z ';
242
+ t.equals(quartered, svgElement.getElementById('path').attributes.d.value);
243
+ t.end();
244
+ });
245
+
246
+ // Transform combines all types of transforms
247
+ test('variousTransformsPath', t => {
248
+ const svgString =
249
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="500px" height="400px" viewBox="0 0 500 400">` +
250
+ `<path transform="rotate(25) matrix(2,0,0,2,0,0) skewX(10) translate(20) ` +
251
+ `rotate(25, 100, 100) skewY(-10) translate(-10, 4) scale(1.5,0.8) translate(40,80) " ` +
252
+ `id="path" fill="#0000" stroke="red" stroke-width="1" d="${d}"/>` +
253
+ `</svg>`;
254
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
255
+ transformStrokeWidths(svgElement, window);
256
+ comparisonFileAppend(svgString, svgElement, 'variousTransformsPath');
257
+
258
+ const transformedPath = 'M 115.3172 96.7866 L 134.6908 171.2195 L 151.9584 175.6212 L 164.2563 185.7055 ' +
259
+ 'L 159.2866 191.3881 C 159.2866 191.3881 183.8824 211.5567 156.6755 218.5202 ' +
260
+ 'C 129.4685 225.4837 151.7058 224.2028 141.7664 235.568 Q 144.1249 257.0175 158.7814 288.5514 ' +
261
+ 'Q 173.4379 320.0852 148.842 299.9166 Q 124.2462 279.7479 114.3068 291.1131 M 144.6301 159.8543 ' +
262
+ 'A 75.4328 127.2656 -51.6345 1 1 45.2364 273.5062 Z ';
263
+ t.equals(transformedPath, svgElement.getElementById('path').attributes.d.value);
264
+ t.false(svgElement.getElementById('path').attributes.transform);
265
+ t.end();
266
+ });
267
+
268
+ // Transform is pushed down to other children
269
+ test('siblingsTransformPath', t => {
270
+ const svgString =
271
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="160px" height="160px" viewBox="-20 -20 140 140">` +
272
+ `<g transform="matrix(0.5 0 0 0.5 0 0)">` +
273
+ `<g transform="translate(10, 20)">` +
274
+ `<path transform="matrix(2 0 0 2 0 0)" id="path" fill="#0000" stroke="red" stroke-width="1" ` +
275
+ `d="${d}"/>` +
276
+ `<rect id="sibling" x="40" y="40" width="40" height="40" fill="#0000" stroke="blue" />` +
277
+ `</g>` +
278
+ `<rect id="distantCousin1" transform="translate(-0.5,-.5)" ` +
279
+ `x="40" y="40" width="40" height="40" fill="#0000" stroke="blue" />` +
280
+ `<rect id="distantCousin2" x="40" y="40" width="40" height="40" fill="#0000" stroke="blue" />` +
281
+ `</g>` +
282
+ `</svg>`;
283
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
284
+ transformStrokeWidths(svgElement, window);
285
+ comparisonFileAppend(svgString, svgElement, 'siblingsTransformPath');
286
+
287
+ t.equals('matrix(0.5,0,0,0.5,5,10)', svgElement.getElementById('sibling').attributes.transform.value);
288
+ t.equals('matrix(0.5,0,0,0.5,-0.25,-0.25)', svgElement.getElementById('distantCousin1').attributes.transform.value);
289
+ t.equals('matrix(0.5,0,0,0.5,0,0)', svgElement.getElementById('distantCousin2').attributes.transform.value);
290
+ t.end();
291
+ });
292
+
293
+ // Stroke width is pushed down to leaf level
294
+ test('siblingsStroke', t => {
295
+ const svgString =
296
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="120px" height="120px" viewBox="-20 -20 100 100">` +
297
+ `<g stroke-width="5">` +
298
+ `<g stroke-width="10">` +
299
+ `<path transform="matrix(.5 0 0 .5 0 0)" fill="#0000" stroke="red" stroke-width="1" ` +
300
+ `d="${d}" id="path"/>` +
301
+ `<rect id="sibling" x="10" y="10" width="40" height="40" fill="#0000" stroke="blue" />` +
302
+ `</g>` +
303
+ `<rect id="distantCousin1" stroke-width="15" x="25" y="25" width="40" height="40" fill="#0000" ` +
304
+ `stroke="blue" />` +
305
+ `<rect id="distantCousin2" x="40" y="40" width="40" height="40" fill="#0000" stroke="blue" />` +
306
+ `</g>` +
307
+ `</svg>`;
308
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
309
+ transformStrokeWidths(svgElement, window);
310
+ comparisonFileAppend(svgString, svgElement, 'siblingsStroke');
311
+
312
+ t.equals('10', svgElement.getElementById('sibling').attributes['stroke-width'].value);
313
+ t.equals('15', svgElement.getElementById('distantCousin1').attributes['stroke-width'].value);
314
+ t.equals('5', svgElement.getElementById('distantCousin2').attributes['stroke-width'].value);
315
+ t.end();
316
+ });
317
+
318
+ // Nested stroke width is transformed
319
+ test('transformedNestedStroke', t => {
320
+ const svgString =
321
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="650px" height="170px" viewBox="-100 -20 550 150">` +
322
+ `<g stroke-width="1" transform="scale(-.5,.5)">` +
323
+ `<path transform="matrix(5 0 0 2 0 0)" fill="#0000" stroke="red" d="${d}" id="path"/>` +
324
+ `</g>` +
325
+ `</svg>`;
326
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
327
+ transformStrokeWidths(svgElement, window);
328
+ comparisonFileAppend(svgString, svgElement, 'transformedNestedStroke');
329
+
330
+ const quadraticMean = Math.sqrt(((5 / 2 * 5 / 2) + (2 / 2 * 2 / 2)) / 2);
331
+ t.equals(`${quadraticMean}`, svgElement.getElementById('path').attributes['stroke-width'].value);
332
+ t.end();
333
+ });
334
+
335
+ // Various transforms applied to a path with relative instructions
336
+ test('variousTransformsRelativePath', t => {
337
+ const pathData = 'm 20 20 0 20 10 0 l 5 5 h 10 v 10 c 0 10 0 20 15 5 z ' +
338
+ 'm -50 5 s 15 0 15 10 q 20 10 10 20 t 20 10 20 10 a 30 10 30 1 1 0 1 ';
339
+ const svgString =
340
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="200px" height="150px" viewBox="0 0 200 150">` +
341
+ `<path transform="skewX(10) rotate(-25) translate(5 20)" ` +
342
+ `id="path" fill="#0000" stroke="red" stroke-width="5" d="${pathData}" />` +
343
+ `</svg>`;
344
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
345
+ transformStrokeWidths(svgElement, window);
346
+ comparisonFileAppend(svgString, svgElement, 'variousTransformsRelativePath');
347
+
348
+ const transformed = 'M 44.0917 25.6869 L 55.7402 43.813 L 64.0581 39.5868 L 71.1292 42.0053 L 79.447 37.7791 ' +
349
+ 'L 85.2713 46.8422 C 91.0955 55.9052 96.9198 64.9683 100.6603 45.0344 Z M 5.4144 51.3493 ' +
350
+ 'C 5.4144 51.3493 17.8912 45.01 23.7155 54.0731 Q 46.1755 54.6838 43.6819 67.9731 ' +
351
+ 'Q 41.1882 81.2623 66.1419 68.5838 Q 91.0955 55.9052 88.6019 69.1945 ' +
352
+ 'A 9.8314 30.5145 -83.9007 1 1 89.1843 70.1008 ';
353
+ t.equals(transformed, svgElement.getElementById('path').attributes.d.value);
354
+ t.end();
355
+ });
356
+
357
+ // Testing scale transform, elliptical paths
358
+ test('scaleTransformEllipticalPath', t => {
359
+ const svgString =
360
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="600px" height="250px" viewBox="0 0 600 250"> ` +
361
+ `<path transform="scale(.5)" ` +
362
+ `id="path" fill="#0000" stroke="red" stroke-width="5" d="${ellipticalPath}"/>` +
363
+ `</svg>`;
364
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
365
+ transformStrokeWidths(svgElement, window);
366
+ comparisonFileAppend(svgString, svgElement, 'scaleTransformEllipticalPath');
367
+
368
+ const scaled = 'M 5 150 L 30 137.5 A 12.5 12.5 -50.7685 0 1 55 125 L 80 112.5 A 12.5 25 -45 0 1 105 100 ' +
369
+ 'L 130 87.5 A 12.5 37.5 -30 0 1 155 75 L 180 62.5 A 12.5 50 -15 0 1 205 50 L 230 37.5 L 230 62.5 L 205 75 ' +
370
+ 'A 12.5 12.5 -50.7685 1 1 180 87.5 L 155 100 A 12.5 25 45 1 1 130 112.5 L 105 125 A 12.5 37.5 30 1 1 80 137.5 ' +
371
+ 'L 55 150 A 12.5 50 15 1 1 30 162.5 L 5 175 ';
372
+ t.equals(scaled, svgElement.getElementById('path').attributes.d.value);
373
+ t.end();
374
+ });
375
+
376
+ // Testing invert transform, elliptical paths
377
+ test('invertTransformEllipticalPath', t => {
378
+ const svgString =
379
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="600px" height="500px" viewBox="0 0 600 500"> ` +
380
+ `<path transform="matrix(0 1 1 0 0 0)" ` +
381
+ `id="path" fill="#0000" stroke="red" stroke-width="5" d="${ellipticalPath}"/>` +
382
+ `</svg>`;
383
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
384
+ transformStrokeWidths(svgElement, window);
385
+ comparisonFileAppend(svgString, svgElement, 'invertTransformEllipticalPath');
386
+
387
+ const inverted = 'M 300 10 L 275 60 A 25 25 -50.7685 0 0 250 110 L 225 160 A 25 50 -45 0 0 200 210 ' +
388
+ 'L 175 260 A 25 75 -60 0 0 150 310 L 125 360 A 25 100 -75 0 0 100 410 L 75 460 L 125 460 L 150 410 ' +
389
+ 'A 25 25 -50.7685 1 0 175 360 L 200 310 A 25 50 45 1 0 225 260 L 250 210 A 25 75 60 1 0 275 160 L 300 110 ' +
390
+ 'A 25 100 75 1 0 325 60 L 350 10 ';
391
+ t.equals(inverted, svgElement.getElementById('path').attributes.d.value);
392
+ t.end();
393
+ });
394
+
395
+ // Testing rotate transform, elliptical paths
396
+ test('rotateTransformEllipticalPath', t => {
397
+ const svgString =
398
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="600px" height="600px" viewBox="0 0 600 600"> ` +
399
+ `<path transform="rotate(-255) translate(0,-500)" ` +
400
+ `id="path" fill="#0000" stroke="red" stroke-width="5" d="${ellipticalPath}"/>` +
401
+ `</svg>`;
402
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
403
+ transformStrokeWidths(svgElement, window);
404
+ comparisonFileAppend(svgString, svgElement, 'rotateTransformEllipticalPath');
405
+
406
+ const rotated = 'M 190.597 61.4231 L 201.8042 116.1898 A 25 25 -50.7685 0 1 213.0114 170.9566 ' +
407
+ 'L 224.2186 225.7234 A 25 50 60 0 1 235.4257 280.4901 L 246.6329 335.2569 A 25 75 75 0 1 257.8401 390.0237 ' +
408
+ 'L 269.0473 444.7904 A 25 100 90 0 1 280.2545 499.5572 L 291.4617 554.324 L 243.1654 541.383 ' +
409
+ 'L 231.9582 486.6163 A 25 25 -50.7685 1 1 220.751 431.8495 L 209.5438 377.0827 ' +
410
+ 'A 25 50 -30 1 1 198.3367 322.316 L 187.1295 267.5492 A 25 75 -45 1 1 175.9223 212.7824 L 164.7151 158.0156 ' +
411
+ 'A 25 100 -60 1 1 153.5079 103.2489 L 142.3007 48.4821 ';
412
+ t.equals(rotated, svgElement.getElementById('path').attributes.d.value);
413
+ t.end();
414
+ });
415
+
416
+ // Testing skewX transform, elliptical paths
417
+ test('skewXTransformEllipticalPath', t => {
418
+ const svgString =
419
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="600px" height="350px" viewBox="0 0 600 350"> ` +
420
+ `<path transform="skewX(-20)" ` +
421
+ `id="path" fill="#0000" stroke="red" stroke-width="5" d="${ellipticalPath}"/>` +
422
+ `</svg>`;
423
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
424
+ transformStrokeWidths(svgElement, window);
425
+ comparisonFileAppend(svgString, svgElement, 'skewXTransformEllipticalPath');
426
+
427
+ const skewed = 'M -99.1911 300 L -40.0918 275 A 20.861 29.9602 50.1571 0 1 19.0074 250 L 78.1067 225 ' +
428
+ 'A 29.7657 41.9946 -28.5971 0 1 137.206 200 L 196.3052 175 A 28.0557 66.8312 -9.069 0 1 255.4045 150 ' +
429
+ 'L 314.5037 125 A 25.6458 97.482 6.9831 0 1 373.603 100 L 432.7022 75 L 414.5037 125 L 355.4045 150 ' +
430
+ 'A 20.861 29.9602 50.1571 1 1 296.3052 175 L 237.206 200 A 20.8982 59.8139 53.2248 1 1 178.1067 225 ' +
431
+ 'L 119.0074 250 A 21.0102 89.2423 43.6881 1 1 59.9082 275 L 0.8089 300 ' +
432
+ 'A 21.8464 114.4351 32.9028 1 1 -58.2903 325 L -117.3896 350 ';
433
+ t.equals(skewed, svgElement.getElementById('path').attributes.d.value);
434
+ t.end();
435
+ });
436
+
437
+ // Testing skewY transform, elliptical paths
438
+ test('skewYTransformEllipticalPath', t => {
439
+ const svgString =
440
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="600px" height="400px" viewBox="0 0 600 400"> ` +
441
+ `<path transform="skewY(-20)" ` +
442
+ `id="path" fill="#0000" stroke="red" stroke-width="5" d="${ellipticalPath}"/>` +
443
+ `</svg>`;
444
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
445
+ transformStrokeWidths(svgElement, window);
446
+ comparisonFileAppend(svgString, svgElement, 'skewYTransformEllipticalPath');
447
+
448
+ const skewed = 'M 10 296.3603 L 60 253.1618 A 20.861 29.9602 39.8429 0 1 110 209.9633 L 160 166.7648 ' +
449
+ 'A 29.7657 41.9946 -61.4029 0 1 210 123.5663 L 260 80.3677 A 29.4429 63.6825 -34.2139 0 1 310 37.1692 ' +
450
+ 'L 360 -6.0293 A 27.3833 91.2964 -14.925 0 1 410 -49.2278 L 460 -92.4263 L 460 -42.4263 L 410 0.7722 ' +
451
+ 'A 20.861 29.9602 39.8429 1 1 360 43.9707 L 310 87.1692 A 20.8982 59.8139 36.7752 1 1 260 130.3677 ' +
452
+ 'L 210 173.5663 A 21.4899 87.2503 26.3947 1 1 160 216.7648 L 110 259.9633 ' +
453
+ 'A 22.8454 109.4312 14.6345 1 1 60 303.1618 L 10 346.3603 ';
454
+ t.equals(skewed, svgElement.getElementById('path').attributes.d.value);
455
+ t.end();
456
+ });
457
+
458
+ // Testing various transforms, elliptical paths
459
+ test('variousTransformsEllipticalPath', t => {
460
+ const svgString =
461
+ `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="600px" height="600px" viewBox="0 -200 600 300"> ` +
462
+ `<path transform="skewX(10) rotate(-25) translate(-50 -200)" ` +
463
+ `id="path" fill="#0000" stroke="red" stroke-width="5" d="${ellipticalPath}"/>` +
464
+ `</svg>`;
465
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
466
+ transformStrokeWidths(svgElement, window);
467
+ comparisonFileAppend(svgString, svgElement, 'variousTransformsEllipticalPath');
468
+
469
+ const transformed = 'M 24.9709 107.5355 L 51.9997 63.7469 A 22.8929 27.3011 -47.5192 0 1 79.0286 19.9583 ' +
470
+ 'L 106.0574 -23.8303 A 23.5927 52.9826 -69.05 0 1 133.0862 -67.6189 L 160.115 -111.4075 ' +
471
+ 'A 23.0486 81.3499 -57.6917 0 1 187.1438 -155.1961 L 214.1727 -198.9847 ' +
472
+ 'A 22.8991 109.1745 -45.4789 0 1 241.2015 -242.7734 L 268.2303 -286.562 L 297.3515 -241.2466 ' +
473
+ 'L 270.3227 -197.458 A 22.8929 27.3011 -47.5192 1 1 243.2939 -153.6694 L 216.2651 -109.8807 ' +
474
+ 'A 26.0319 48.0181 7.1283 1 1 189.2363 -66.0921 L 162.2074 -22.3035 ' +
475
+ 'A 24.9487 75.1544 -6.3334 1 1 135.1786 21.4851 L 108.1498 65.2737 ' +
476
+ 'A 23.9235 104.4996 -19.9344 1 1 81.121 109.0623 L 54.0922 152.8509 ';
477
+ t.equals(transformed, svgElement.getElementById('path').attributes.d.value);
478
+ t.end();
479
+ });
480
+
481
+ test('linearGradientTransformSquareSkewY', t => {
482
+ const svgString =
483
+ `<svg version="1.1" width="200" height="200" viewBox="-100 0 100 200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">` +
484
+ `<defs>` +
485
+ `<linearGradient id="grad_a" x2="0" y2="1">` +
486
+ `<stop offset="0" stop-color="green" stop-opacity="1"/>` +
487
+ `<stop offset="1" stop-color="red" stop-opacity="1"/>` +
488
+ `</linearGradient>` +
489
+ `</defs>` +
490
+ `<path id="path" fill="url(#grad_a)" stroke="#000000" stroke-width="2" d="M0,0 0,100 100,100 100,0 z" ` +
491
+ `transform="translate(-50, 50) scale(-.75, 1) skewY(-15)"/>` +
492
+ `</svg>`;
493
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
494
+ transformStrokeWidths(svgElement, window, {width: 100, height: 100, x: 0, y: 0});
495
+ comparisonFileAppend(svgString, svgElement, 'linearGradientTransformSquareSkewY');
496
+ t.equals('-50', svgElement.getElementById('grad_a-0.75,-0.2679491924311227,0,1,-50,50').attributes.x1.value);
497
+ t.equals('-81.6826', svgElement.getElementById('grad_a-0.75,-0.2679491924311227,0,1,-50,50').attributes.x2.value);
498
+ t.equals('50', svgElement.getElementById('grad_a-0.75,-0.2679491924311227,0,1,-50,50').attributes.y1.value);
499
+ t.equals('138.6809', svgElement.getElementById('grad_a-0.75,-0.2679491924311227,0,1,-50,50').attributes.y2.value);
500
+
501
+ t.end();
502
+ });
503
+
504
+ test('linearGradientTransformSquareSkewX', t => {
505
+ const svgString =
506
+ `<svg version="1.1" width="200" height="200" viewBox="-100 0 100 200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">` +
507
+ `<defs>` +
508
+ `<linearGradient id="grad_b" x2="0" y2="1">` +
509
+ `<stop offset="0" stop-color="green" stop-opacity="1"/>` +
510
+ `<stop offset="1" stop-color="red" stop-opacity="1"/>` +
511
+ `</linearGradient>` +
512
+ `</defs>` +
513
+ `<path id="path" fill="url(#grad_b)" stroke="#000000" stroke-width="2" d="M0,0 0,100 100,100 100,0 z" ` +
514
+ `transform="translate(-50, 50) scale(-.75, 1) skewX(-15)"/>` +
515
+ `</svg>`;
516
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
517
+ transformStrokeWidths(svgElement, window, {width: 100, height: 100, x: 0, y: 0});
518
+ comparisonFileAppend(svgString, svgElement, 'linearGradientTransformSquareSkewX');
519
+ t.equals('-50', svgElement.getElementById('grad_b-0.75,0,0.20096189432334202,1,-50,50').attributes.x1.value);
520
+ t.equals('-50', svgElement.getElementById('grad_b-0.75,0,0.20096189432334202,1,-50,50').attributes.x2.value);
521
+ t.equals('50', svgElement.getElementById('grad_b-0.75,0,0.20096189432334202,1,-50,50').attributes.y1.value);
522
+ t.equals('150', svgElement.getElementById('grad_b-0.75,0,0.20096189432334202,1,-50,50').attributes.y2.value);
523
+
524
+ t.end();
525
+ });
526
+
527
+ test('linearGradientTransform', t => {
528
+ const svgString =
529
+ `<svg version="1.1" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">` +
530
+ `<defs>` +
531
+ `<linearGradient id="grad_c">` +
532
+ `<stop offset="0" stop-color="green" stop-opacity="1"/>` +
533
+ `<stop offset="1" stop-color="red" stop-opacity="1"/>` +
534
+ `</linearGradient>` +
535
+ `</defs>` +
536
+ `<path id="path" fill="url(#grad_c)" stroke="#000000" stroke-width="2" d="${trickyBoundsPath}" ` +
537
+ `transform="scale(.75) skewX(-15)"/>` +
538
+ `</svg>`;
539
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
540
+ transformStrokeWidths(svgElement, window, trickyBoundsPathBounds);
541
+ comparisonFileAppend(svgString, svgElement, 'linearGradientTransform');
542
+ t.equals('26.9399', svgElement.getElementById('grad_c-.75,0,-0.20096189432334202,0.75,0,0').attributes.x1.value);
543
+ t.equals('84.6436', svgElement.getElementById('grad_c-.75,0,-0.20096189432334202,0.75,0,0').attributes.x2.value);
544
+ t.equals('0.9571', svgElement.getElementById('grad_c-.75,0,-0.20096189432334202,0.75,0,0').attributes.y1.value);
545
+ t.equals('16.4187', svgElement.getElementById('grad_c-.75,0,-0.20096189432334202,0.75,0,0').attributes.y2.value);
546
+
547
+ t.end();
548
+ });
549
+
550
+ test('reusedLinearGradientTransform', t => {
551
+ const svgString =
552
+ `<svg version="1.1" width="200" height="150" viewBox="0 0 200 150" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">` +
553
+ `<defs>` +
554
+ `<linearGradient id="grad_1">` +
555
+ `<stop offset="0" stop-color="green" stop-opacity="1"/>` +
556
+ `<stop offset="1" stop-color="red" stop-opacity="1"/>` +
557
+ `</linearGradient>` +
558
+ `</defs>` +
559
+ `<path id="path" fill="url(#grad_1)" stroke="#000000" stroke-width="2" d="${trickyBoundsPath}" ` +
560
+ `transform="scale(.75) skewX(-15)"/>` +
561
+ `<path id="path2" fill="url(#grad_1)" stroke="#000000" stroke-width="2" d="${trickyBoundsPath}" ` +
562
+ `transform="translate(150, 150) rotate(180)"/>` +
563
+ `<path id="path3" fill="url(#grad_1)" stroke="#000000" stroke-width="2" d="${trickyBoundsPath}" ` +
564
+ `transform="translate(150, 150) rotate(180)"/>` +
565
+ `</svg>`;
566
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
567
+ transformStrokeWidths(svgElement, window, trickyBoundsPathBounds);
568
+ comparisonFileAppend(svgString, svgElement, 'reusedLinearGradientTransform');
569
+ t.equals('26.9399', svgElement.getElementById('grad_1-.75,0,-0.20096189432334202,0.75,0,0').attributes.x1.value);
570
+ t.equals('84.6436', svgElement.getElementById('grad_1-.75,0,-0.20096189432334202,0.75,0,0').attributes.x2.value);
571
+ t.equals('0.9571', svgElement.getElementById('grad_1-.75,0,-0.20096189432334202,0.75,0,0').attributes.y1.value);
572
+ t.equals('16.4187', svgElement.getElementById('grad_1-.75,0,-0.20096189432334202,0.75,0,0').attributes.y2.value);
573
+ t.equals('113.7382', svgElement.getElementById('grad_1-1,1.2246467991473532e-16,-1.2246467991473532e-16,-1,150,150')
574
+ .attributes.x1.value);
575
+ t.equals('31.2761', svgElement.getElementById('grad_1-1,1.2246467991473532e-16,-1.2246467991473532e-16,-1,150,150')
576
+ .attributes.x2.value);
577
+ t.equals('148.7239', svgElement.getElementById('grad_1-1,1.2246467991473532e-16,-1.2246467991473532e-16,-1,150,150')
578
+ .attributes.y1.value);
579
+ t.equals('148.7239', svgElement.getElementById('grad_1-1,1.2246467991473532e-16,-1.2246467991473532e-16,-1,150,150')
580
+ .attributes.y2.value);
581
+
582
+ t.end();
583
+ });
584
+
585
+ test('nestedLinearGradientTransform', t => {
586
+ const svgString =
587
+ `<svg version="1.1" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
588
+ <defs>
589
+ <linearGradient id="grad_2" x2="0" y2="1">
590
+ <stop offset="0" stop-color="#7F00FF" stop-opacity="1"/>
591
+ <stop offset="1" stop-color="#FF9400" stop-opacity="1"/>
592
+ </linearGradient>
593
+ </defs>
594
+ <g transform="scale(.75) skewX(-15)">
595
+ <path id="path" fill="url(#grad_2)" stroke="#003FFF" stroke-width="5" d="${trickyBoundsPath}" />
596
+ </g>
597
+ </svg>`;
598
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
599
+ transformStrokeWidths(svgElement, window, trickyBoundsPathBounds);
600
+ comparisonFileAppend(svgString, svgElement, 'nestedLinearGradientTransform');
601
+ t.equals('26.9399', svgElement.getElementById('grad_2-.75,0,-0.20096189432334202,0.75,0,0').attributes.x1.value);
602
+ t.equals('26.9399', svgElement.getElementById('grad_2-.75,0,-0.20096189432334202,0.75,0,0').attributes.x2.value);
603
+ t.equals('0.9571', svgElement.getElementById('grad_2-.75,0,-0.20096189432334202,0.75,0,0').attributes.y1.value);
604
+ t.equals('62.8036', svgElement.getElementById('grad_2-.75,0,-0.20096189432334202,0.75,0,0').attributes.y2.value);
605
+
606
+ t.end();
607
+ });
608
+
609
+ test('percentLinearGradientTransform', t => {
610
+ const svgString =
611
+ `<svg version="1.1" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
612
+ <defs>
613
+ <linearGradient id="grad_3" x2="50%" y2="50%">
614
+ <stop offset="0" stop-color="#7F00FF" stop-opacity="1"/>
615
+ <stop offset="1" stop-color="#FF9400" stop-opacity="1"/>
616
+ </linearGradient>
617
+ </defs>
618
+ <path id="path" fill="url(#grad_3)" stroke="#003FFF" stroke-width="5" d="${trickyBoundsPath}"
619
+ transform="scale(.75) skewX(-15)" />
620
+ </svg>`;
621
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
622
+ transformStrokeWidths(svgElement, window, trickyBoundsPathBounds);
623
+ comparisonFileAppend(svgString, svgElement, 'percentLinearGradientTransform');
624
+ t.equals('26.9399', svgElement.getElementById('grad_3-.75,0,-0.20096189432334202,0.75,0,0').attributes.x1.value);
625
+ t.equals('50.6569', svgElement.getElementById('grad_3-.75,0,-0.20096189432334202,0.75,0,0').attributes.x2.value);
626
+ t.equals('0.9571', svgElement.getElementById('grad_3-.75,0,-0.20096189432334202,0.75,0,0').attributes.y1.value);
627
+ t.equals('31.029', svgElement.getElementById('grad_3-.75,0,-0.20096189432334202,0.75,0,0').attributes.y2.value);
628
+
629
+ t.end();
630
+ });
631
+
632
+ test('userSpaceLinearGradientTransform', t => {
633
+ const svgString =
634
+ `<svg version="1.1" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
635
+ <defs>
636
+ <linearGradient id="grad_4" x1="20" x2="80" y1="20" y2="80" gradientUnits="userSpaceOnUse">
637
+ <stop offset="0" stop-color="#7F00FF" stop-opacity="1"/>
638
+ <stop offset="1" stop-color="#FF9400" stop-opacity="1"/>
639
+ </linearGradient>
640
+ </defs>
641
+ <path id="path" fill="url(#grad_4)" stroke="#003FFF" stroke-width="5" d="${trickyBoundsPath}"
642
+ transform="scale(.75) skewX(-15)" />
643
+ </svg>`;
644
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
645
+ transformStrokeWidths(svgElement, window, trickyBoundsPathBounds);
646
+ comparisonFileAppend(svgString, svgElement, 'userSpaceLinearGradientTransform');
647
+ t.equals('10.9808', svgElement.getElementById('grad_4-.75,0,-0.20096189432334202,0.75,0,0').attributes.x1.value);
648
+ t.equals('45.494', svgElement.getElementById('grad_4-.75,0,-0.20096189432334202,0.75,0,0').attributes.x2.value);
649
+ t.equals('15', svgElement.getElementById('grad_4-.75,0,-0.20096189432334202,0.75,0,0').attributes.y1.value);
650
+ t.equals('58.761', svgElement.getElementById('grad_4-.75,0,-0.20096189432334202,0.75,0,0').attributes.y2.value);
651
+
652
+ t.end();
653
+ });
654
+
655
+ test('degenerateLinearGradientTransform', t => {
656
+ const svgString =
657
+ `<svg version="1.1" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">` +
658
+ `<defs>` +
659
+ `<linearGradient id="grad_d" x1="50%" x2="50%" y1="50%" y2="50%">` +
660
+ `<stop offset="0" stop-color="green" stop-opacity="1"/>` +
661
+ `<stop offset="1" stop-color="red" stop-opacity="1"/>` +
662
+ `</linearGradient>` +
663
+ `</defs>` +
664
+ `<path id="path" fill="url(#grad_d)" stroke="#000000" stroke-width="2" d="${trickyBoundsPath}" ` +
665
+ `transform="scale(.75) skewX(-15)"/>` +
666
+ `</svg>`;
667
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
668
+ transformStrokeWidths(svgElement, window, trickyBoundsPathBounds);
669
+ comparisonFileAppend(svgString, svgElement, 'linearGradientTransform');
670
+
671
+ t.end();
672
+ });
673
+
674
+ test('nestedRadialGradientTransform', t => {
675
+ const svgString =
676
+ `<svg version="1.1" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
677
+ <defs>
678
+ <radialGradient id="grad_5">
679
+ <stop offset="0" stop-color="#7F00FF" stop-opacity="1"/>
680
+ <stop offset="1" stop-color="#FF9400" stop-opacity="1"/>
681
+ </radialGradient>
682
+ </defs>
683
+ <g transform="scale(.75) skewX(-15)">
684
+ <path id="path" fill="url(#grad_5)" stroke="#003FFF" stroke-width="5" d="${trickyBoundsPath}" />
685
+ </g>
686
+ </svg>`;
687
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
688
+ transformStrokeWidths(svgElement, window, trickyBoundsPathBounds);
689
+ comparisonFileAppend(svgString, svgElement,
690
+ 'nestedRadialGradientTransform. Note that radial gradients are not expected to match exactly.');
691
+ t.equals('49.5773', svgElement.getElementById('grad_5-.75,0,-0.20096189432334202,0.75,0,0').attributes.cx.value);
692
+ t.equals('31.8804', svgElement.getElementById('grad_5-.75,0,-0.20096189432334202,0.75,0,0').attributes.cy.value);
693
+ t.equals('30.9233', svgElement.getElementById('grad_5-.75,0,-0.20096189432334202,0.75,0,0').attributes.r.value);
694
+
695
+ t.end();
696
+ });
697
+
698
+ test('focalRadialGradientTransform', t => {
699
+ const svgString =
700
+ `<svg version="1.1" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
701
+ <defs>
702
+ <radialGradient id="grad_6" fx=".75" fy=".75">
703
+ <stop offset="0" stop-color="#7F00FF" stop-opacity="1"/>
704
+ <stop offset="1" stop-color="#FF9400" stop-opacity="1"/>
705
+ </radialGradient>
706
+ </defs>
707
+ <g transform="scale(.75) skewX(-15)">
708
+ <path id="path" fill="url(#grad_6)" stroke="#003FFF" stroke-width="5" d="${trickyBoundsPath}" />
709
+ </g>
710
+ </svg>`;
711
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
712
+ transformStrokeWidths(svgElement, window, trickyBoundsPathBounds);
713
+ comparisonFileAppend(svgString, svgElement, 'focalRadialGradientTransform');
714
+ t.equals('49.5773', svgElement.getElementById('grad_6-.75,0,-0.20096189432334202,0.75,0,0').attributes.cx.value);
715
+ t.equals('31.8804', svgElement.getElementById('grad_6-.75,0,-0.20096189432334202,0.75,0,0').attributes.cy.value);
716
+ t.equals('30.9233', svgElement.getElementById('grad_6-.75,0,-0.20096189432334202,0.75,0,0').attributes.r.value);
717
+ t.equals('60.896', svgElement.getElementById('grad_6-.75,0,-0.20096189432334202,0.75,0,0').attributes.fx.value);
718
+ t.equals('47.342', svgElement.getElementById('grad_6-.75,0,-0.20096189432334202,0.75,0,0').attributes.fy.value);
719
+
720
+ t.end();
721
+ });
722
+
723
+ test('percentRadialGradientTransform', t => {
724
+ const svgString =
725
+ `<svg version="1.1" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
726
+ <defs>
727
+ <radialGradient id="grad_7" cx="60%" cy="80%" fx="75%" fy="85%">
728
+ <stop offset="0" stop-color="#7F00FF" stop-opacity="1"/>
729
+ <stop offset="1" stop-color="#FF9400" stop-opacity="1"/>
730
+ </radialGradient>
731
+ </defs>
732
+ <g transform="scale(.75) skewX(-15)">
733
+ <path id="path" fill="url(#grad_7)" stroke="#003FFF" stroke-width="5" d="${trickyBoundsPath}" />
734
+ </g>
735
+ </svg>`;
736
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
737
+ transformStrokeWidths(svgElement, window, trickyBoundsPathBounds);
738
+ comparisonFileAppend(svgString, svgElement, 'percentRadialGradientTransform');
739
+ t.equals('50.7905', svgElement.getElementById('grad_7-.75,0,-0.20096189432334202,0.75,0,0').attributes.cx.value);
740
+ t.equals('50.4343', svgElement.getElementById('grad_7-.75,0,-0.20096189432334202,0.75,0,0').attributes.cy.value);
741
+ t.equals('30.9233', svgElement.getElementById('grad_7-.75,0,-0.20096189432334202,0.75,0,0').attributes.r.value);
742
+ t.equals('59.2389', svgElement.getElementById('grad_7-.75,0,-0.20096189432334202,0.75,0,0').attributes.fx.value);
743
+ t.equals('53.5267', svgElement.getElementById('grad_7-.75,0,-0.20096189432334202,0.75,0,0').attributes.fy.value);
744
+
745
+ t.end();
746
+ });
747
+
748
+ test('userSpaceRadialGradientTransform', t => {
749
+ const svgString =
750
+ `<svg version="1.1" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
751
+ <defs>
752
+ <radialGradient id="grad_8" cx="80" r="10" cy="60" gradientUnits="userSpaceOnUse">
753
+ <stop offset="0" stop-color="#7F00FF" stop-opacity="1"/>
754
+ <stop offset="1" stop-color="#FF9400" stop-opacity="1"/>
755
+ </radialGradient>
756
+ </defs>
757
+ <path id="path" fill="url(#grad_8)" stroke="#003FFF" stroke-width="5" d="${trickyBoundsPath}"
758
+ transform="scale(.75) skewX(-15)" />
759
+ </svg>`;
760
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
761
+ transformStrokeWidths(svgElement, window, trickyBoundsPathBounds);
762
+ comparisonFileAppend(svgString, svgElement, 'userSpaceRadialGradientTransform');
763
+ t.equals('47.9423', svgElement.getElementById('grad_8-.75,0,-0.20096189432334202,0.75,0,0').attributes.cx.value);
764
+ t.equals('45', svgElement.getElementById('grad_8-.75,0,-0.20096189432334202,0.75,0,0').attributes.cy.value);
765
+ t.equals('7.5', svgElement.getElementById('grad_8-.75,0,-0.20096189432334202,0.75,0,0').attributes.r.value);
766
+
767
+ t.end();
768
+ });
769
+
770
+ test('blackFillsBugFix', t => {
771
+ const svgString =
772
+ `<svg width="26px" height="14px" viewBox="0 0 26 14" version="1.1" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
773
+ <g>
774
+ <g id="Page-1" stroke="none" stroke-width="5" fill="none" fill-rule="evenodd">
775
+ <path d="M23.87,0.75 C20.19,0.75 16.38,4.75 16.38,4.75 L16.38,9.25 C16.38,9.25 20.19,13.25 23.87,13.25
776
+ C24.6811343,11.269062 25.0661499,9.139551 25,7 C25.0661499,4.860449 24.6811343,2.73093802 23.87,0.75 Z"
777
+ id="Shape" stroke="#149948"/>
778
+ </g>
779
+ </g>
780
+ </svg>`;
781
+ const svgElement = parser.parseFromString(svgString, 'text/xml').documentElement;
782
+ transformStrokeWidths(svgElement, window,
783
+ {
784
+ height: 12.5,
785
+ width: 24.020904541015625,
786
+ x: 0.9896308183670044,
787
+ y: 0.75
788
+ });
789
+ comparisonFileAppend(svgString, svgElement, 'blackFillsBugFix');
790
+ t.equals('none', svgElement.getElementById('Shape').attributes.fill.value);
791
+ t.equals('5', svgElement.getElementById('Shape').attributes['stroke-width'].value);
792
+
793
+ t.end();
794
+ });
795
+
796
+ outputComparisonFile();