Added #1913 Retaining shape exact position(bounds) in SVG export (Can be turned on in advanced settings)

This commit is contained in:
Jindra Petřík
2023-01-11 21:17:59 +01:00
parent 29e2dc7ce3
commit 99ef1fbbbf
5 changed files with 26 additions and 3 deletions

View File

@@ -879,6 +879,10 @@ public final class Configuration {
@ConfigurationCategory("ui")
public static ConfigurationItem<Boolean> showImportSoundInfo = null;
@ConfigurationDefaultBoolean(false)
@ConfigurationCategory("export")
public static ConfigurationItem<Boolean> svgRetainBounds = null;
private enum OSId {
WINDOWS, OSX, UNIX
}

View File

@@ -96,8 +96,13 @@ public class SVGExporter {
Element svgRoot = _svg.getDocumentElement();
svgRoot.setAttribute("xmlns:xlink", xlinkNamespace);
if (bounds != null) {
svgRoot.setAttribute("width", (bounds.getWidth() / SWF.unitDivisor) + "px");
svgRoot.setAttribute("height", (bounds.getHeight() / SWF.unitDivisor) + "px");
if (Configuration.svgRetainBounds.get()) {
svgRoot.setAttribute("width", (bounds.xMax / SWF.unitDivisor) + "px");
svgRoot.setAttribute("height", (bounds.yMax / SWF.unitDivisor) + "px");
} else {
svgRoot.setAttribute("width", (bounds.getWidth() / SWF.unitDivisor) + "px");
svgRoot.setAttribute("height", (bounds.getHeight() / SWF.unitDivisor) + "px");
}
createDefGroup(bounds, null, zoom);
}
} catch (ParserConfigurationException ex) {
@@ -131,7 +136,12 @@ public class SVGExporter {
public final void createDefGroup(ExportRectangle bounds, String id, double zoom) {
Element g = _svg.createElement("g");
if (bounds != null) {
Matrix mat = Matrix.getTranslateInstance(-bounds.xMin, -bounds.yMin);
Matrix mat;
if (Configuration.svgRetainBounds.get()) {
mat = new Matrix();
} else {
mat = Matrix.getTranslateInstance(-bounds.xMin, -bounds.yMin);
}
mat.scale(zoom);
g.setAttribute("transform", mat.getSvgTransformationString(SWF.unitDivisor, 1));
}