Skip to content

Commit 961aba1

Browse files
committed
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 1e3db4a commit 961aba1

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ protected boolean supportsZoomLevel(int zoom) {
450450
// Currently only support integer zoom levels, because getZoomedImageData(..)
451451
// suffers from Bug 97506: [HiDPI] ImageData.scaledTo() should use a
452452
// better interpolation method.
453-
return zoom > 0 && zoom % 100 == 0;
453+
return true;
454454
}
455455

456456
private ImageData getZoomedImageData(ImageDataProvider srcProvider) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public ImageData getImageData(int zoom) {
126126
InputStream in = getStream(zoom);
127127
if (in != null) {
128128
try (BufferedInputStream stream = new BufferedInputStream(in)) {
129-
return new ImageData(stream);
129+
return new ImageData(stream, zoom);
130130
} catch (SWTException e) {
131131
if (e.code != SWT.ERROR_INVALID_IMAGE) {
132132
throw e;

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public URLImageFileNameProvider(String url) {
5959
public String getImagePath(int zoom) {
6060
URL tempURL = getURL(url);
6161
if (tempURL != null) {
62+
if (tempURL.toString().endsWith(".svg")) { //$NON-NLS-1$
63+
return getFilePath(tempURL, false);
64+
}
6265
final boolean logIOException = zoom == 100;
6366
if (zoom == 100) {
6467
return getFilePath(tempURL, logIOException);
@@ -139,12 +142,15 @@ public ImageData getImageData(int zoom) {
139142
private static ImageData getImageData(String url, int zoom) {
140143
URL tempURL = getURL(url);
141144
if (tempURL != null) {
145+
if (tempURL.toString().endsWith(".svg")) { //$NON-NLS-1$
146+
return getImageData(tempURL, zoom);
147+
}
142148
if (zoom == 100) {
143-
return getImageData(tempURL);
149+
return getImageData(tempURL, zoom);
144150
}
145151
URL xUrl = getxURL(tempURL, zoom);
146152
if (xUrl != null) {
147-
ImageData xdata = getImageData(xUrl);
153+
ImageData xdata = getImageData(xUrl, zoom);
148154
if (xdata != null) {
149155
return xdata;
150156
}
@@ -153,18 +159,22 @@ private static ImageData getImageData(String url, int zoom) {
153159
if (xpath != null) {
154160
URL xPathUrl = getURL(xpath);
155161
if (xPathUrl != null) {
156-
return getImageData(xPathUrl);
162+
return getImageData(xPathUrl, zoom);
157163
}
158164
}
159165
}
160166
return null;
161167
}
162168

163169
private static ImageData getImageData(URL url) {
170+
return getImageData(url, 0);
171+
}
172+
173+
private static ImageData getImageData(URL url, int zoom) {
164174
ImageData result = null;
165175
try (InputStream in = getStream(url)) {
166176
if (in != null) {
167-
result = new ImageData(in);
177+
result = new ImageData(in, zoom);
168178
}
169179
} catch (SWTException e) {
170180
if (e.code != SWT.ERROR_INVALID_IMAGE) {

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchImages.java

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ private static final void declareImages() {
236236
declareImage(ISharedImages.IMG_DEF_VIEW, PATH_EVIEW + "defaultview_misc.png", true); //$NON-NLS-1$
237237

238238
declareImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW, PATH_ELOCALTOOL + "close_view.png", true); //$NON-NLS-1$
239+
declareImage(IWorkbenchGraphicConstants.IMG_LCL_PIN_VIEW, PATH_ELOCALTOOL + "pin_view.png", true); //$NON-NLS-1$
239240
declareImage(IWorkbenchGraphicConstants.IMG_LCL_MIN_VIEW, PATH_ELOCALTOOL + "min_view.png", true); //$NON-NLS-1$
240241
declareImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU, PATH_ELOCALTOOL + "view_menu.png", true); //$NON-NLS-1$
241242
declareImage(IWorkbenchGraphicConstants.IMG_LCL_BUTTON_MENU, PATH_ELOCALTOOL + "button_menu.png", true); //$NON-NLS-1$

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)