X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FSCLScenegraph.java;h=559469d4a21ce908aff65f9574355363a989d2f3;hb=85c927c26e991764ddebaf69daae8d598380475e;hp=4e4811c5a15fe066d6ecf645accbe8fc26a4ca93;hpb=34ee11ce2339ebdae4783e5765583a6ae13c2920;p=simantics%2Fplatform.git
diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java
index 4e4811c5a..559469d4a 100644
--- a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java
+++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java
@@ -51,6 +51,7 @@ import org.simantics.g2d.canvas.ICanvasContext;
import org.simantics.g2d.diagram.DiagramHints;
import org.simantics.g2d.diagram.IDiagram;
import org.simantics.g2d.diagram.handler.DataElementMap;
+import org.simantics.g2d.diagram.participant.ElementPainter.SelectionShapeNode;
import org.simantics.g2d.diagram.participant.Selection;
import org.simantics.g2d.element.IElement;
import org.simantics.g2d.scenegraph.ICanvasSceneGraphProvider;
@@ -68,6 +69,7 @@ import org.simantics.scenegraph.g2d.nodes.BackgroundNode;
import org.simantics.scenegraph.g2d.nodes.BoundsNode;
import org.simantics.scenegraph.g2d.nodes.ConnectionNode;
import org.simantics.scenegraph.g2d.nodes.DataNode;
+import org.simantics.scenegraph.g2d.nodes.LinkNode;
import org.simantics.scenegraph.g2d.nodes.NavigationNode;
import org.simantics.scenegraph.g2d.nodes.SVGNode;
import org.simantics.scenegraph.g2d.nodes.SelectionNode;
@@ -84,6 +86,7 @@ import org.slf4j.LoggerFactory;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class SCLScenegraph {
@@ -93,9 +96,16 @@ public class SCLScenegraph {
private static final String MAIN_SECTION = "main";
private static final String SELECTION_SECTION = "selection";
private static final String SELECTION_MASK_SECTION = "selectionMask";
-
+
private static final String[] ALL_SECTIONS = { MAIN_SECTION, SELECTION_SECTION, SELECTION_MASK_SECTION };
+ // Changed from 0.001 to 0.0001 to prevent creation of huge BufferedImage's when
+ // generating PDF from SVG. If SVG contains any transparency then Batik uses
+ // bitmap-rendering which remarkably slows things down
+ // See org.apache.batik.gvt.AbstractGraphicsNode.paint(Graphics2D) where decisions are made
+ // if AlphaComposite should be painted
+ private static final String OPACITY = "0.0001";
+
@Deprecated
public static ICanvasSceneGraphProvider getICanvasSceneGraphProvider(Resource model, Resource diagram, String diagramRVI) throws DatabaseException, InterruptedException {
ICanvasSceneGraphProvider provider = DiagramNodeUtil.loadSceneGraphProvider(model, diagram, diagramRVI);
@@ -666,22 +676,28 @@ public class SCLScenegraph {
// get the bounds of the content
Rectangle2D content = rtreeBounds;
- // To account for dynamic padding of selection rectangles (5 units + stroke width)
- int offset = 6;
- double scale = width < 0 || height < 0 ? 1.0 : Math.min((width - 2*offset) / content.getWidth(), (height - 2*offset) / content.getHeight());
-
- AffineTransform tr = new AffineTransform();
- tr.translate(offset, offset);
- tr.scale(scale, scale);
- tr.translate(-content.getX(), -content.getY());
- tr.getMatrix(matrix);
+ if (content != null) {
+ // To account for dynamic padding of selection rectangles (5 units + stroke width)
+ int offset = 6;
+
+ double scale = width < 0 || height < 0 ? 1.0 : Math.min((width - 2*offset) / content.getWidth(), (height - 2*offset) / content.getHeight());
+
+ AffineTransform tr = new AffineTransform();
+ tr.translate(offset, offset);
+ tr.scale(scale, scale);
+ tr.translate(-content.getX(), -content.getY());
+ tr.getMatrix(matrix);
+ svgGenerator.setSVGCanvasSize(new Dimension((int)Math.ceil(scale * content.getWidth()) + 2*offset, (int)Math.ceil(scale * content.getHeight()) + 2*offset));
+ } else {
+ svgGenerator.setSVGCanvasSize(new Dimension(100, 100));
+ }
//svgGenerator.translate(offset, offset);
//svgGenerator.scale(scale, scale);
// translate svgGenerator to the x and y coordinates of current content
//svgGenerator.translate(-content.getX(), -content.getY());
- svgGenerator.setSVGCanvasSize(new Dimension((int)Math.ceil(scale * content.getWidth()) + 2*offset, (int)Math.ceil(scale * content.getHeight()) + 2*offset));
+
//svgGenerator.setClip(content);
result.append(MAIN_SECTION, "");
@@ -707,7 +723,11 @@ public class SCLScenegraph {
result.append(ALL_SECTIONS, "");
StringBuilder res = new StringBuilder();
- res.append("