Skip to content

Commit 5b08378

Browse files
[vector_graphics_compiler] Set the m4_10 (Z scale) value to 1 when constructing an AffineMatrix from an SVG matrix (#9813)
The 4x4 matrix produced by the SVG matrix() function should have its 10th element set to 1. (see https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix) The SVG matrix parser constructs an AffineMatrix from the SVG input. The AffineMatrix is then converted into a list that is given to Flutter engine APIs. Before flutter/engine@62cb2c9, the Flutter engine was implicitly overriding the 10th element of the matrix with a 1 value. After that commit, the engine uses the matrix contents as is and does not override any values. This PR changes the SVG matrix parser to explicitly set the AffineMatrix m4_10 parameter to 1. This reflects the SVG spec and produces output that matches the original engine behavior. See flutter/flutter#171854
1 parent 5866014 commit 5b08378

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

packages/vector_graphics_compiler/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## NEXT
1+
## 1.1.18
22

33
* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
4+
* Fixes SVG matrix parsing to explicitly set the Z scale value.
45

56
## 1.1.17
67

packages/vector_graphics_compiler/lib/src/svg/parsers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ AffineMatrix _parseSvgMatrix(List<double> params, AffineMatrix current) {
9393
final double e = params[4];
9494
final double f = params[5];
9595

96-
return AffineMatrix(a, b, c, d, e, f).multiplied(current);
96+
return AffineMatrix(a, b, c, d, e, f, 1.0).multiplied(current);
9797
}
9898

9999
AffineMatrix _parseSvgSkewX(List<double> params, AffineMatrix current) {

packages/vector_graphics_compiler/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: vector_graphics_compiler
22
description: A compiler to convert SVGs to the binary format used by `package:vector_graphics`.
33
repository: https://github.com/flutter/packages/tree/main/packages/vector_graphics_compiler
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+vector_graphics%22
5-
version: 1.1.17
5+
version: 1.1.18
66

77
executables:
88
vector_graphics_compiler:

packages/vector_graphics_compiler/test/end_to_end_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void main() {
320320
0.0,
321321
0.0,
322322
0.0,
323-
3.0,
323+
1.0,
324324
0.0,
325325
30.0,
326326
40.0,

packages/vector_graphics_compiler/test/parsers_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ void main() {
132132

133133
expect(
134134
parseTransform('matrix(1.5, 2.0, 3.0, 4.0, 5.0, 6.0)'),
135-
const AffineMatrix(1.5, 2.0, 3.0, 4.0, 5.0, 6.0),
135+
const AffineMatrix(1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0),
136136
);
137137

138138
expect(
139139
parseTransform('matrix(1.5, 2.0, 3.0, 4.0, 5.0, 6.0 )'),
140-
const AffineMatrix(1.5, 2.0, 3.0, 4.0, 5.0, 6.0),
140+
const AffineMatrix(1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0),
141141
);
142142

143143
expect(
@@ -198,7 +198,7 @@ void main() {
198198
0.70711, -0.70711, //
199199
0.70711, 0.70711, //
200200
-640.89, 452.68, //
201-
0.70711, //
201+
1.0, //
202202
),
203203
);
204204
});

0 commit comments

Comments
 (0)