Skip to content

Commit 673643f

Browse files
committed
Adds option to normalize stencil size (scaling to absolute size)
1 parent a53e4cb commit 673643f

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/com/mxgraph/svg2xml/Shape2Xml.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public static Element parse(Element element, Document xmlDoc, XmlConfig configDo
5050
{
5151
double s = configDoc.getRelativeScalingRatio();
5252

53+
if (!configDoc.isRelativeScaling())
54+
{
55+
s = Math.min(configDoc.getAbsoluteScalingX() / configDoc.getStencilBoundsX(), configDoc.getAbsoluteScalingY() / configDoc.getStencilBoundsY());
56+
}
57+
5358
if (element.getNodeName().equals("rect"))
5459
{
5560
if (element.getAttribute("transform") != null && !element.getAttribute("transform").equals(""))

src/com/mxgraph/svg2xml/Svg2Xml.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ else if (aspectRatio.toLowerCase().equals("variable"))
336336
Constraint currConstraint = constraints.get(j);
337337

338338
double x = currConstraint.getX() - bounds.getMinX();
339-
x = Math.round(x * 100.0 / bounds.getWidth()) / 100.0;
339+
x = Math.round(x * 1000.0 / bounds.getWidth()) / 1000.0;
340340
currConstraint.setX(x);
341341

342342
double y = currConstraint.getY() - bounds.getMinY();
343-
y = Math.round(y * 100.0 / bounds.getHeight()) / 100.0;
343+
y = Math.round(y * 1000.0 / bounds.getHeight()) / 1000.0;
344344
currConstraint.setY(y);
345345
}
346346

@@ -2252,8 +2252,16 @@ private static void createBackbone(Document destDoc, XmlConfig destConfigDoc, St
22522252

22532253
if (destConfigDoc.isCalculateBorder())
22542254
{
2255-
double w = destConfigDoc.getStencilBoundsX() * s;
2256-
double h = destConfigDoc.getStencilBoundsY() * s;
2255+
double w = Math.round(destConfigDoc.getStencilBoundsX() * s * 1000.0) / 1000.0;
2256+
double h = Math.round(destConfigDoc.getStencilBoundsY() * s * 1000.0) / 1000.0;
2257+
2258+
if (!destConfigDoc.isRelativeScaling())
2259+
{
2260+
double sc = Math.min(destConfigDoc.getAbsoluteScalingX() / destConfigDoc.getStencilBoundsX(), destConfigDoc.getAbsoluteScalingY() / destConfigDoc.getStencilBoundsY());
2261+
w = Math.round(destConfigDoc.getStencilBoundsX() * sc * 1000.0) / 1000.0;
2262+
h = Math.round(destConfigDoc.getStencilBoundsY() * sc * 1000.0) / 1000.0;
2263+
}
2264+
22572265
root.setAttribute("w", String.valueOf(w));
22582266
root.setAttribute("h", String.valueOf(h));
22592267
}

src/com/mxgraph/svg2xml/Svg2XmlGui.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class Svg2XmlGui implements ActionListener{
4949
protected boolean roundCoords=true;
5050

5151
//round to decimals (used with roundCoords=true)
52-
protected int decimalsToRound=2;
52+
protected int decimalsToRound=3;
5353

5454
//i'm not yet sure about the exact functionality of this
5555
protected boolean overrideLocalConfig=false; //TODO make use of this var
@@ -136,7 +136,7 @@ public void actionPerformed(ActionEvent e) {
136136
relScalePanel.add(relScaleComponent);
137137

138138
JPanel absScalePanel = new JPanel();
139-
useAbsScaleComponent = new JRadioButton("TODO", !relativeScaling); //Use absolute scaling
139+
useAbsScaleComponent = new JRadioButton("Normalize size to:", !relativeScaling); //Use absolute scaling
140140
JLabel absScaleLabel1 = new JLabel("x:");
141141
absXScaleComponent = new JTextField(Double.toString(absoluteScalingX), 4);
142142
JLabel absScaleLabel2 = new JLabel("px y:");
@@ -156,7 +156,7 @@ public void actionPerformed(ActionEvent e) {
156156

157157
JPanel roundPanel = new JPanel();
158158
roundCoordinatesComponent = new JCheckBox("Round coordinates to ", roundCoords);
159-
roundDecimalNumComponent = new JTextField("2", 4);
159+
roundDecimalNumComponent = new JTextField("3", 4);
160160
JLabel decimalLabel1 = new JLabel("decimals");
161161
roundPanel.add(roundCoordinatesComponent);
162162
roundPanel.add(roundDecimalNumComponent);

0 commit comments

Comments
 (0)