Java SVG renderer

Related tags

Spring Boot svg
Overview

Quality Gate Status Code Style CI Maven Central

JSVG - A Java SVG implementation

The SVG logo rendered by JSVG
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.

How to use

The library is available on maven central:

dependencies {
    implementation("com.github.weisj:jsvg:0.0.3")
}

Also nightly snapshot builds will be release to maven:

repositories {
    maven {
        url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
    }
}

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 which can be rendered to any Graphics2D object you like (e.g. a BufferedImage or a swing component).

Supported features

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.
  • (): 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.

Shape and container elements

Element Status
a
circle
clipPath
defs
ellipse
foreignObject
g
image
line
marker
mask
path
polygon
polyline
rect
svg
symbol
use
view ()

Paint server elements

Element Status
linearGradient
🧪 meshgradient
🧪 meshrow
🧪 meshpatch
pattern
radialGradient
solidColor
stop

Text elements

Element Status
text
textPath
⚠️ tref
tspan

Animation elements

Element Status
animate
⚠️ animateColor
animateMotion
animateTransform
mpath
set
switch

Filter elements

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 ☑️

Font elements

Element Status
⚠️ altGlyph
⚠️ altGlyphDef
⚠️ altGlyphItem
⚠️ font
⚠️ font-face
⚠️ font-face-format
⚠️ font-face-name
⚠️ font-face-src
⚠️ font-face-uri
⚠️ glyph
⚠️ glyphRef
⚠️ hkern
⚠️ missing-glyph
⚠️ vkern

Other elements

