Skip to content

Commit 5bc6a02

Browse files
authored
Save before clip (dnfield#232)
1 parent d67db22 commit 5bc6a02

File tree

8 files changed

+45
-10
lines changed

8 files changed

+45
-10
lines changed

packages/vector_graphics/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 1.1.10+1
4+
5+
- Add missing save before clip.
6+
37
## 1.1.10
48

59
- Add missing clip before saveLayer.

packages/vector_graphics/lib/src/render_vector_graphic.dart

+1
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ class RenderPictureVectorGraphic extends RenderBox {
439439
context.canvas.translate(offset.dx, offset.dy);
440440
}
441441
if (_opacityValue != 1.0 || colorFilter != null) {
442+
context.canvas.save();
442443
context.canvas.clipRect(Offset.zero & size);
443444
context.canvas.saveLayer(Offset.zero & size, colorPaint);
444445
}

packages/vector_graphics/pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: vector_graphics
22
description: A vector graphics rendering package for Flutter.
3-
version: 1.1.10
3+
version: 1.1.10+1
44
homepage: https://github.com/dnfield/vector_graphics
55

66
environment:
@@ -10,13 +10,13 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13-
vector_graphics_codec: 1.1.10
13+
vector_graphics_codec: 1.1.10+1
1414

1515
dev_dependencies:
1616
flutter_test:
1717
sdk: flutter
1818
flutter_lints: ^1.0.0
19-
vector_graphics_compiler: 1.1.10
19+
vector_graphics_compiler: 1.1.10+1
2020

2121
# Comment out before publishing
2222
dependency_overrides:

packages/vector_graphics/test/render_vector_graphics_test.dart

+25-3
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ void main() {
421421

422422
expect(context.canvas.lastClipRect,
423423
equals(const ui.Rect.fromLTRB(0, 0, 50, 50)));
424+
expect(context.canvas.saveCount, 0);
425+
expect(context.canvas.totalSaves, 1);
426+
expect(context.canvas.totalSaveLayers, 1);
424427
});
425428
}
426429

@@ -430,6 +433,9 @@ class FakeCanvas extends Fake implements Canvas {
430433
Rect? lastDst;
431434
Paint? lastPaint;
432435
Rect? lastClipRect;
436+
int saveCount = 0;
437+
int totalSaves = 0;
438+
int totalSaveLayers = 0;
433439

434440
@override
435441
void drawImageRect(ui.Image image, Rect src, Rect dst, Paint paint) {
@@ -444,14 +450,30 @@ class FakeCanvas extends Fake implements Canvas {
444450

445451
@override
446452
int getSaveCount() {
447-
return 0;
453+
return saveCount;
448454
}
449455

450456
@override
451-
void restoreToCount(int count) {}
457+
void restoreToCount(int count) {
458+
saveCount = count;
459+
}
460+
461+
@override
462+
void saveLayer(Rect? bounds, Paint paint) {
463+
saveCount++;
464+
totalSaveLayers++;
465+
}
452466

453467
@override
454-
void saveLayer(Rect? bounds, Paint paint) {}
468+
void save() {
469+
saveCount++;
470+
totalSaves++;
471+
}
472+
473+
@override
474+
void restore() {
475+
saveCount--;
476+
}
455477

456478
@override
457479
void clipRect(ui.Rect rect,

packages/vector_graphics_codec/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 1.1.10+1
4+
5+
- Add missing save before clip.
6+
37
## 1.1.10
48

59
- Add missing clip before saveLayer.

packages/vector_graphics_codec/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: vector_graphics_codec
22
description: An encoding library for `package:vector_graphics`
3-
version: 1.1.10
3+
version: 1.1.10+1
44
homepage: https://github.com/dnfield/vector_graphics
55

66
environment:

packages/vector_graphics_compiler/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 1.1.10+1
4+
5+
- Add missing save before clip.
6+
37
## 1.1.10
48

59
- Add missing clip before saveLayer.

packages/vector_graphics_compiler/pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: vector_graphics_compiler
22
description: A compiler for `package:vector_graphics`.
3-
version: 1.1.10
3+
version: 1.1.10+1
44
homepage: https://github.com/dnfield/vector_graphics
55

66
executables:
@@ -14,7 +14,7 @@ dependencies:
1414
meta: ^1.7.0
1515
path_parsing: ^1.0.1
1616
xml: ^6.3.0
17-
vector_graphics_codec: 1.1.10
17+
vector_graphics_codec: 1.1.10+1
1818
path: ^1.8.0
1919

2020
dev_dependencies:
@@ -25,7 +25,7 @@ dev_dependencies:
2525
sdk: flutter
2626
flutter_test:
2727
sdk: flutter
28-
vector_graphics: 1.1.10
28+
vector_graphics: 1.1.10+1
2929

3030
# Comment out before publishing
3131
dependency_overrides:

0 commit comments

Comments
 (0)