Skip to content

Commit 503cfd2

Browse files
Michael5601HannesWell
authored andcommitted
Introduce SVG Rasterization for Icons
Feature Proposal: Rasterization of SVGs at Runtime for Eclipse Icons Fixes #1438 Eclipse currently loads icons exclusively as raster graphics (e.g., `.png`), without support for vector formats like `.svg`. A major drawback of raster graphics is their inability to scale without degrading image quality. Additionally, generating icons of different sizes requires manually rasterizing SVGs outside Eclipse, leading to unnecessary effort and many icon files. This PR introduces support for vector graphics in Eclipse, enabling SVGs to be used for icons. Existing PNG icons will continue to be loaded alongside SVGs, allowing the use of the new functionality without the need to replace all PNG files at once. --- - **How It Works**: - To use SVG icons, simply place the SVG file in the bundle and reference it in the `plugin.xml` and other necessary locations, as is done for PNGs. No additional configuration is required. - At runtime, Eclipse uses the library JSVG to rasterize the SVG into a raster image of the desired size, eliminating the need for scaling. My analysis shows that JSVG is the most suitable Java library for this purpose. - You need to write the flag `-Dswt.autoScale=quarter` into your `eclipse.ini` file or into the run arguments of a new configuration.
1 parent 586ef10 commit 503cfd2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java

+20
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ public ImageData getImageData(int zoom) {
139139
private static ImageData getImageData(String url, int zoom) {
140140
URL tempURL = getURL(url);
141141
if (tempURL != null) {
142+
// if (tempURL.toString().endsWith(".svg")) { //$NON-NLS-1$
143+
// return getImageData(tempURL, zoom);
144+
// }
142145
if (zoom == 100) {
143146
return getImageData(tempURL);
144147
}
@@ -177,6 +180,23 @@ private static ImageData getImageData(URL url) {
177180
return result;
178181
}
179182

183+
// private static ImageData getImageData(URL url, int zoom) {
184+
// ImageData result = null;
185+
// try (InputStream in = getStream(url)) {
186+
// if (in != null) {
187+
// result = new ImageData(in, zoom);
188+
// }
189+
// } catch (SWTException e) {
190+
// if (e.code != SWT.ERROR_INVALID_IMAGE) {
191+
// throw e;
192+
// // fall through otherwise
193+
// }
194+
// } catch (IOException e) {
195+
// Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, e.getLocalizedMessage(), e));
196+
// }
197+
// return result;
198+
// }
199+
180200
/**
181201
* Returns a stream on the image contents. Returns null if a stream could
182202
* not be opened.

features/org.eclipse.e4.rcp/feature.xml

+4
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@
294294
arch="aarch64"
295295
version="0.0.0"/>
296296

297+
<plugin
298+
id="org.eclipse.swt.svg"
299+
version="0.0.0"/>
300+
297301
<plugin
298302
id="org.eclipse.jface"
299303
version="0.0.0"/>

0 commit comments

Comments
 (0)