diff --git a/packages/vector_graphics_compiler/CHANGELOG.md b/packages/vector_graphics_compiler/CHANGELOG.md index ba4804c871c9..e132bbc01f73 100644 --- a/packages/vector_graphics_compiler/CHANGELOG.md +++ b/packages/vector_graphics_compiler/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.16 + +* Sets stroke-width to 1 by default when an invalid value is parsed instead of throwing an exception. + ## 1.1.15 * Fixes a bug where empty tags caused the parser to crash. diff --git a/packages/vector_graphics_compiler/lib/src/svg/parser.dart b/packages/vector_graphics_compiler/lib/src/svg/parser.dart index 6e846cf00181..6a4f280adcf3 100644 --- a/packages/vector_graphics_compiler/lib/src/svg/parser.dart +++ b/packages/vector_graphics_compiler/lib/src/svg/parser.dart @@ -1587,7 +1587,7 @@ class SvgParser { cap: _parseCap(rawStrokeCap, null), join: _parseJoin(rawLineJoin, null), miterLimit: parseDouble(rawMiterLimit), - width: parseDoubleWithUnits(rawStrokeWidth), + width: parseDoubleWithUnits(rawStrokeWidth, tryParse: true), dashArray: _parseDashArray(rawStrokeDashArray), dashOffset: _parseDashOffset(rawStrokeDashOffset), hasPattern: hasPattern, diff --git a/packages/vector_graphics_compiler/pubspec.yaml b/packages/vector_graphics_compiler/pubspec.yaml index 1eba55f247b3..5beb9df96240 100644 --- a/packages/vector_graphics_compiler/pubspec.yaml +++ b/packages/vector_graphics_compiler/pubspec.yaml @@ -2,7 +2,7 @@ name: vector_graphics_compiler description: A compiler to convert SVGs to the binary format used by `package:vector_graphics`. repository: https://github.com/flutter/packages/tree/main/packages/vector_graphics_compiler issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+vector_graphics%22 -version: 1.1.15 +version: 1.1.16 executables: vector_graphics_compiler: diff --git a/packages/vector_graphics_compiler/test/parser_test.dart b/packages/vector_graphics_compiler/test/parser_test.dart index e6633fb6f254..cfbec4732e6c 100644 --- a/packages/vector_graphics_compiler/test/parser_test.dart +++ b/packages/vector_graphics_compiler/test/parser_test.dart @@ -704,6 +704,87 @@ void main() { ]); }); + test('stroke-width with invalid value', () { + const String svg = + ''; + + final VectorInstructions instructions = parseWithoutOptimizers(svg); + + expect(instructions.paints, const [ + Paint( + stroke: Stroke(color: Color(0xff0000ff)), + fill: Fill(color: Color(0xffff0000))), + ]); + + expect(instructions.paths, [ + Path( + commands: const [ + MoveToCommand(100.0, 10.0), + LineToCommand(180.0, 10.0), + LineToCommand(180.0, 90.0), + LineToCommand(100.0, 90.0), + CloseCommand(), + ], + ), + ]); + }); + + test('stroke-width with unit value', () { + const SvgTheme theme = SvgTheme(); + const double ptConversionFactor = 96 / 72; + + const String svg_px = + ''; + const String svg_pt = + ''; + const String svg_ex = + ''; + const String svg_em = + ''; + const String svg_rem = + ''; + + final VectorInstructions instructionsPx = parseWithoutOptimizers(svg_px); + final VectorInstructions instructionsPt = parseWithoutOptimizers(svg_pt); + final VectorInstructions instructionsEx = parseWithoutOptimizers(svg_ex); + final VectorInstructions instructionsEm = parseWithoutOptimizers(svg_em); + final VectorInstructions instructionsRem = parseWithoutOptimizers(svg_rem); + + expect(instructionsPx.paints, [ + const Paint( + stroke: Stroke(color: Color(0xff0000ff), width: 1.0), + fill: Fill(color: Color(0xffff0000))), + ]); + + expect(instructionsPt.paints, [ + const Paint( + stroke: + Stroke(color: Color(0xff0000ff), width: 1 * ptConversionFactor), + fill: Fill(color: Color(0xffff0000))), + ]); + + expect(instructionsEx.paints, [ + Paint( + stroke: Stroke( + color: const Color(0xff0000ff), width: 1.0 * theme.xHeight), + fill: const Fill(color: Color(0xffff0000))), + ]); + + expect(instructionsEm.paints, [ + Paint( + stroke: Stroke( + color: const Color(0xff0000ff), width: 1.0 * theme.fontSize), + fill: const Fill(color: Color(0xffff0000))), + ]); + + expect(instructionsRem.paints, [ + Paint( + stroke: Stroke( + color: const Color(0xff0000ff), width: 1.0 * theme.fontSize), + fill: const Fill(color: Color(0xffff0000))), + ]); + }); + test('Dashed path', () { final VectorInstructions instructions = parseWithoutOptimizers( '''