MGraphics: jsvg_get_size behavior has changed WHY ?

Nodanoma's icon

Hello all,

this may well be the wrong place to ask about this but does anyone know why certain MGraphics functionality has simply been 'changed' ?

The console is clogged with messages such as this one

jsvg_get_size behavior has changed. viewbox X/Y offset unused. color_palette.svg viewbox: 4294967247 0 1181 4294968426

After a long spell of settup a lot of v8ui code to support neat SVG-rendering many of them now appear scaled, compressed, deformed — all because jsvg_get_size behavior has changed. This has been implemented in the latest version of Max.

Is this going to be fixed again or am I to expect such changes with any odd update now? Very hard to predict what's going to happen next I am now having to revisit all of my code to scale all vector graphics correctly — in all of my projects. Unless this will be fixed again. Will it ?

This really ain't good! What am I missing ¿?

Joshua Kit Clayton's icon

The old jsvg_get_size function was ambiguous in considering the size of an SVG when the viewbox did not start at 0,0. This posed a number of problems for SVG files with things like negative offsets and a general mismatch for expected sizes in situations where the desired size was to make use of the viewbox as expected in most software.

Can you share a simple example with your SVG file and drawing code? If so, I can then determine if there is something better we can do for this, or if even there is a bug in the changes (those view box numbers above look ridiculously large).

If you want a quick and dirty solution you should be able to do something like the following to simulate the old behavior, but again that viewbox looks suspicious to me, so a solid example would be helpful to see.

function legacy_getsize(svg)
{
  var viewbox = svg.viewbox;
  var width = viewbox[2] + viewbox[0]; // viewbox width plus x offset
  var height = viewbox[3] + viewbox[1]; // viewbox height plus y offset
  return [width, height];
}

Thanks!