@@ -10,6 +10,24 @@ import 'package:vector_graphics_compiler/vector_graphics_compiler.dart';
1010
1111import 'test_svg_strings.dart' ;
1212
13+ class _TestOpacityColorMapper implements ColorMapper {
14+ const _TestOpacityColorMapper ();
15+
16+ @override
17+ Color substitute (
18+ String ? id,
19+ String elementName,
20+ String attributeName,
21+ Color color,
22+ ) {
23+ if (color.value == 0xff000000 ) {
24+ return const Color (0x7fff0000 );
25+ } else {
26+ return color;
27+ }
28+ }
29+ }
30+
1331void main () {
1432 test ('Reuse ID self-referentially' , () {
1533 final VectorInstructions instructions = parseWithoutOptimizers ('''
@@ -266,6 +284,24 @@ void main() {
266284 );
267285 });
268286
287+ test ('preserve opacity from color mapper for strokes' , () {
288+ const String strokeOpacitySvg = '''
289+ <svg viewBox="0 0 10 10" fill="none">
290+ <rect x="0" y="0" width="5" height="5" stroke="#000000" />
291+ </svg>
292+ ''' ;
293+
294+ final VectorInstructions instructions = parseWithoutOptimizers (
295+ strokeOpacitySvg,
296+ colorMapper: const _TestOpacityColorMapper (),
297+ );
298+
299+ expect (
300+ instructions.paints.single,
301+ const Paint (stroke: Stroke (color: Color (0x7fff0000 ))),
302+ );
303+ });
304+
269305 test ('text attributes are preserved' , () {
270306 final VectorInstructions instructions = parseWithoutOptimizers (textTspan);
271307 expect (
@@ -352,6 +388,39 @@ void main() {
352388 );
353389 });
354390
391+ test ('currentColor stoke opacity' , () {
392+ const String currentColorSvg = '''
393+ <svg viewBox="0 0 10 10">
394+ <rect x="0" y="0" width="5" height="5" fill="currentColor" stroke="currentColor" />
395+ </svg>
396+ ''' ;
397+
398+ final VectorInstructions blueInstructions = parseWithoutOptimizers (
399+ currentColorSvg,
400+ theme: const SvgTheme (currentColor: Color (0x7F0000FF )),
401+ );
402+ final VectorInstructions redInstructions = parseWithoutOptimizers (
403+ currentColorSvg,
404+ theme: const SvgTheme (currentColor: Color (0x7FFF0000 )),
405+ );
406+
407+ expect (
408+ blueInstructions.paints.single,
409+ const Paint (
410+ fill: Fill (color: Color (0x7F0000FF )),
411+ stroke: Stroke (color: Color (0x7F0000FF )),
412+ ),
413+ );
414+
415+ expect (
416+ redInstructions.paints.single,
417+ const Paint (
418+ fill: Fill (color: Color (0x7FFF0000 )),
419+ stroke: Stroke (color: Color (0x7FFF0000 )),
420+ ),
421+ );
422+ });
423+
355424 test ('Opacity with a save layer does not continue to inherit' , () {
356425 final VectorInstructions instructions = parseWithoutOptimizers ('''
357426<svg width="283" height="180" viewBox="0 0 283 180" fill="none" xmlns="http://www.w3.org/2000/svg">
0 commit comments