X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2Fnodes%2FSVGNode.java;h=ec85fd75c86e7893a8b7341bcfde6641e380d244;hp=2fc37b7d59ab6bc9179943ab80b60246118e08e3;hb=2e21c89c81d449bcc2301b3cf3cce4f2cd403a60;hpb=edbb4df64407826271ee6423451401684e9cd68c diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SVGNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SVGNode.java index 2fc37b7d5..ec85fd75c 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SVGNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SVGNode.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.WeakHashMap; import org.simantics.scenegraph.ExportableWidget.RasterOutputWidget; @@ -172,32 +173,55 @@ public class SVGNode extends G2DNode implements InitValueSupport, LoaderNode { diagramCache = null; } - // NOTE: hard-coded to assume all SVG data is encoded in UTF-8 - byte[] dataBytes = data.getBytes("UTF-8"); + + // Lets check for rootAssignment that contributes the whole SVG + SVGNodeAssignment rootAssignment = null; + if (!assignments.isEmpty()) { + for (SVGNodeAssignment ass : assignments) { + if (ass.attributeNameOrId.equals("$root")) { + rootAssignment = ass; + break; + } + } + } + byte[] dataBytes; + if (rootAssignment != null) { + dataBytes = rootAssignment.value.getBytes("UTF-8"); + } else { + // NOTE: hard-coded to assume all SVG data is encoded in UTF-8 + dataBytes = data.getBytes("UTF-8"); + } dataHash = digest(dataBytes, assignments); URI uri = univ.loadSVG(new ByteArrayInputStream(dataBytes), dataHash); diagramCache = univ.getDiagram(uri, false); if (diagramCache != null) { univ.incRefCount(diagramCache.getXMLBase()); - - if (diagramCache.getRoot() == null) { + SVGRoot root = diagramCache.getRoot(); + if (root == null) { univ.decRefCount(diagramCache.getXMLBase()); diagramCache = univ.getDiagram(univ.loadSVG(BROKEN_SVG_DATA), false); dataHash = "broken"; univ.incRefCount(diagramCache.getXMLBase()); bbox = (Rectangle2D) diagramCache.getRoot().getBoundingBox().clone(); } else { - bbox = diagramCache.getRoot().getBoundingBox(); + bbox = root.getBoundingBox(); if (bbox.isEmpty()) { - univ.decRefCount(diagramCache.getXMLBase()); - diagramCache = univ.getDiagram(univ.loadSVG(EMPTY_SVG_DATA), false); - dataHash = "empty"; - univ.incRefCount(diagramCache.getXMLBase()); - bbox = (Rectangle2D) diagramCache.getRoot().getBoundingBox().clone(); + // Lets check if this should be visible or not + Set presentationAttributes = root.getPresentationAttributes(); + if (!presentationAttributes.contains("display")) { + // TODO: fix this - How can one read values of attributes in SVG salamander??? + univ.decRefCount(diagramCache.getXMLBase()); + diagramCache = univ.getDiagram(univ.loadSVG(EMPTY_SVG_DATA), false); + dataHash = "empty"; + univ.incRefCount(diagramCache.getXMLBase()); + bbox = (Rectangle2D) root.getBoundingBox().clone(); + } else { + bbox = new Rectangle2D.Double(0, 0, 0, 0); + } } else { if (applyAssignments(diagramCache, assignments)) { - bbox = (Rectangle2D) diagramCache.getRoot().getBoundingBox().clone(); + bbox = (Rectangle2D) root.getBoundingBox().clone(); } else { bbox = (Rectangle2D) bbox.clone(); } @@ -227,6 +251,9 @@ public class SVGNode extends G2DNode implements InitValueSupport, LoaderNode { return false; boolean changed = false; for (SVGNodeAssignment ass : assignments) { +// System.err.println("assign: " + ass.elementId + " " + ass.attributeNameOrId + " " + ass.value); +// if("opacity".equals(ass.attributeNameOrId)) +// System.err.println("faaf"); SVGElement e = diagram.getElement(ass.elementId); if (e != null) { if ("$text".equals(ass.attributeNameOrId)) {