Element Status
desc ()
title ()
metadata ()
color-profile
⚠️ cursor
script
style
Comments
  • SVG Path renders incorrectly

    SVG Path renders incorrectly

    Jsvg renders the svg different than Firefox.

    The svg:

    <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M4.5 6.5V3.5C4.5 1.84315 5.84315 0.5 7.5 0.5C9.15685 0.5 10.5 1.84315 10.5 3.5V6.5M2.5 6.5H12.5C13.0523 6.5 13.5 6.94772 13.5 7.5V13.5C13.5 14.0523 13.0523 14.5 12.5 14.5H2.5C1.94772 14.5 1.5 14.0523 1.5 13.5V7.5C1.5 6.94772 1.94772 6.5 2.5 6.5Z" stroke="black"/>
    </svg>
    

    Comparison between correct (png version) and incorrect (svg version) rendered image: issue

    If wanted I can provide more samples of incorrectly rendered images.

    opened by narutoDev 2
  • ArrayIndexOutOfBoundsException when loading SVG

    ArrayIndexOutOfBoundsException when loading SVG

    When loading the attached SVG file I get the following stacktrace:
    Jan 30, 2022 10:32:56 AM com.github.weisj.jsvg.parser.SVGLoader load WARNING: Could not load SVG java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 at com.github.weisj.jsvg/com.github.weisj.jsvg.parser.AttributeNode.preprocessAttributes(AttributeNode.java:77) at com.github.weisj.jsvg/com.github.weisj.jsvg.parser.AttributeNode.<init>(AttributeNode.java:60) at com.github.weisj.jsvg/com.github.weisj.jsvg.parser.SVGLoader$SVGLoadHandler.startElement(SVGLoader.java:232) at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:518) at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374) at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2725) at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605) at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112) at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:541) at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888) at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824) at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224) at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635) at com.github.weisj.jsvg/com.github.weisj.jsvg.parser.SVGLoader.load(SVGLoader.java:136) at com.github.weisj.jsvg/com.github.weisj.jsvg.parser.SVGLoader.load(SVGLoader.java:124) at Encryption/crypttool.util.SVGIcon.<init>(SVGIcon.java:23) at Encryption/crypttool.gui.MainFrame.<clinit>(MainFrame.java:138) at Encryption/crypttool.Crypttool.main(Crypttool.java:41)

    The file gets displayed perfectly fine in my browser. I tried to load another SVG file, which worked. Is there an issue with my svg file, or is it a bug in your library? Any potential workarounds?
    The svg file causing the error: password

    opened by narutoDev 2
  • Text doesn't support textLength attribute

    Text doesn't support textLength attribute

    It is parsed but currently does nothing. https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/textLength

    It applies to text, tspan and textPath.

    enhancement 
    opened by weisJ 2
  • Implement <pattern>

    Implement

    Its the last of the paint primitives which need to be implemented. The best approach would probably be to use a TexturePaint for it. The only tricky thing is to figure out what resolution the texture image needs to be for it to have the same resolution as the target shape to be painted.

    enhancement 
    opened by weisJ 1
  • Check if font family is available

    Check if font family is available

    Currently the FontResolver assumes that any given font exists on the system. AWT will never fail if a font isn't available but instead silently fall back to the default font. We should check the queried font families to choose an available one instead.

    bug 
    opened by weisJ 0
  • Soft clipping for clip-path

    Soft clipping for clip-path

    Currently the clip-path establishes a new clip on the current graphics context, which doesn't support soft clipping on every platform. (It does on macOS with quartz rendering enabled). This isn't a desired behaviour as it makes clipped edges look very harsh compared to all other edges which are usually rendered using antialiasing.

    enhancement 
    opened by weisJ 0
  • Framework for implementing filters

    Framework for implementing filters

    We need an easy framework for implementing filters. By design filters necessitate rendering to an off-screen buffer. To avoid unnecessary buffer creation this should be coordinated with the mask (#3) implementation, which most likely also uses an off-screen buffer.

    Before tackling the ´´ effect it should be possible to implement and use some of the <fe[...]> filter primitives.

    enhancement 
    opened by weisJ 0
  • Overlapping masks show bleeding

    Overlapping masks show bleeding

    When overlapping elements have masks with edges laying directly over each other there may be some bleed through of the bottom element. This is probably due to some inaccurate coordinate calculations in the MaskedPaint implementation.

    bug enhancement 
    opened by weisJ 0
  • <textPath> doesn't support <tspan> x attribute

    doesn't support x attribute

    If specified one can declare the individual "x" location of a character along the text path. This is currently not supported as we can't easily move to an arbitrary position in the path.

    bug enhancement 
    opened by weisJ 1
  • Support for marker-knockout-left, marker-knockout-right

    Support for marker-knockout-left, marker-knockout-right

    These properties are still under heavy development, but we should still think about how to implement them regardless of how they are declared.

    https://www.w3.org/TR/svg-markers/#MarkerKnockout

    enhancement 
    opened by weisJ 0
  • Support basic-shape declarations for clip-path

    Support basic-shape declarations for clip-path

    The 'clip-path' attribute allows to define inline shapes using the grammar for <basic-shape>. We should support it: https://developer.mozilla.org/en-US/docs/Web/CSS/basic-shape

    This includes the optional geometryBox argument:

    geometry-box: An extra information to tell how a is applied to an element: fill-box indicates to use the object bounding box; stroke-box indicates to use the object bounding box extended with the stroke; view-box indicates to use the nearest SVG viewport as the reference box.

    enhancement 
    opened by weisJ 0
Owner
Jannis Weis
Student at the Karlsruhe Institute of Technology
Jannis Weis
"Some" Utilities you can use for your Java projects "freely"! Files are compiled with Java-8 and above, but mostly Java-11.

✨ Java-SomeUtils ?? "Some" Utilities you can use for your Java projects "freely"! *"Freely"* forcing you to include the license into your program. Fil

JumperBot_ 2 Jan 6, 2023
Java-Programs---For-Practice is one of the Java Programming Practice Series By Shaikh Minhaj ( minhaj-313 ). This Series will help you to level up your Programming Skills. This Java Programs are very much helpful for Beginners.

Java-Programs---For-Practice is one of the Java Programming Practice Series By Shaikh Minhaj ( minhaj-313 ). This Series will help you to level up your Programming Skills. This Java Programs are very much helpful for Beginners. If You Have any doubt or query you can ask me here or you can also ask me on My LinkedIn Profile

Shaikh Minhaj 3 Nov 8, 2022
(Java & React) Yazılım Geliştirici Yetiştirme Kampı Java kısmına ait yazılan kaynak kodlar ve ödev çalışmalarım.

JavaCamp Kamp sürecinde yazılan kaynak kodlar ve ödev çalışmalarım. Day 1 1)Intro Day 2 2)oopIntro 2.1)oopIntro ~ Homework Day 3 3)oopIntro2 3.1)inher

Melih Çelik 17 Jun 26, 2022
☁ Tencent Cloud IM Server SDK in Java | 腾讯云 IM 服务端 SDK Java 版

Tencent Cloud IM Server SDK in Java The Tencent Cloud IM Server SDK for Java enables Java developers to easily work with Tencent Cloud IM. Requirement

