Skip to content

Commit 8f75982

Browse files
committed
Fixes gradient NPEs and fixes duplicate fill entries
1 parent 673643f commit 8f75982

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

src/com/mxgraph/svg2xml/Svg2Xml.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,12 @@ else if (aspectRatio.toLowerCase().equals("variable"))
500500
//16. compare the new style with the old one, and add the differences to the XML
501501
styleDiff = getStyleDiff(oldStyle, currStyle);
502502
}
503-
503+
504+
// if (currStyle.getStrokeColor() == "")
505+
// {
506+
// currStyle.setStrokeColor("none");
507+
// }
508+
504509
appendStyle(destDoc.getElementsByTagName("foreground").item(0), styleDiff, destConfigDoc, nextElement);
505510

506511
//18. translate the SVG element into XML
@@ -667,11 +672,11 @@ static String getStrokeString(XmlStyle currStyle)
667672
String fc = currStyle.getFillColor();
668673
String sc = currStyle.getStrokeColor();
669674

670-
if (!fc.equals("none") && !sc.equals("none"))
675+
if (!fc.equals("none") && !sc.equals("none") && !sc.equals(""))
671676
{
672677
return "fillstroke";
673678
}
674-
else if (!fc.equals("none") && sc.equals("none"))
679+
else if (!fc.equals("none"))
675680
{
676681
return "fill";
677682
}
@@ -1386,7 +1391,10 @@ private Map<String, String> parseFillDefs(Node root)
13861391
if (currEl.getNodeName().equals("linearGradient") || currEl.getNodeName().equals("radialGradient"))
13871392
{
13881393
String avgColor = getAvgGradientColor(currEl);
1389-
fillTable.put(currEl.getAttribute("id"), avgColor);
1394+
if (avgColor != null)
1395+
{
1396+
fillTable.put(currEl.getAttribute("id"), avgColor);
1397+
}
13901398
}
13911399

13921400
fillTable.putAll(parseFillDefs(currChild));
@@ -1422,7 +1430,10 @@ private Map<String, String> parseStrokeDefs(Node root)
14221430
if (currEl.getNodeName().equals("linearGradient") || currEl.getNodeName().equals("radialGradient"))
14231431
{
14241432
String avgColor = getAvgGradientColor(currEl);
1425-
strokeTable.put(currEl.getAttribute("id"), avgColor);
1433+
if (avgColor != null)
1434+
{
1435+
strokeTable.put(currEl.getAttribute("id"), avgColor);
1436+
}
14261437
}
14271438

14281439
strokeTable.putAll(parseStrokeDefs(currChild));
@@ -1462,13 +1473,13 @@ private String getAvgGradientColor(Element element)
14621473
Color col = new Color(0, 0, 0);
14631474
String colS = currEl.getAttribute("stop-color");
14641475

1465-
if (colS.charAt(0) == '#')
1476+
if (colS == null || colS.equals(""))
14661477
{
1467-
col = Color.decode(colS);
1478+
return null;
14681479
}
1469-
else if (colS == null || colS.equals(""))
1480+
else if (colS.charAt(0) == '#')
14701481
{
1471-
return null;
1482+
col = Color.decode(colS);
14721483
}
14731484
else
14741485
{

src/com/mxgraph/svg2xml/XmlStyle.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ public void setStrokeWidth(String strokeWidth)
109109
{
110110
if(strokeWidth != null)
111111
{
112+
strokeWidth = strokeWidth.replaceAll("mm", "");
113+
strokeWidth = strokeWidth.replaceAll("pc", "");
114+
strokeWidth = strokeWidth.replaceAll("pt", "");
115+
strokeWidth = strokeWidth.replaceAll("in", "");
116+
strokeWidth = strokeWidth.replaceAll("cm", "");
117+
strokeWidth = strokeWidth.replaceAll("px", "");
118+
strokeWidth = strokeWidth.replaceAll("%", "");
119+
strokeWidth = strokeWidth.replaceAll("\\s","");
112120
this.strokeWidth = strokeWidth;
113121
}
114122
}

0 commit comments

Comments
 (0)