X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fsvg%2FCreateSVGElement.java;h=92dbe16a65e9b383c7a923d572d3f9bd6d26d92d;hb=e5c9ce2de1b970b17c3ffc1151d7c49743df6183;hp=994d417c99b815ba4c3deae54511777a84e8fc05;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/svg/CreateSVGElement.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/svg/CreateSVGElement.java index 994d417c9..92dbe16a6 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/svg/CreateSVGElement.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/svg/CreateSVGElement.java @@ -2,6 +2,7 @@ package org.simantics.modeling.svg; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import org.simantics.databoard.Bindings; import org.simantics.db.Resource; @@ -19,6 +20,10 @@ import org.simantics.utils.FileUtils; public class CreateSVGElement { public static void createSVGElement(WriteGraph g, Resource diagram, String suffix, byte[] data, double mposX, double mposY) throws DatabaseException { + createSVGElement(g, diagram, suffix, data, mposX, mposY); + } + + public static Resource createSVGElementR(WriteGraph g, Resource diagram, String suffix, byte[] data, double mposX, double mposY) throws DatabaseException { Layer0 L0 = Layer0.getInstance(g); DiagramResource DIA = DiagramResource.getInstance(g); @@ -31,7 +36,7 @@ public class CreateSVGElement { g.claimValue(transform, new double[] {1.0, 0.0, 0.0, 1.0, mposX, mposY}, Bindings.DOUBLE_ARRAY); element = GraphUtils.create(g, L0.InstanceOf, DIA.SVGElement, - G2D.HasSVGDocument, new String(data), + G2D.HasSVGDocument, new String(data, StandardCharsets.UTF_8), DIA.HasTransform, transform); AddElement.claimFreshElementName(g, diagram, element); } else if ("png".equals(suffix)) { @@ -50,19 +55,22 @@ public class CreateSVGElement { throw new DatabaseException("Unknown image format " + suffix); OrderedSetUtils.addFirst(g, diagram, element); g.claim(diagram, L0.ConsistsOf, element); - + return element; } - + public static void importSVGElement(WriteGraph graph, Resource diagram, File file, double posX, double posY) throws DatabaseException, IOException { - + importSVGElementR(graph, diagram, file, posX, posY); + } + + public static Resource importSVGElementR(WriteGraph graph, Resource diagram, File file, double posX, double posY) throws DatabaseException, IOException { final byte[] data = FileUtils.readFile(file); - createSVGElement(graph, diagram, suffix(file.getName()), data, posX, posY); + return createSVGElementR(graph, diagram, suffix(file.getName()), data, posX, posY); } - + private static String suffix(String fileName) { int len = fileName.length(); if(len < 3) return null; else return fileName.substring(len-3,len).toLowerCase(); } - + }