lucaslorentz / AS3SVGRenderer

An AS3 SVG Renderer for Flash Player.
106 stars 28 forks source link

svg is drawn smaller than actual size #39

Open 9tontruck opened 10 years ago

9tontruck commented 10 years ago

SVG object is drawn about 25% smaller than the actual size.

see this photo please: http://imageshack.com/a/img203/5676/gqrf.jpg

The first line in the photo is drawn by my own SVG parser. The second line is drawn by AS3SVGRenderer.

Both parsers used to draw in the same size but this problem happened after I updated AS3SVGRenderer from one-year old version to the newest version.

All I wrote is var svg:SVG = new SVG() //Flex.SVG svg.source = getSVGText();

Is there anything I am missing?

9tontruck commented 10 years ago

Figured out having viewbox parameter in tag makes size problem.

mattlohkamp commented 10 years ago

this is huge - even if the artwork is 120x120, the artboard is 120x120, everything is 120x120 - the image drawn in flash might still end up being scaled wrong. removing that viewbox attr fixes it.

this is still very much a big bug.

lucaslorentz commented 10 years ago

I am comparing the library result with chrome. And both size is precisely equal when you have a viewbox and the svg width and height are set as pixels.

But if I change svg width and height to pt, in, cm, or any unit that must be converted using dpi, there is a slight size difference between the AS3SVGRenderer and chrome.

That conversion is coded on method getUserUnit, at this file: https://github.com/LucasLorentz/AS3SVGRenderer/blob/master/SVGRenderer/src/com/lorentz/SVG/utils/SVGUtil.as

You can see that the conversion from "in" to "pixels" (user unit) is a multiplication by "90", that, means that this library considers 90 dpi (dots per inch). Which is the same of Inkscape. But each renderer choose a different DPI to render, maybe that's the difference that you are seeing.

Take a look at those links: http://stackoverflow.com/questions/1346922/svg-and-dpi-absolute-units-and-user-units-inkscape-vs-firefox-vs-imagemagick http://www.w3.org/TR/SVG/coords.html#Units

Can any of you confirm that this is what is causing the difference on size? If that's the problem, I can provide a property to configure the DPI the library should use, that way you can customize it to fit your needs.

If that isn't the problem, can you provide me an svg to reproduce the problem?

About the differences between old version of AS3SVGRenderer and the current version, I believe the version you were using don't support ViewBox and ViewPort correctly, so it don't re-scale the svg.

mattlohkamp commented 10 years ago

github won't let me attach svgs, so here are a couple links -

http://junk.mattlohkamp.com/2in1.svg http://junk.mattlohkamp.com/tablet.svg

not sure what version of the library this was using, I wanna say I grabbed it a couple months ago?

it was happening intermittently too, which was one of the weirdest parts - sometimes they'd scale correctly, sometimes they wouldn't. sorry, I know this isn't much help. :[

I'll see if I can dig up the old build of my project that was showing the issue.