Skip to content

Commit be4662f

Browse files
authored
Remove linear gradient tranfsorms from codec (#28)
* Remove linear gradient tranfsorms from codec * fix radial gradient with no matrix
1 parent 54113fe commit be4662f

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

packages/vector_graphics/lib/src/listener.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ class FlutterVectorGraphicsListener extends VectorGraphicsCodecListener {
186186
double toY,
187187
Int32List colors,
188188
Float32List? offsets,
189-
Float64List? transform,
190189
int tileMode,
191190
int id,
192191
) {
@@ -203,7 +202,6 @@ class FlutterVectorGraphicsListener extends VectorGraphicsCodecListener {
203202
colorValues,
204203
offsets,
205204
ui.TileMode.values[tileMode],
206-
transform,
207205
);
208206
_shaders.add(gradient);
209207
}

packages/vector_graphics_codec/lib/vector_graphics_codec.dart

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,8 @@ class VectorGraphicsCodec {
211211
required double toY,
212212
required Int32List colors,
213213
required Float32List? offsets,
214-
required Float64List? transform,
215214
required int tileMode,
216215
}) {
217-
assert(transform == null || transform.length == 16);
218216
if (buffer._decodePhase.index > _CurrentSection.shaders.index) {
219217
throw StateError('Shaders must be encoded together.');
220218
}
@@ -234,12 +232,6 @@ class VectorGraphicsCodec {
234232
buffer._putInt32(offsets.length);
235233
buffer._putFloat32List(offsets);
236234
}
237-
if (transform != null) {
238-
buffer._putUint8(transform.length);
239-
buffer._putFloat64List(transform);
240-
} else {
241-
buffer._putInt32(0);
242-
}
243235
buffer._putUint8(tileMode);
244236
return shaderId;
245237
}
@@ -292,7 +284,7 @@ class VectorGraphicsCodec {
292284
buffer._putUint8(transform.length);
293285
buffer._putFloat64List(transform);
294286
} else {
295-
buffer._putInt32(0);
287+
buffer._putUint8(0);
296288
}
297289
buffer._putUint8(tileMode);
298290
return shaderId;
@@ -345,9 +337,6 @@ class VectorGraphicsCodec {
345337
final Int32List colors = buffer.getInt32List(colorLength);
346338
final int offsetLength = buffer.getInt32();
347339
final Float32List offsets = buffer.getFloat32List(offsetLength);
348-
final int transformLength = buffer.getUint8();
349-
final Float64List? transform =
350-
transformLength != 0 ? buffer.getFloat64List(transformLength) : null;
351340
final int tileMode = buffer.getUint8();
352341
listener?.onLinearGradient(
353342
fromX,
@@ -356,7 +345,6 @@ class VectorGraphicsCodec {
356345
toY,
357346
colors,
358347
offsets,
359-
transform,
360348
tileMode,
361349
id,
362350
);
@@ -721,7 +709,6 @@ abstract class VectorGraphicsCodecListener {
721709
double toY,
722710
Int32List colors,
723711
Float32List? offsets,
724-
Float64List? transform,
725712
int tileMode,
726713
int id,
727714
);

packages/vector_graphics_codec/test/vector_graphics_codec_test.dart

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,41 @@ void main() {
251251
]);
252252
});
253253

254+
test('Can encode a radial gradient (no matrix)', () {
255+
final buffer = VectorGraphicsBuffer();
256+
final TestListener listener = TestListener();
257+
258+
final int shaderId = codec.writeRadialGradient(
259+
buffer,
260+
centerX: 2.0,
261+
centerY: 3.0,
262+
radius: 5.0,
263+
focalX: 1.0,
264+
focalY: 1.0,
265+
colors: Int32List.fromList([0xFFAABBAA]),
266+
offsets: Float32List.fromList([2.2, 1.2]),
267+
tileMode: 0,
268+
transform: null,
269+
);
270+
271+
codec.decode(buffer.done(), listener);
272+
273+
expect(listener.commands, [
274+
OnRadialGradient(
275+
centerX: 2.0,
276+
centerY: 3.0,
277+
radius: 5.0,
278+
focalX: 1.0,
279+
focalY: 1.0,
280+
colors: Int32List.fromList([0xFFAABBAA]),
281+
offsets: Float32List.fromList([2.2, 1.2]),
282+
transform: null,
283+
tileMode: 0,
284+
id: shaderId,
285+
),
286+
]);
287+
});
288+
254289
test('Can encode a linear gradient', () {
255290
final buffer = VectorGraphicsBuffer();
256291
final TestListener listener = TestListener();
@@ -264,7 +299,6 @@ void main() {
264299
colors: Int32List.fromList([0xFFAABBAA]),
265300
offsets: Float32List.fromList([2.2, 1.2]),
266301
tileMode: 0,
267-
transform: mat4,
268302
);
269303

270304
codec.decode(buffer.done(), listener);
@@ -277,7 +311,6 @@ void main() {
277311
toY: 1.0,
278312
colors: Int32List.fromList([0xFFAABBAA]),
279313
offsets: Float32List.fromList([2.2, 1.2]),
280-
transform: mat4,
281314
tileMode: 0,
282315
id: shaderId,
283316
),
@@ -465,7 +498,6 @@ class TestListener extends VectorGraphicsCodecListener {
465498
double toY,
466499
Int32List colors,
467500
Float32List? offsets,
468-
Float64List? transform,
469501
int tileMode,
470502
int id,
471503
) {
@@ -476,7 +508,6 @@ class TestListener extends VectorGraphicsCodecListener {
476508
toY: toY,
477509
colors: colors,
478510
offsets: offsets,
479-
transform: transform,
480511
tileMode: tileMode,
481512
id: id,
482513
));
@@ -500,7 +531,6 @@ class OnLinearGradient {
500531
required this.toY,
501532
required this.colors,
502533
required this.offsets,
503-
required this.transform,
504534
required this.tileMode,
505535
required this.id,
506536
});
@@ -511,7 +541,6 @@ class OnLinearGradient {
511541
final double toY;
512542
final Int32List colors;
513543
final Float32List? offsets;
514-
final Float64List? transform;
515544
final int tileMode;
516545
final int id;
517546

@@ -523,7 +552,6 @@ class OnLinearGradient {
523552
toY,
524553
Object.hashAll(colors),
525554
Object.hashAll(offsets ?? []),
526-
Object.hashAll(transform ?? []),
527555
tileMode,
528556
id,
529557
);
@@ -537,7 +565,6 @@ class OnLinearGradient {
537565
other.toY == toY &&
538566
_listEquals(other.colors, colors) &&
539567
_listEquals(other.offsets, offsets) &&
540-
_listEquals(other.transform, transform) &&
541568
other.tileMode == tileMode &&
542569
other.id == id;
543570
}

packages/vector_graphics_compiler/lib/vector_graphics_compiler.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ Future<Uint8List> encodeSvg(String input, String filename) async {
6868
? Float32List.fromList(shader.offsets!)
6969
: null,
7070
tileMode: shader.tileMode.index,
71-
transform: _encodeMatrix(shader.transform),
7271
);
7372
} else if (shader is RadialGradient) {
7473
shaderId = codec.writeRadialGradient(

0 commit comments

Comments
 (0)