diff options
author | Andrej Shadura <andrewsh@debian.org> | 2018-08-05 11:30:34 +0200 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2018-08-05 11:30:34 +0200 |
commit | 293202087ef00accaa85af02c2c9359ab6b2513c (patch) | |
tree | bce49368c8052315c0d2c4fc5cc32d2305b69614 /src/net/sourceforge/plantuml/svg/SvgGraphics.java | |
parent | 277c886dbbaa9ac62798e87272c7ead5795033f8 (diff) |
New upstream version 1.2018.9
Diffstat (limited to 'src/net/sourceforge/plantuml/svg/SvgGraphics.java')
-rw-r--r-- | src/net/sourceforge/plantuml/svg/SvgGraphics.java | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/src/net/sourceforge/plantuml/svg/SvgGraphics.java b/src/net/sourceforge/plantuml/svg/SvgGraphics.java index b41e76f..6005be7 100644 --- a/src/net/sourceforge/plantuml/svg/SvgGraphics.java +++ b/src/net/sourceforge/plantuml/svg/SvgGraphics.java @@ -106,6 +106,7 @@ public class SvgGraphics { private final String filterUid; private final String shadowId; private final String gradientId; + private final boolean svgDimensionStyle; final protected void ensureVisible(double x, double y) { if (x > maxX) { @@ -116,12 +117,14 @@ public class SvgGraphics { } } - public SvgGraphics(Dimension2D minDim, double scale, String hover, long seed) { - this(minDim, null, scale, hover, seed); + public SvgGraphics(boolean svgDimensionStyle, Dimension2D minDim, double scale, String hover, long seed) { + this(svgDimensionStyle, minDim, null, scale, hover, seed); } - public SvgGraphics(Dimension2D minDim, String backcolor, double scale, String hover, long seed) { + public SvgGraphics(boolean svgDimensionStyle, Dimension2D minDim, String backcolor, double scale, String hover, + long seed) { try { + this.svgDimensionStyle = svgDimensionStyle; this.scale = scale; this.document = getDocument(); this.backcolor = backcolor; @@ -296,49 +299,54 @@ public class SvgGraphics { } public void closeLink() { - if (pendingLink2.size() > 0) { - final Element element = pendingLink2.get(0); - pendingLink2.remove(0); - getG().appendChild(element); + if (pendingAction.size() > 0) { + final Element element = pendingAction.get(0); + pendingAction.remove(0); + if (element.getFirstChild() != null) { + // Empty link + getG().appendChild(element); + } } } - private final List<Element> pendingLink2 = new ArrayList<Element>(); + private final List<Element> pendingAction = new ArrayList<Element>(); public void openLink(String url, String title, String target) { if (url == null) { throw new IllegalArgumentException(); } - if (pendingLink2.size() > 0) { + if (pendingAction.size() > 0) { closeLink(); } - pendingLink2.add(0, (Element) document.createElement("a")); - pendingLink2.get(0).setAttribute("target", target); - pendingLink2.get(0).setAttribute("xlink:href", url); - pendingLink2.get(0).setAttribute("xlink:type", "simple"); - pendingLink2.get(0).setAttribute("xlink:actuate", "onRequest"); - pendingLink2.get(0).setAttribute("xlink:show", "new"); + 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:type", "simple"); + pendingAction.get(0).setAttribute("xlink:actuate", "onRequest"); + pendingAction.get(0).setAttribute("xlink:show", "new"); if (title == null) { - pendingLink2.get(0).setAttribute("xlink:title", url); + pendingAction.get(0).setAttribute("xlink:title", url); } else { title = title.replaceAll("\\\\n", "\n"); - pendingLink2.get(0).setAttribute("xlink:title", title); + pendingAction.get(0).setAttribute("xlink:title", title); } } public final Element getG() { - if (pendingLink2.size() == 0) { + if (pendingAction.size() == 0) { return gRoot; } - return pendingLink2.get(0); + return pendingAction.get(0); } public void svgRectangle(double x, double y, double width, double height, double rx, double ry, double deltaShadow, String id) { if (height <= 0 || width <= 0) { - throw new IllegalArgumentException(); + return; + // To be restored when Teoz will be finished + // throw new IllegalArgumentException(); } manageShadow(deltaShadow); if (hidden == false) { @@ -564,9 +572,11 @@ public class SvgGraphics { if (backcolor != null) { style += "background:" + backcolor + ";"; } - root.setAttribute("style", style); - root.setAttribute("width", format(maxX) + "px"); - root.setAttribute("height", format(maxY) + "px"); + if (svgDimensionStyle) { + root.setAttribute("style", style); + root.setAttribute("width", format(maxX) + "px"); + root.setAttribute("height", format(maxY) + "px"); + } root.setAttribute("viewBox", "0 0 " + maxXscaled + " " + maxYscaled); root.setAttribute("zoomAndPan", "magnify"); root.setAttribute("preserveAspectRatio", "none"); @@ -611,8 +621,9 @@ public class SvgGraphics { ensureVisible(coord[2] + x + 2 * deltaShadow, coord[3] + y + 2 * deltaShadow); ensureVisible(coord[4] + x + 2 * deltaShadow, coord[5] + y + 2 * deltaShadow); } else if (type == USegmentType.SEG_ARCTO) { - sb.append("A" + format(coord[0]) + "," + format(coord[1]) + " " + format(coord[2]) + "," - + format(coord[3]) + " " + format(coord[4]) + "," + format(coord[5] + x) + "," + // A25,25 0,0 5,395,40 + sb.append("A" + format(coord[0]) + "," + format(coord[1]) + " " + formatBoolean(coord[2]) + " " + + formatBoolean(coord[3]) + " " + formatBoolean(coord[4]) + " " + format(coord[5] + x) + "," + format(coord[6] + y) + " "); ensureVisible(coord[5] + coord[0] + x + 2 * deltaShadow, coord[6] + coord[1] + y + 2 * deltaShadow); } else if (type == USegmentType.SEG_CLOSE) { @@ -683,6 +694,10 @@ public class SvgGraphics { return EpsGraphics.format(x * scale); } + private String formatBoolean(double x) { + return x == 0 ? "0" : "1"; + } + public void fill(int windingRule) { if (hidden == false) { final Element elt = (Element) document.createElement("path"); @@ -728,11 +743,11 @@ public class SvgGraphics { private String manageScale(SvgString svg) { final double svgScale = svg.getScale(); if (svgScale * scale == 1) { - return svg.getSvg(); + return svg.getSvg(false); } final String s1 = "\\<g\\b"; final String s2 = "<g transform=\"scale(" + format(svgScale) + "," + format(svgScale) + ")\" "; - return svg.getSvg().replaceFirst(s1, s2); + return svg.getSvg(false).replaceFirst(s1, s2); } private String toBase64(BufferedImage image) throws IOException { |