Skip to content
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

Closed
RoastVeg opened this issue Feb 26, 2019 · 6 comments

Comments

@RoastVeg
Copy link

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

  • What is the behaviour you expect?
    The value of the screenCTM is displayed under the SVG.
  • What is happening instead?
    Correct behaviour in most browsers, but Firefox throws an error in the console.
  • What error message are you getting?
    Usually "TypeError: source is null", under SVG.Matrix() - though other errors may well be provoked under other circumstances.
@Fuzzyma
Copy link
Member

Fuzzyma commented Feb 26, 2019

Whats the usecase of a viewbox of 0 0 0 0?

@RoastVeg
Copy link
Author

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.

@Fuzzyma
Copy link
Member

Fuzzyma commented Feb 26, 2019

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
  }
})

@RoastVeg
Copy link
Author

RoastVeg commented Aug 5, 2019

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

@Fuzzyma
Copy link
Member

Fuzzyma commented Sep 3, 2023

I wrapped screenCtm in a try catch and it now always returns a matrix

@Fuzzyma
Copy link
Member

Fuzzyma commented Jun 18, 2024

I am sorry, I somehow forgot to publish all the fixes I made. I just released it:
https://github.com/svgdotjs/svg.js/releases/tag/3.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants