summaryrefslogtreecommitdiff
path: root/src/net/sourceforge/plantuml/svg
diff options
context:
space:
mode:
authorAndrej Shadura <andrew.shadura@collabora.co.uk>2020-03-10 16:38:20 +0100
committerAndrej Shadura <andrew.shadura@collabora.co.uk>2020-03-10 16:38:20 +0100
commit7cc8c823de644a510fcc434f39b53e5fffe66bfd (patch)
tree8f4d027284bb366734f610040c621a0c5dd0a12a /src/net/sourceforge/plantuml/svg
parent567b200b91537405689ae0ca944f121201360a6b (diff)
New upstream version 1.2020.2
Diffstat (limited to 'src/net/sourceforge/plantuml/svg')
-rw-r--r--src/net/sourceforge/plantuml/svg/SvgData.java2
-rw-r--r--src/net/sourceforge/plantuml/svg/SvgGraphics.java78
2 files changed, 52 insertions, 28 deletions
diff --git a/src/net/sourceforge/plantuml/svg/SvgData.java b/src/net/sourceforge/plantuml/svg/SvgData.java
index ecc80c8..6f16019 100644
--- a/src/net/sourceforge/plantuml/svg/SvgData.java
+++ b/src/net/sourceforge/plantuml/svg/SvgData.java
@@ -2,7 +2,7 @@
* PlantUML : a free UML diagram generator
* ========================================================================
*
- * (C) Copyright 2009-2017, Arnaud Roques
+ * (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
diff --git a/src/net/sourceforge/plantuml/svg/SvgGraphics.java b/src/net/sourceforge/plantuml/svg/SvgGraphics.java
index 0d76a2a..3ff140f 100644
--- a/src/net/sourceforge/plantuml/svg/SvgGraphics.java
+++ b/src/net/sourceforge/plantuml/svg/SvgGraphics.java
@@ -2,7 +2,7 @@
* PlantUML : a free UML diagram generator
* ========================================================================
*
- * (C) Copyright 2009-2017, Arnaud Roques
+ * (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
@@ -59,11 +59,12 @@ import javax.xml.transform.stream.StreamResult;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.OptionFlags;
+import net.sourceforge.plantuml.SignatureUtils;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.SvgString;
import net.sourceforge.plantuml.code.Base64Coder;
-import net.sourceforge.plantuml.eps.EpsGraphics;
import net.sourceforge.plantuml.graphic.HtmlColorGradient;
+import net.sourceforge.plantuml.tikz.TikzGraphics;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
import net.sourceforge.plantuml.ugraphic.UPath;
import net.sourceforge.plantuml.ugraphic.USegment;
@@ -89,6 +90,11 @@ public class SvgGraphics {
// http://www.w3schools.com/svg/svg_feoffset.asp
// http://www.adobe.com/svg/demos/samples.html
+ private static final String XLINK_TITLE1 = "title";
+ private static final String XLINK_TITLE2 = "xlink:title";
+ private static final String XLINK_HREF1 = "href";
+ private static final String XLINK_HREF2 = "xlink:href";
+
final private Document document;
final private Element root;
final private Element defs;
@@ -103,6 +109,8 @@ public class SvgGraphics {
private int maxX = 10;
private int maxY = 10;
+ private final String preserveAspectRatio;
+
private final double scale;
private final String filterUid;
private final String shadowId;
@@ -118,17 +126,19 @@ public class SvgGraphics {
}
}
- public SvgGraphics(boolean svgDimensionStyle, Dimension2D minDim, double scale, String hover, long seed) {
- this(svgDimensionStyle, minDim, null, scale, hover, seed);
+ public SvgGraphics(boolean svgDimensionStyle, Dimension2D minDim, double scale, String hover, long seed,
+ String preserveAspectRatio) {
+ this(svgDimensionStyle, minDim, null, scale, hover, seed, preserveAspectRatio);
}
public SvgGraphics(boolean svgDimensionStyle, Dimension2D minDim, String backcolor, double scale, String hover,
- long seed) {
+ long seed, String preserveAspectRatio) {
try {
this.svgDimensionStyle = svgDimensionStyle;
this.scale = scale;
this.document = getDocument();
this.backcolor = backcolor;
+ this.preserveAspectRatio = preserveAspectRatio;
ensureVisible(minDim.getWidth(), minDim.getHeight());
this.root = getRootNode();
@@ -326,15 +336,18 @@ public class SvgGraphics {
pendingAction.add(0, (Element) document.createElement("a"));
pendingAction.get(0).setAttribute("target", target);
- pendingAction.get(0).setAttribute("xlink:href", url);
+ pendingAction.get(0).setAttribute(XLINK_HREF1, url);
+ pendingAction.get(0).setAttribute(XLINK_HREF2, url);
pendingAction.get(0).setAttribute("xlink:type", "simple");
pendingAction.get(0).setAttribute("xlink:actuate", "onRequest");
pendingAction.get(0).setAttribute("xlink:show", "new");
if (title == null) {
- pendingAction.get(0).setAttribute("xlink:title", url);
+ pendingAction.get(0).setAttribute(XLINK_TITLE1, url);
+ pendingAction.get(0).setAttribute(XLINK_TITLE2, url);
} else {
title = title.replaceAll("\\\\n", "\n");
- pendingAction.get(0).setAttribute("xlink:title", title);
+ pendingAction.get(0).setAttribute(XLINK_TITLE1, title);
+ pendingAction.get(0).setAttribute(XLINK_TITLE2, title);
}
}
@@ -408,6 +421,7 @@ public class SvgGraphics {
}
public void svgPolygon(double deltaShadow, double... points) {
+ assert points.length % 2 == 0;
manageShadow(deltaShadow);
if (hidden == false) {
final Element elt = (Element) document.createElement("polygon");
@@ -475,16 +489,17 @@ public class SvgGraphics {
elt.setTextContent(text);
getG().appendChild(elt);
- if (textDecoration != null && textDecoration.contains("underline")) {
- final double delta = 2;
- final Element elt2 = (Element) document.createElement("line");
- elt2.setAttribute("x1", format(x));
- elt2.setAttribute("y1", format(y + delta));
- elt2.setAttribute("x2", format(x + textLength));
- elt2.setAttribute("y2", format(y + delta));
- elt2.setAttribute("style", getStyleInternal(fill, "1.0", null));
- getG().appendChild(elt2);
- }
+ // http://forum.plantuml.net/9158/hyperlink-without-underline
+ // if (textDecoration != null && textDecoration.contains("underline")) {
+ // final double delta = 2;
+ // final Element elt2 = (Element) document.createElement("line");
+ // elt2.setAttribute("x1", format(x));
+ // elt2.setAttribute("y1", format(y + delta));
+ // elt2.setAttribute("x2", format(x + textLength));
+ // elt2.setAttribute("y2", format(y + delta));
+ // elt2.setAttribute("style", getStyleInternal(fill, "1.0", null));
+ // getG().appendChild(elt2);
+ // }
}
ensureVisible(x, y);
@@ -523,13 +538,13 @@ public class SvgGraphics {
private Transformer getTransformer() throws TransformerException {
// Get a TransformerFactory object.
TransformerFactory xformFactory = null;
- try {
- final Class<?> factoryClass = Class
- .forName("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
- xformFactory = (TransformerFactory) factoryClass.newInstance();
- } catch (Exception e) {
+// try {
+// final Class<?> factoryClass = Class
+// .forName("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
+// xformFactory = (TransformerFactory) factoryClass.newInstance();
+// } catch (Exception e) {
xformFactory = TransformerFactory.newInstance();
- }
+// }
Log.info("TransformerFactory=" + xformFactory.getClass());
// Get an XSL Transformer object.
@@ -583,7 +598,7 @@ public class SvgGraphics {
}
root.setAttribute("viewBox", "0 0 " + maxXscaled + " " + maxYscaled);
root.setAttribute("zoomAndPan", "magnify");
- root.setAttribute("preserveAspectRatio", "none");
+ root.setAttribute("preserveAspectRatio", preserveAspectRatio);
root.setAttribute("contentScriptType", "application/ecmascript");
root.setAttribute("contentStyleType", "text/css");
@@ -633,7 +648,7 @@ public class SvgGraphics {
} else if (type == USegmentType.SEG_CLOSE) {
// Nothing
} else {
- Log.println("unknown " + seg);
+ Log.println("unknown3 " + seg);
}
}
@@ -695,7 +710,7 @@ public class SvgGraphics {
}
private String format(double x) {
- return EpsGraphics.format(x * scale);
+ return TikzGraphics.format(x * scale);
}
private String formatBoolean(double x) {
@@ -789,6 +804,7 @@ public class SvgGraphics {
}
private void addFilter(Element filter, String name, String... data) {
+ assert data.length % 2 == 0;
final Element elt = (Element) document.createElement(name);
for (int i = 0; i < data.length; i += 2) {
elt.setAttribute(data[i], data[i + 1]);
@@ -802,7 +818,15 @@ public class SvgGraphics {
this.hidden = hidden;
}
+ public static final String MD5_HEADER = "<!--MD5=[";
+
+ public static String getMD5Hex(String comment) {
+ return SignatureUtils.getMD5Hex(comment);
+ }
+
public void addComment(String comment) {
+ final String signature = getMD5Hex(comment);
+ comment = "MD5=[" + signature + "]\n" + comment;
final Comment commentElement = document.createComment(comment);
getG().appendChild(commentElement);
}