Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
JFreeSVG script and onload patch
diff -Nru jfreesvg-2.1.orig/src/main/java/org/jfree/graphics2d/svg/SVGGraphics2D.java jfreesvg-2.1/src/main/java/org/jfree/graphics2d/svg/SVGGraphics2D.java
--- jfreesvg-2.1.orig/src/main/java/org/jfree/graphics2d/svg/SVGGraphics2D.java 2014-08-04 09:03:06.000000000 -0400
+++ jfreesvg-2.1/src/main/java/org/jfree/graphics2d/svg/SVGGraphics2D.java 2014-12-09 10:55:02.000000000 -0500
@@ -2473,7 +2473,40 @@
* @return The SVG element.
*/
public String getSVGElement() {
- return getSVGElement(null);
+ return getSVGElement(null, null, null);
+ }
+
+ /**
+ * Returns the SVG element that has been generated by calls to this
+ * {@code Graphics2D} implementation, giving it the specified {@code id}.
+ * If {@code id} is {@code null}, the element will have no {@code id}
+ * attribute.
+ *
+ * @param id the element id ({@code null} permitted).
+ *
+ * @return A string containing the SVG element.
+ *
+ * @since 1.8
+ */
+ public String getSVGElement(String id) {
+ return getSVGElement(id, null, null);
+ }
+
+ /**
+ * Returns the SVG element that has been generated by calls to this
+ * {@code Graphics2D} implementation, giving it the specified {@code id}.
+ * If {@code id} is {@code null}, the element will have no {@code id}
+ * attribute.
+ *
+ * @param id the element id ({@code null} permitted).
+ * @param script the script to to add to the element ({@code null} permitted).
+ *
+ * @return A string containing the SVG element.
+ *
+ * @since 2.2
+ */
+ public String getSVGElement(String id, String script) {
+ return getSVGElement(id, script, null);
}
/**
@@ -2483,16 +2516,21 @@
* attribute.
*
* @param id the element id ({@code null} permitted).
+ * @param script the script to to add to the element ({@code null} permitted).
+ * @param onload the onload function to call ({@code null} permitted).
*
* @return A string containing the SVG element.
*
- * @since 1.8
+ * @since 2.2
*/
- public String getSVGElement(String id) {
+ public String getSVGElement(String id, String script, String onload) {
StringBuilder svg = new StringBuilder("<svg ");
if (id != null) {
svg.append("id=\"").append(id).append("\" ");
}
+ if (onload != null) {
+ svg.append("onload=\"").append(onload).append("\" ");
+ }
svg.append("xmlns=\"http://www.w3.org/2000/svg\" ")
.append("xmlns:xlink=\"http://www.w3.org/1999/xlink\" ")
.append("xmlns:jfreesvg=\"http://www.jfree.org/jfreesvg/svg\" ")
@@ -2528,6 +2566,9 @@
defs.append("</defs>\n");
svg.append(defs);
svg.append(this.sb);
+ if (script != null) {
+ svg.append(script);
+ }
svg.append("</svg>");
return svg.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment