A start on SVG "quirks mode"#56
Conversation
# Conflicts: # src/Drawable.js
cwillisf
left a comment
There was a problem hiding this comment.
Nice work! The code looks pretty good -- I have one nitpick that could go either way. How many browsers have you tested this with?
I'm worried about license compatibility so I'm going to mark this as "Request changes" for the moment, but if it turns out that the licenses are in fact compatible then you can consider this approved.
|
|
||
| Apache License | ||
| Version 2.0, January 2004 | ||
| http://www.apache.org/licenses/ |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
| document.body.appendChild(svgSpot); | ||
| svgSpot.appendChild(this._svgTag); | ||
| // Take the bounding box, and then destroy the element. | ||
| let bbox = this._svgTag.getBBox(); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
|
@tmickel do you know of a way to tell (from code) that a particular SVG was created in the Scratch 2.0 style? I'm imagining a world where some of our SVGs require this special treatment but others can be render as-is... how do we tell the difference? |
|
@cwillisf Unfortunately I'm not sure if there's an easy way to accomplish what you're talking about. The Scratch 2.0 paint editor does insert a comment into SVGs, along the lines of But, it would make sense to me for future assets and imports to use a different renderer (ideally a pure browser renderer that respects viewboxes and whatever, maybe). In that case we should probably explicitly mark new assets to distinguish when we can use a "standards mode" renderer? Any thoughts @thisandagain ? |
|
Thanks for putting this together @tmickel . This looks like a great start. I like the idea of tagging new SVGs so we can use a less "quirky" rendering approach and (hopefully) split with some of the pain that we see in 2.0: |
|
How do you plan to handle the case for a SVG file being imported? For example, an SVG file made in Inkscape or something similar would work best being rendered by the browser, but an SVG that had previously been downloaded from Scratch might work best in quirks mode. My suggestion would be to treat all imported SVGs as normal SVGs (ie not quirks mode) Also:
I've been using Inkscape for SVGs for quite a while now. Whilst Scratch 2.0s support for more advanced SVG features (eg. shadows) is ... interesting, I never had any quirks mode problems myself |
|
@chooper100 Any SVG that could have previously been rendered by Scratch 2.0 would be rendered in quirks mode. That includes SVGs created by external tools, and SVGs created in the paint editor. Treating import-SVGs differently would no doubt lead to broken projects, because they are rendered in 2.0 with these quirks and possibly more. I'm not sure I understand what you're saying, I don't think these are treated differently in scratch-flash if they're made in external tools. Do you have an example of an SVG created in Inkscape, for example, where the viewBox is smaller than the graphic, and Scratch renders the clipped graphic? |
|
My interpretation of @chooper100's comments:
I think we can continue to discuss when (and when not) to use Scratch 2.0 quirks-mode SVG rendering independently of this PR. As long as we want to do it in at least one case, we'll need some code like this :) |
|
@cwillisf Comments addressed I think - any other thoughts? By the way, I tested in Chrome, Firefox, and Safari. I didn't test in IE or Edge. |
|
Update:
|
cwillisf
left a comment
There was a problem hiding this comment.
👍
For the record, my SVG code was broken in IE from the beginning. I'm curious what's up with Edge, but IMO it shouldn't hold up this PR.
|
👏 |
* Start of an SVG rendering quirks mode * Provide font defaults in SVG quirks mode * Remove svg-to-image dependency * Remove fonts and use package fonts instead. * try/finally for getBBox
* Start of an SVG rendering quirks mode * Provide font defaults in SVG quirks mode * Remove svg-to-image dependency * Remove fonts and use package fonts instead. * try/finally for getBBox
I definitely don't think this is complete, but hopefully it can provide some thinking for how to approach Scratch 2.0 quirks.
Example project:
https://scratch.mit.edu/projects/127228166/
Before "quirks mode":


After "quirks mode":
Differences:
getBBoxmeasurements, before re-drawing the SVG again with corrected measurements. I tried to do this several different ways - this was the best way I found so far.xandyproperties that Scratch 2.0 appears to set incorrectly and otherwise ignore, fixes non-standard line break treatment, and adds in fonts (which was actually quite tricky).There is no doubt in my mind that this has bugs, is incomplete (I'm sure there are more quirks), and maybe these could be done better some other way. Would be happy to have more ideas!