Skip to content

Commit 99e876d

Browse files
committed
Handles predefined font sizes like x-small, small, medium etc
1 parent 1f232f5 commit 99e876d

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

src/com/mxgraph/svg2xml/Svg2Xml.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,39 @@ else if(!styleDiff.get("fillcolor").equals("none"))
823823
if (!fontSizeStr.equals(""))
824824
{
825825
fontSizeStr = removeUnits(fontSizeStr);
826-
double fs = Double.parseDouble(fontSizeStr) * configDoc.getRelativeScalingRatio();
826+
double fs = 16;
827+
828+
if (isNumeric(fontSizeStr))
829+
{
830+
fs = Double.parseDouble(fontSizeStr) * configDoc.getRelativeScalingRatio();
831+
}
832+
else
833+
{
834+
switch (fontSizeStr)
835+
{
836+
case "xx-small":
837+
fs = 9;
838+
break;
839+
case "x-small":
840+
fs = 10;
841+
break;
842+
case "small":
843+
fs = 13;
844+
break;
845+
case "medium":
846+
fs = 16;
847+
break;
848+
case "large":
849+
fs = 18;
850+
break;
851+
case "x-large":
852+
fs = 24;
853+
break;
854+
case "xx-large":
855+
fs = 32;
856+
}
857+
858+
}
827859
el.setAttribute("size", Double.toString(fs));
828860
node.appendChild(el);
829861
}
@@ -2531,5 +2563,9 @@ private Document removeConnections(Document svgDoc)
25312563

25322564
return svgDoc;
25332565
}
2566+
2567+
public static boolean isNumeric(String str) {
2568+
return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal.
2569+
}
25342570
};
25352571

0 commit comments

Comments
 (0)