Package org.jfree.svg

Class SVGUtils


  • public class SVGUtils
    extends java.lang.Object
    Utility methods related to the SVGGraphics2D implementation.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SVGUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.function.DoubleFunction<java.lang.String> createDoubleConverter​(int dp)
      Returns a double-to-string function that limits the output to a specific number of decimal places (in the range 1 to 10).
      static java.lang.String doubleToString​(double d)
      Returns a string representing the specified double value.
      static java.lang.String escapeForXML​(java.lang.String source)
      Returns a new string where any special characters in the source string have been encoded.
      static void writeToHTML​(java.io.File file, java.lang.String title, java.lang.String svgElement)
      Writes an HTML file containing an SVG element.
      static void writeToSVG​(java.io.File file, java.lang.String svgElement)
      Writes a file containing the SVG element.
      static void writeToSVG​(java.io.File file, java.lang.String svgElement, boolean zip)
      Writes a file containing the SVG element.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SVGUtils

        private SVGUtils()
    • Method Detail

      • escapeForXML

        public static java.lang.String escapeForXML​(java.lang.String source)
        Returns a new string where any special characters in the source string have been encoded.
        Parameters:
        source - the source string (null not permitted).
        Returns:
        A new string with special characters escaped for XML.
        Since:
        1.5
      • writeToSVG

        public static void writeToSVG​(java.io.File file,
                                      java.lang.String svgElement)
                               throws java.io.IOException
        Writes a file containing the SVG element.
        Parameters:
        file - the file (null not permitted).
        svgElement - the SVG element (null not permitted).
        Throws:
        java.io.IOException - if there is an I/O problem.
        Since:
        1.2
      • writeToSVG

        public static void writeToSVG​(java.io.File file,
                                      java.lang.String svgElement,
                                      boolean zip)
                               throws java.io.IOException
        Writes a file containing the SVG element.
        Parameters:
        file - the file (null not permitted).
        svgElement - the SVG element (null not permitted).
        zip - compress the output.
        Throws:
        java.io.IOException - if there is an I/O problem.
        Since:
        3.0
      • writeToHTML

        public static void writeToHTML​(java.io.File file,
                                       java.lang.String title,
                                       java.lang.String svgElement)
                                throws java.io.IOException
        Writes an HTML file containing an SVG element.
        Parameters:
        file - the file.
        title - the title.
        svgElement - the SVG element.
        Throws:
        java.io.IOException - if there is an I/O problem.
      • doubleToString

        public static java.lang.String doubleToString​(double d)
        Returns a string representing the specified double value. Internally this method is using the code from: https://github.com/ulfjack/ryu which is optimised for speed.
        Parameters:
        d - the value.
        Returns:
        A string representation of the double.
        Since:
        5.0
      • createDoubleConverter

        public static java.util.function.DoubleFunction<java.lang.String> createDoubleConverter​(int dp)
        Returns a double-to-string function that limits the output to a specific number of decimal places (in the range 1 to 10).
        Parameters:
        dp - the decimal places (required in the range 1 to 10).
        Returns:
        The converter.
        Since:
        5.0