Determining the Viewport for an SVG Element

In order to solve my desire to have text use the same font size[1] regardless of zooming (via the viewBox), I needed to determine the size of the viewport for the root <svg> element [2].

Given that the renderer needs to calculate this viewport anyhow, I would have thought that it would be exposed via some interface. As far as I can tell, it is not (either in specifications or practice). Am I missing something? Is there supposed to be a method/property that returns the viewport size of the contents?

The amount of code in [2] below is far more than I would like, and even then it requires knowledge of the outer dimensions of the SVG element (something that does not currently work in Firefox [3]). If there does not already exist a specification designed to grant this information directly, I would like to propose that one should be added.

(Independent of all this, I’m also interested: have there been any discussions of scale/zoom independent font sizes, similar in desire to vector-effect:non-scaling-stroke?)


[1] http://stackoverflow.com/questions/23645150/maintain-same-font-size-text-regardless-of-viewbox-zooming
[2] http://stackoverflow.com/questions/23664967/determining-the-svg-viewport-in-global-root-coordinates
[3] https://bugzilla.mozilla.org/show_bug.cgi?id=530985

Received on Friday, 16 May 2014 22:28:42 UTC