-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Since the Eclipse 2025-06 (4.36) SWT supports rendering of SVGs.
https://eclipse.dev/eclipse/markdown/?f=news/4.36/platform.md
To use SVGs in your runtime, you need to add the new fragment org.eclipse.swt.svg and its dependency com.github.weisj.jsvg.
The NatTable GUIHelper needs to be extended to support the .svg file ending. And for SVG files, the resolution suffixes are not needed, as the scaling can be done directly on the SVG. There is no need for differently scaled images then.
It should be possible to introduce that change without updated dependencies. In case SVG support is not available in the JFace and SWT versions in the runtime, ImageDescriptor#getImageData() should return null, as the image data could not be created. In that case a fallback needs to be added, so that the existing PNG files are used.
Unfortunately the SVG support is not very fail safe. There are various errors that happen for different issues in the runtime.
- The fragment
org.eclipse.swt.svgis missing in the runtimeorg.eclipse.swt.SWTException: Unsupported or unrecognized format [No SVG rasterizer found] - The fragment
org.eclipse.swt.svgis available but the required dependencycom.github.weisj.jsvgis not available in the runtimeThis happens on determining thejava.util.ServiceConfigurationError: org.eclipse.swt.internal.image.SVGRasterizer: Provider org.eclipse.swt.svg.JSVGRasterizer could not be instantiatedFileFormatwhen theorg.eclipse.swt.internal.image.SVGFileFormatclass is loaded. - The fragment
org.eclipse.swt.svgis available but the required dependencycom.github.weisj.jsvgis not available in the correct versionorg.eclipse.swt.svg:3.130.0requirescom.github.weisj.jsvg:[1.7.0,2.0.0)org.eclipse.swt.svg:3.131.0requirescom.github.weisj.jsvg:[2.0.0,3.0.0)
If the combination does not match in the runtime, you will get the following errorjava.lang.NoSuchMethodError: 'com.github.weisj.jsvg.geometry.size.FloatSize com.github.weisj.jsvg.SVGDocument.size()'
From an OSGi perspective I am also missing the capability headers as described in OSGi Compendium - Service Loader Mediator, but maybe it is not necessary or useful in case of a fragment.
The above issues should only come up when setting up the runtime manually, e.g. if you create a plain SWT application or maybe a plain OSGi application using Bndtools. Although I haven't tested the later. But for plain SWT applications the above issues came up on testing.
You can of course argue that a developer that wants to load SVGs in the application needs to ensure that the runtime supports this, and the errors directly show the developer that something is missing. But as NatTable is a framework and developers might not really be aware of the SVG support, or do not even have it because they rely on an older Eclipse version, the SVG support needs to be guarded with a try {} catch (Error e) and a fallback to the default PNG/GIF images.
@HannesWell @HeikoKlare
I am not sure if you are aware of those issues and if this is a design by intention. I just wanted to note down my findings somewhere. From my perspective the above issues are a violation of the getImageData() contract, as it should return null in case the image data can not be loaded.