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;
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();
}
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)) {