blackears / svgSalamander

158 stars 57 forks source link

Fixed height, but variable width to keep aspect ratio #7

Closed fnatter closed 7 years ago

fnatter commented 8 years ago

Dear svgSalamander maintainer,

I am a developer of the Mind Mapping solution Freeplane (http://freeplane.org), which will use svgSalamander starting from version 1.6. Many thanks for the excellent library!

AUTOSIZE_STRETCH mostly works for Freeplane, but our artist says that not all icons are squared, and we would like to specify a squared size using setPreferredSize() (e.g. setPreferredSize(new Dimension(48,48))), and then have the width above ignored and calculated so that the aspect ratio of the SVG is preserved.

So I picked an SVG Icon that has a non-squared aspect ratio ("button_ok.svg"), and tried with AUTOSIZE_STRETCH, AUTOSIZE_HORIZ and AUTOSIZE_VERT: https://github.com/fnatter/svgtest/blob/master/screenshot.png

The minimal source code is at: https://github.com/fnatter/svgtest/blob/master/src/main/java/org/freeplane/svgtest/TestAutostretch.java

I would expect that with AUTOSIZE_HORIZ, the width is taken from setPreferredSize(), and the height is calculated to preserve the aspect ratio, and vice versa for AUTOSIZE_VERT (or the other way around). But why is the resulting image cropped (HORIZ) or there is extra space (VERT)? What am I doing wrong? (please see the minimal source code above)

All files are at: https://github.com/fnatter/svgtest

BTW: Could you add Freeplane to README.md?

Many Thanks and Best Regards, Felix

fnatter commented 8 years ago

Dimitry Polivaev (Freeplane) helped me find the problem. I will create a pull request on the weekend.

fnatter commented 8 years ago

I created a pull request for this. You can see that this works here: https://github.com/fnatter/svgtest/blob/master/screenshot-works1.png https://github.com/fnatter/svgtest/blob/master/screenshot-works2.png

It also works fine in Freeplane.

Cheers and Best Regards, Felix

blackears commented 7 years ago

Change has been merged. Thanks for looking into this issue.