Top Description Constructors Methods
com.dlsc.gemsfx.util

public final Class SVGUtil

extends Object
Class Inheritance
Imports
com.github.weisj.jsvg.SVGDocument, com.github.weisj.jsvg.attributes.ViewBox, com.github.weisj.jsvg.geometry.size.FloatSize, com.github.weisj.jsvg.parser.SVGLoader, javafx.embed.swing.SwingFXUtils, javafx.scene.image.Image, java.awt.Graphics2D, .RenderingHints, java.awt.image.BufferedImage, java.io.File, .InputStream, java.net.MalformedURLException, .URI, .URISyntaxException, .URL

A utility class that provides methods for parsing SVG files and converting them to JavaFX Image objects.

This class provides methods for loading SVG documents from various sources, such as files, URLs, and input streams, and then rendering them to JavaFX Image objects.

Note for SVGUtil: Currently, due to the limitation that weisj can only render BufferedImage from SVG, SvgImageView does not support usage in native packaging scenarios.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static SVGDocument
private static SVGDocument
private static SVGDocument
public static Image

Returns:

an Image object representing the parsed SVG file.
parseSVGFromFile
(String
the file path of the SVG file.
svgFilePath
)

Parses an SVG file from a given file path.

public static Image

Returns:

an Image object representing the parsed SVG file.
parseSVGFromFile
(File
the File object representing the SVG file.
svgFile
)

Parses an SVG file from a given File object.

public static Image

Returns:

an Image object representing the parsed SVG file.
parseSVGFromFile
(File
the File object representing the SVG file.
svgFile
,
double
the preferred width of the Image.
prefWidth
,
double
the preferred height of the Image.
prefHeight
)

Parses an SVG file from a given File object with the specified width and height.

public static Image

Returns:

an Image object representing the parsed SVG file.
parseSVGFromUrl
(String
the URL string of the SVG file.
urlString
)

Parses an SVG file from a given URL string.

public static Image

Returns:

an Image object representing the parsed SVG file.
parseSVGFromUrl
(URL
the URL object of the SVG file.
url
)

Parses an SVG file from a given URL object.

public static Image

Returns:

an Image object representing the parsed SVG file.
parseSVGFromUrl
(URL
the URL object of the SVG file.
url
,
double
the preferred width of the Image.
prefWidth
,
double
the preferred height of the Image.
prefHeight
)

Parses an SVG file from a given URL object with the specified width and height.

private static BufferedImage
renderImage(SVGDocument svgDocument, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY)

public static Image

Returns:

an Image object representing the SVG file.
toImage
(InputStream
the InputStream of the SVG file.
is
,
double
the preferred width of the Image.
requestedWidth
,
double
the preferred height of the Image.
requestedHeight
,
double
the horizontal scale factor.
outputScaleX
,
double
the vertical scale factor.
outputScaleY
)

Converts an InputStream representing an SVG file to an Image object with the specified dimensions and scale factors.

public static Image

Returns:

an Image object representing the SVG file.
toImage
(URL
the URL of the SVG file.
url
,
double
the preferred width of the Image.
requestedWidth
,
double
the preferred height of the Image.
requestedHeight
,
double
the horizontal scale factor.
outputScaleX
,
double
the vertical scale factor.
outputScaleY
)

Converts a URL representing an SVG file to an Image object with the specified dimensions and scale factors.

public static Image

Returns:

an Image object representing the SVG file.
toImage
(String
the URL string of the SVG file.
urlStr
,
double
the preferred width of the Image.
requestedWidth
,
double
the preferred height of the Image.
requestedHeight
,
double
the horizontal scale factor.
outputScaleX
,
double
the vertical scale factor.
outputScaleY
)

Converts a URL string representing an SVG file to an Image object with the specified dimensions and scale factors.

public static Image
toImage(File svgFile, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY)

private static Image
toImage(SVGDocument svgDocument, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SVGUtilback to summary
private SVGUtil()

Method Detail

loadSVGDocumentback to summary
private static SVGDocument loadSVGDocument(File svgFile)
loadSVGDocumentback to summary
private static SVGDocument loadSVGDocument(URL url)
loadSVGDocumentback to summary
private static SVGDocument loadSVGDocument(InputStream is)
parseSVGFromFileback to summary
public static Image parseSVGFromFile(String svgFilePath)

Parses an SVG file from a given file path.

Parameters
svgFilePath:String

the file path of the SVG file.

Returns:Image

an Image object representing the parsed SVG file.

parseSVGFromFileback to summary
public static Image parseSVGFromFile(File svgFile)

Parses an SVG file from a given File object.

Parameters
svgFile:File

the File object representing the SVG file.

Returns:Image

an Image object representing the parsed SVG file.

parseSVGFromFileback to summary
public static Image parseSVGFromFile(File svgFile, double prefWidth, double prefHeight)

Parses an SVG file from a given File object with the specified width and height.

Parameters
svgFile:File

the File object representing the SVG file.

prefWidth:double

the preferred width of the Image.

prefHeight:double

the preferred height of the Image.

Returns:Image

an Image object representing the parsed SVG file.

parseSVGFromUrlback to summary
public static Image parseSVGFromUrl(String urlString)

Parses an SVG file from a given URL string.

Parameters
urlString:String

the URL string of the SVG file.

Returns:Image

an Image object representing the parsed SVG file.

parseSVGFromUrlback to summary
public static Image parseSVGFromUrl(URL url)

Parses an SVG file from a given URL object.

Parameters
url:URL

the URL object of the SVG file.

Returns:Image

an Image object representing the parsed SVG file.

parseSVGFromUrlback to summary
public static Image parseSVGFromUrl(URL url, double prefWidth, double prefHeight)

Parses an SVG file from a given URL object with the specified width and height.

Parameters
url:URL

the URL object of the SVG file.

prefWidth:double

the preferred width of the Image.

prefHeight:double

the preferred height of the Image.

Returns:Image

an Image object representing the parsed SVG file.

renderImageback to summary
private static BufferedImage renderImage(SVGDocument svgDocument, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY)
toImageback to summary
public static Image toImage(InputStream is, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY)

Converts an InputStream representing an SVG file to an Image object with the specified dimensions and scale factors.

Parameters
is:InputStream

the InputStream of the SVG file.

requestedWidth:double

the preferred width of the Image.

requestedHeight:double

the preferred height of the Image.

outputScaleX:double

the horizontal scale factor.

outputScaleY:double

the vertical scale factor.

Returns:Image

an Image object representing the SVG file.

toImageback to summary
public static Image toImage(URL url, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY)

Converts a URL representing an SVG file to an Image object with the specified dimensions and scale factors.

Parameters
url:URL

the URL of the SVG file.

requestedWidth:double

the preferred width of the Image.

requestedHeight:double

the preferred height of the Image.

outputScaleX:double

the horizontal scale factor.

outputScaleY:double

the vertical scale factor.

Returns:Image

an Image object representing the SVG file.

toImageback to summary
public static Image toImage(String urlStr, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY)

Converts a URL string representing an SVG file to an Image object with the specified dimensions and scale factors.

Parameters
urlStr:String

the URL string of the SVG file.

requestedWidth:double

the preferred width of the Image.

requestedHeight:double

the preferred height of the Image.

outputScaleX:double

the horizontal scale factor.

outputScaleY:double

the vertical scale factor.

Returns:Image

an Image object representing the SVG file.

toImageback to summary
public static Image toImage(File svgFile, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY)
toImageback to summary
private static Image toImage(SVGDocument svgDocument, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY)