import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGeneratorContext;
import org.apache.batik.svggen.SVGGraphics2D;
+import org.apache.batik.svggen.SVGIDGenerator;
import org.simantics.Simantics;
import org.simantics.datatypes.literal.GUID;
import org.simantics.db.ReadGraph;
import org.simantics.diagram.elements.TextGridNode;
import org.simantics.diagram.elements.TextNode;
import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.diagram.ui.DiagramModelHints;
import org.simantics.g2d.canvas.Hints;
import org.simantics.g2d.canvas.ICanvasContext;
import org.simantics.g2d.diagram.DiagramHints;
return true;
}
+
+ static class UniqueIDGenerator extends SVGIDGenerator{
+
+ String overallId;
+ public UniqueIDGenerator(String overallId) {
+ super();
+ this.overallId = overallId;
+ }
+
+ @Override
+ public String generateID(String prefix) {
+ return super.generateID(overallId+prefix);
+ }
+
+ }
+
static class Generator extends SVGGraphics2D {
int elemLevel = 0;
}
public Generator(Document document) {
+ this(document,null);
+ }
+ public Generator(Document document, String id) {
super(document);
// prevent batik comment in each g-element
getGeneratorContext().setComment(null);
+ if (id != null)
+ getGeneratorContext().setIDGenerator(new UniqueIDGenerator(id));
}
@Override
}
+
+
private static String renderSVG0(double width, double height, ICanvasContext ctx, Function1<Set<?>, Map<?, ?>> mappingFunction) {
// Get a DOMImplementation.
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
- SVGGraphics2D svgGenerator = new Generator(document);
+ IDiagram d = ctx.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM);
+ Resource r = d.getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE);
+ SVGGraphics2D svgGenerator;
+ if (r != null)
+ svgGenerator = new Generator(document,r.toString());
+ else
+ svgGenerator = new Generator(document);
RenderSVGContext result = new RenderSVGContext();
if (selection != null) {
// This prevents workbench selection from being left over.
// Also prevents scene graph crap from being left on the screen.
- IDiagram d = ctx.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM);
- selection.setSelection(0, d.getElements());
+ selection.setSelection(0, d.getElements());
}
G2DSceneGraph sg = ctx.getSceneGraph();