-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firefox returns null on native getScreenCTM for SVG objects with a viewBox of all zero #968
Comments
Whats the usecase of a viewbox of 0 0 0 0? |
According to the SVG 1.1 specification, setting the width or height to zero is a valid method to disable rendering of the SVG element, and will display as such in all browsers. Any program with dynamic viewBox manipulation should reasonably expect the acceptable range to be >=0 for both, especially if the source SVG data is not known ahead of time. |
While I accept that argument, it seems unpractical to me. Even if this is for your specific usecase an issue, I think this will not be fixed in this library. I dont want to calculate the screenCTM manually in case FF throws an error. And changing the viewbox, getting the matrix and then setting it back is also a huge and slow hack. If you need a handling for this usecase, you might be better off to just implement it yourself. You can change the default viewbox method by using extend: // its SVG.Doc in svg.js v2
SVG.extend(SVG.Svg, {
viewbox () {
// own implementation
}
}) |
Update: this also breaks in the (rather common) scenario that the canvas is hidden. On Chrome the correct CTM is displayed, but FF produces an identical error. Here is a minimal fiddle: link |
I wrapped screenCtm in a try catch and it now always returns a matrix |
I am sorry, I somehow forgot to publish all the fixes I made. I just released it: |
Bug report
Any and all SVG objects with a viewBox attribute of "0 0 0 0" return null under Firefox when getScreenCTM is called on them. This causes all sorts of issues with svg.js when trying to apply any transformations on them. Although this issue rests with FF, a workaround is definitely required for cross browser compatibility. FF has a history of buggy CTM code.
Fiddle
A fiddle demonstrating the issue can be found here.
Explanation
The value of the screenCTM is displayed under the SVG.
Correct behaviour in most browsers, but Firefox throws an error in the console.
Usually "TypeError: source is null", under SVG.Matrix() - though other errors may well be provoked under other circumstances.
The text was updated successfully, but these errors were encountered: