Properly handle Scratch 2.0's <image> behavior... but at what cost? #88
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.
Resolves
Resolves #58 (at least for PNGs)
Proposed Changes
This PR adds a new step to the Scratch 2.0 compatibility mode path that strips the "x" and "y" attributes from
<image>
s, and sets their "width" and "height" to their actual resolution.Currently, in order to keep
SvgRenderer.fromString()
synchronous, this step only operates on PNG images, reading their width and height directly from their binary data*.A much more robust solution would be to create an
<img>
element for each SVG<image>
, and read the width and height from there. However, this only works if you read the dimensions after the<img>
has loaded, which you need an event callback to do. This would makeSvgRenderer.fromString()
an asynchronous function, which has implications for the rest of the Scratch codebase.Reason for Changes
Scratch 2.0 ignores
<image>
s' "x", "y", "width", and "height", only recognizing the "transform" attribute.*it's not an ugly hack if it's well-commented, amirite?