The SVG logo rendered using JSVG
JSVG is an SVG user agent using AWT graphics. Its aim is to provide a small and fast implementation. This library is under active development and doesn't yet support all features of the SVG specification, some of which it decidedly won't support at all. This implementation only tries to be a static user agent meaning it won't support any scripting languages or interaction. Animations aren't currently implemented but are planned to be supported.
This library aims to be as lightweight as possible. Generally JSVG uses ~50% less memory than svgSalamander and ~98% less than Batik.
JSVG is used by the Jetbrains IDEA IDE suite for rendering their interface icons.
The library is available on maven central:
dependencies {
implementation("com.github.weisj:jsvg:1.0.0")
}
Also, nightly snapshot builds will be released to maven:
repositories {
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
}
// Optional:
configurations.all {
resolutionStrategy.cacheChangingModulesFor(0, "seconds")
}
dependencies {
implementation("com.github.weisj:jsvg:latest.integration")
}
To load an svg icon you can use
the SVGLoader
class. It will produce
an SVGDocument
SVGLoader loader = new SVGLoader();
URL svgUrl = MyClass.class.getResource("mySvgFile.svg");
SVGDocument svgDocument = loader.load(svgUrl);
Note that SVGLoader
is not guaranteed to be thread safe hence shouldn't be used across multiple threads.
An SVGDocument
can be rendered to any Graphics2D
object you like e.g. a BufferedImage
FloatSize size = svgDocument.size();
BufferedImage image = new BufferedImage((int) size.width,(int) size.height);
Graphics2D g = image.createGraphics();
svgDocument.render(null,g);
g.dispose();
or a swing component
class MyComponent extends JComponent {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
svgDocument.render(this, (Graphics2D) g, new ViewBox(0, 0, getWidth(), getHeight()));
}
}
For supported elements most of the attributes which apply to them are implemented.
- ✅: The element is supported. Note that this doesn't mean that every attribute is supported.
- (:white_check_mark:): The element is supported, but won't have any effect (e.g. it's currently not possible to query
the content of a
<desc>
element) - ☑️: The element is partially implemented and might not support most basic features of the element.
- ❌: The element is currently not supported
⚠️ : The element is deprecated in the spec and has a low priority of getting implemented.- 🧪: The element is an experimental part of the svg 2.* spec. It may not fully behave as expected.
Element | Status |
---|---|
a | ✅ |
circle | ✅ |
clipPath | ✅ |
defs | ✅ |
ellipse | ✅ |
foreignObject | ❌ |
g | ✅ |
image | ✅ |
line | ✅ |
marker | ✅ |
mask | ✅ |
path | ✅ |
polygon | ✅ |
polyline | ✅ |
rect | ✅ |
svg | ✅ |
symbol | ✅ |
use | ✅ |
view | (:white_check_mark:) |
Element | Status |
---|---|
linearGradient | ✅ |
🧪meshgradient | ✅ |
🧪meshrow | ✅ |
🧪meshpatch | ✅ |
pattern | ✅ |
radialGradient | ✅ |
solidColor | ✅ |
stop | ✅ |
Element | Status |
---|---|
text | ✅ |
textPath | ✅ |
❌ | |
tspan | ✅ |
Element | Status |
---|---|
animate | ❌ |
❌ | |
animateMotion | ❌ |
animateTransform | ❌ |
mpath | ❌ |
set | ❌ |
switch | ❌ |
Element | Status |
---|---|
feBlend | ✅ |
feColorMatrix | ✅ |
feComponentTransfer | ❌ |
feComposite | ✅ |
feConvolveMatrix | ❌ |
feDiffuseLighting | ✅ |
feDisplacementMap | ✅ |
feDistantLight | ❌ |
feFlood | ✅ |
feFuncA | ❌ |
feFuncB | ❌ |
feFuncG | ❌ |
feFuncR | ❌ |
feGaussianBlur | ✅ |
feImage | ❌ |
feMerge | ✅ |
feMergeNode | ✅ |
feMorphology | ❌ |
feOffset | ✅ |
fePointLight | ❌ |
feSpecularLighting | ❌ |
feSpotLight | ❌ |
feTile | ❌ |
feTurbulence | ✅ |
filter | ☑️ |
Element | Status |
---|---|
❌ | |
❌ | |
❌ | |
❌ | |
❌ | |
❌ | |
❌ | |
❌ | |
❌ | |
❌ | |
❌ | |
❌ | |
❌ | |
❌ |
Element | Status |
---|---|
desc | (:white_check_mark:) |
title | (:white_check_mark:) |
metadata | (:white_check_mark:) |
color-profile | ❌ |
❌ | |
script | ❌ |
style | ☑️ |