This repository was archived by the owner on Feb 25, 2025. It is now read-only.
fix the bounds of nested save layers with a mix of clips and transforms #31437
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes dnfield/flutter_svg#661
(Note that the first example in that issue was the only issue that I was able to see a problem on, the other 3 issues added as github comments don't seem to fail for me. But, this fix does fix that first example.)
The problem causing the SVG to not display was the fact that we were getting the bounds of nested save/saveLayer calls wrong. At some point I decided to accumulate the bounds of the layers into their own accumulators and then transforming and clipping them when I accumulated those bounds into the outer layer's bounds in the restore() call. Unfortunately, this doesn't work because the clip is in device pixels (actually in "the pixel coordinate space in which the DL is rendered" to be specific) and so when I reset the matrix and not the clip I would end up with mismatched a clip and matrix that didn't agree on the coordinate space in which they applied.
I fixed this by 2 essential changes:
LayerDatasubclasses in favor of a single class that just remembers the needed information and lets therestore()call do the work in one location that is easier to understand and maintain.