Skip to content
Snippets Groups Projects
Commit 4b8564a5 authored by Stepan Sindelar's avatar Stepan Sindelar
Browse files

[GR-2798] Fix: append </svg> when generating SVG string.

parents 846d1da7 4ca5be55
Branches
No related tags found
No related merge requests found
...@@ -53,7 +53,8 @@ public class SVGDevice implements GridDevice { ...@@ -53,7 +53,8 @@ public class SVGDevice implements GridDevice {
this.height = height; this.height = height;
} }
public String getContents() { public String closeAndGetContents() {
closeSVGDocument();
return data.toString(); return data.toString();
} }
...@@ -73,11 +74,7 @@ public class SVGDevice implements GridDevice { ...@@ -73,11 +74,7 @@ public class SVGDevice implements GridDevice {
@Override @Override
public void close() throws DeviceCloseException { public void close() throws DeviceCloseException {
if (cachedCtx != null) { closeSVGDocument();
// see #appendStyle
append("</g>");
}
append("</svg>");
try { try {
Files.write(Paths.get(filename), Collections.singleton(data.toString()), StandardCharsets.UTF_8); Files.write(Paths.get(filename), Collections.singleton(data.toString()), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException e) {
...@@ -176,6 +173,14 @@ public class SVGDevice implements GridDevice { ...@@ -176,6 +173,14 @@ public class SVGDevice implements GridDevice {
data.append("' ").append(attributes).append(" />"); data.append("' ").append(attributes).append(" />");
} }
private void closeSVGDocument() {
if (cachedCtx != null) {
// see #appendStyle
append("</g>");
}
append("</svg>");
}
private void appendStyle(DrawingContext ctx) { private void appendStyle(DrawingContext ctx) {
if (cachedCtx == null || !DrawingContext.areSame(cachedCtx, ctx)) { if (cachedCtx == null || !DrawingContext.areSame(cachedCtx, ctx)) {
if (cachedCtx != null) { if (cachedCtx != null) {
......
...@@ -70,7 +70,7 @@ public abstract class DevOff extends RExternalBuiltinNode.Arg1 { ...@@ -70,7 +70,7 @@ public abstract class DevOff extends RExternalBuiltinNode.Arg1 {
GridDevice dev = ctx.getDevice(which); GridDevice dev = ctx.getDevice(which);
ctx.removeDevice(which); ctx.removeDevice(which);
if ((dev instanceof SVGDevice)) { if ((dev instanceof SVGDevice)) {
return ((SVGDevice) dev).getContents(); return ((SVGDevice) dev).closeAndGetContents();
} else { } else {
warning(Message.GENERIC, "The device was not SVG device."); warning(Message.GENERIC, "The device was not SVG device.");
return ""; return "";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment