org.simantics.graphfile.ontology,
org.apache.batik;bundle-version="1.12.0",
org.simantics.graph.compiler,
- org.simantics.browsing.ui;bundle-version="1.1.0"
+ org.simantics.browsing.ui;bundle-version="1.1.0",
+ org.apache.commons.lang;bundle-version="2.6.0"
Export-Package: org.simantics.modeling,
org.simantics.modeling.actions,
org.simantics.modeling.adapters,
result.append(ALL_SECTIONS, "</g>");
StringBuilder res = new StringBuilder();
- res.append("<svg width=\"100%\" height=\"100%\" stroke=\"black\">");
+ if (width > 0 && height > 0 ) {
+ res.append("<svg width=\"" + width +"px\" height=\""+height+"px\" stroke=\"black\" xmlns=\"http://www.w3.org/2000/svg\">");
+ } else {
+ res.append("<svg width=\"100%\" height=\"100%\" stroke=\"black\" xmlns=\"http://www.w3.org/2000/svg\">");
+ }
res.append("<g transform=\"matrix(").append(matrix[0]).append(",").append(matrix[1]).append(",").append(matrix[2]).append(",").append(matrix[3]).append(",").append(matrix[4]).append(",").append(matrix[5]).append(")\">");
res.append(result.get(MAIN_SECTION));
res.append(result.get(SELECTION_SECTION));
private String getKey(SingleElementNode node) {
String key;
if(node.getKey() != null) {
- if (mappings.containsKey(node.getKey()))
+ if (mappings.containsKey(node.getKey())) {
key = mappings.get(node.getKey()).toString();
- else
+ key = escape(key);
+ } else {
key = node.getKey().toString();
+ key = escape(key);
+ }
} else {
key = Long.toString(node.getId());
}
return key;
}
+
+ private String escape(String key) {
+ // Keys may contain '<' '>' characters, which causes errors in browser SVG handling.
+ return org.apache.commons.lang.StringEscapeUtils.escapeHtml(key);
+ }
+
+ private String removeElem(String xml, String elemStart) {
+ // FIXME: This is rather nasty and error prone way of removing elements from XML string.
+ // This only supports elements with /> end element tag. Elements ends with </elem name> are not supported!
+ int start = xml.indexOf("<"+elemStart);
+ if (start>=0) {
+ int end = xml.indexOf(">",start);
+ if (end >= 0) {
+ if (start > 0)
+ return xml.substring(0,start)+xml.substring(end+1);
+ else
+ return xml.substring(end+1);
+ }
+ }
+ return null;
+ }
@Override
public void enter(IG2DNode node) {
parentBuilder.append(MAIN_SECTION, "\n<g transform=\"" + m + "\">");
}
}
- parentBuilder.append(MAIN_SECTION, svg.getSVGText());
+ String svgContent = svg.getSVGText();
+ // SVGNode content may contain SVG/XML elements, which break browser compatibility
+ int start = svgContent.indexOf("<svg");
+ if (start >= 0)
+ svgContent = svgContent.substring(start);
+ else {
+ String s = removeElem(svgContent, "?xml");
+ if (s != null) {
+ svgContent = "<g>"+s+"</g>";
+ s = removeElem(svgContent, "!DOCTYPE");
+ if (s != null)
+ svgContent = s;
+ }
+ }
+ parentBuilder.append(MAIN_SECTION, svgContent);
if (!at.isIdentity()) {
parentBuilder.append(MAIN_SECTION, "\n</g>");
}