Skip to content

Commit

Permalink
Save before clip (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored Feb 6, 2024
1 parent d67db22 commit 5bc6a02
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/vector_graphics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.1.10+1

- Add missing save before clip.

## 1.1.10

- Add missing clip before saveLayer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class RenderPictureVectorGraphic extends RenderBox {
context.canvas.translate(offset.dx, offset.dy);
}
if (_opacityValue != 1.0 || colorFilter != null) {
context.canvas.save();
context.canvas.clipRect(Offset.zero & size);
context.canvas.saveLayer(Offset.zero & size, colorPaint);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vector_graphics/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: vector_graphics
description: A vector graphics rendering package for Flutter.
version: 1.1.10
version: 1.1.10+1
homepage: https://github.com/dnfield/vector_graphics

environment:
Expand All @@ -10,13 +10,13 @@ environment:
dependencies:
flutter:
sdk: flutter
vector_graphics_codec: 1.1.10
vector_graphics_codec: 1.1.10+1

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
vector_graphics_compiler: 1.1.10
vector_graphics_compiler: 1.1.10+1

# Comment out before publishing
dependency_overrides:
Expand Down
28 changes: 25 additions & 3 deletions packages/vector_graphics/test/render_vector_graphics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ void main() {

expect(context.canvas.lastClipRect,
equals(const ui.Rect.fromLTRB(0, 0, 50, 50)));
expect(context.canvas.saveCount, 0);
expect(context.canvas.totalSaves, 1);
expect(context.canvas.totalSaveLayers, 1);
});
}

Expand All @@ -430,6 +433,9 @@ class FakeCanvas extends Fake implements Canvas {
Rect? lastDst;
Paint? lastPaint;
Rect? lastClipRect;
int saveCount = 0;
int totalSaves = 0;
int totalSaveLayers = 0;

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

@override
int getSaveCount() {
return 0;
return saveCount;
}

@override
void restoreToCount(int count) {}
void restoreToCount(int count) {
saveCount = count;
}

@override
void saveLayer(Rect? bounds, Paint paint) {
saveCount++;
totalSaveLayers++;
}

@override
void saveLayer(Rect? bounds, Paint paint) {}
void save() {
saveCount++;
totalSaves++;
}

@override
void restore() {
saveCount--;
}

@override
void clipRect(ui.Rect rect,
Expand Down
4 changes: 4 additions & 0 deletions packages/vector_graphics_codec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.1.10+1

- Add missing save before clip.

## 1.1.10

- Add missing clip before saveLayer.
Expand Down
2 changes: 1 addition & 1 deletion packages/vector_graphics_codec/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: vector_graphics_codec
description: An encoding library for `package:vector_graphics`
version: 1.1.10
version: 1.1.10+1
homepage: https://github.com/dnfield/vector_graphics

environment:
Expand Down
4 changes: 4 additions & 0 deletions packages/vector_graphics_compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.1.10+1

- Add missing save before clip.

## 1.1.10

- Add missing clip before saveLayer.
Expand Down
6 changes: 3 additions & 3 deletions packages/vector_graphics_compiler/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: vector_graphics_compiler
description: A compiler for `package:vector_graphics`.
version: 1.1.10
version: 1.1.10+1
homepage: https://github.com/dnfield/vector_graphics

executables:
Expand All @@ -14,7 +14,7 @@ dependencies:
meta: ^1.7.0
path_parsing: ^1.0.1
xml: ^6.3.0
vector_graphics_codec: 1.1.10
vector_graphics_codec: 1.1.10+1
path: ^1.8.0

dev_dependencies:
Expand All @@ -25,7 +25,7 @@ dev_dependencies:
sdk: flutter
flutter_test:
sdk: flutter
vector_graphics: 1.1.10
vector_graphics: 1.1.10+1

# Comment out before publishing
dependency_overrides:
Expand Down

0 comments on commit 5bc6a02

Please sign in to comment.