Doocs 64 Dec 23, 2022
Trust-java - Test Results Verification library for Java

TRUST - Test Results Verification library for Java The TRUST's primary goal is to provide the simple way of different test results verification. Gener

Serhii Shymkiv 2 Nov 19, 2017
Changelog-java-version - Eine Auflistung der Änderungen in Java aus Sicht eines Entwicklers.

Changelog Java Versions Eine Auflistung der Änderungen in Java aus Sicht eines Entwicklers. Inhaltsverzeichnis Zugehörige Präsentation Homepage des Au

Frank W. Rahn 1 Jan 4, 2022
Bank Statement Analyzer Application that currently runs in terminal with the commands: javac Application.java java Application [file-name].csv GUI coming soon...

Bank Statement Analyzer Application that currently runs in terminal with the commands: javac Application.java java Application [file-name].csv GUI coming soon...

Hayden Hanson 0 May 21, 2022
Library for converting from one Java class to a dissimilar Java class with similar names based on the Bean convention

Beanmapper Beanmapper is a Java library for mapping dissimilar Java classes with similar names. The use cases for Beanmapper are the following: mappin

null 26 Nov 15, 2022
Free and 100% open source Progressive Java Runtime for modern Java™ deployments supported by a leading OpenJDK contributor

BellSoft Liberica JDK is a build of OpenJDK that is tested and verified to be compliant with the Java SE specification using OpenJDK Technology Compat

null 195 Dec 22, 2022
ActiveJ is an alternative Java platform built from the ground up. ActiveJ redefines web, high load, and cloud programming in Java, featuring ultimate performance and scalability!

Introduction ActiveJ is a full-featured modern Java platform, created from the ground up as an alternative to Spring/Micronauts/Netty/Jetty. It is des

ActiveJ LLC 579 Jan 7, 2023
Short Java programs for practice (OCP) Oracle Certified Professional Java SE 11

OCP-study Short Java programs to practice for (OCP) Oracle Certified Professional Java SE 11 Exam Google document with notes: https://docs.google.com/

Sabina Matjašič 1 May 24, 2022
Professional Java Developer Career Starter: Java Foundations Course Exercise Solutions

java-foundations-solutions Professional Java Developer Career Starter: Java Foundations Course Exercise Solutions The solutions are generally to be fo

Neutrino Systems Inc 41 Dec 28, 2022
Team 5468's 2022 FRC robot code. This code is written in Java and is based off of WPILib's Java control system and utilizes a command based system

FRC 2022 Team 5468's 2022 FRC robot code. This code is written in Java and is based off of WPILib's Java control system and utilizes a command based s

null 4 Oct 4, 2022
ijrd - internal java runtime debugger (loads through java agents LOL)

ijrd ijrd - internal java runtime debugger (loads through java agents LOL) this actually requires brain to build and then setup little guide to setup

null 6 Jan 28, 2022
Java - Packet Analyzer Application based on Java, Networking and Swing UI

Network-Packet-Tracer-using-Java Java - Packet Analyzer / Sniffing System Application based on Java, Networking and Swing UI Java - Packet Analyzer Ap

Muhammad Asad 6 Feb 3, 2022
Java virtual machine made in Java by HoverCatz#0060

Obzcure Virtual Machine Java virtual machine made in Java THIS IS NOT PRODUCTION SAFE - WORK IN PROGRESS! Use at your own risk. Requires Java 17 (with

null 9 Oct 18, 2022
Create a Music Playlist Library -Core JAVA, JAVA Swing, AWT

Project Specifications Manage Everything about a basic Music Playlist Application in Java A Music Library for Listing, Replaying, Navigating between c

Muhammad Asad 7 Nov 8, 2022
This repository contains Java programs to become zero to hero in Java. Programs related to each and every concep are present from easy to intermidiate level.

Learn Java Programming In this repository you will find topic wise programs of java from basics to intermediate. This follows topic wise approach that

Sahil Batra 15 Oct 9, 2022
Alibaba Cloud Dedicated KMS Transfer SDK for Java can help Java developers to migrate from the KMS keys to the Dedicated KMS keys.

Alibaba Cloud Dedicated KMS Transfer SDK for Java Alibaba Cloud Dedicated KMS Transfer SDK for Java can help Java developers to migrate from the KMS k

Alibaba Cloud 3 May 12, 2022