Skip to content
Snippets Groups Projects
Commit 4ca5be55 authored by stepan's avatar stepan
Browse files

Fix: append </svg> when generating SVG string

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