From 28a4e92f4bf7395eecc9e178f59bcc383876f6bf Mon Sep 17 00:00:00 2001 From: Michael Bangas Date: Tue, 5 Nov 2024 14:53:45 +0100 Subject: [PATCH 1/2] 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. --- .../jface/resource/URLImageDescriptor.java | 20 +++++++++++++++++++ features/org.eclipse.e4.rcp/feature.xml | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java index e00a363bfe0..a2dda6a18c4 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java @@ -139,6 +139,9 @@ public ImageData getImageData(int zoom) { private static ImageData getImageData(String url, int zoom) { URL tempURL = getURL(url); if (tempURL != null) { +// if (tempURL.toString().endsWith(".svg")) { //$NON-NLS-1$ +// return getImageData(tempURL, zoom); +// } if (zoom == 100) { return getImageData(tempURL); } @@ -177,6 +180,23 @@ private static ImageData getImageData(URL url) { return result; } +// private static ImageData getImageData(URL url, int zoom) { +// ImageData result = null; +// try (InputStream in = getStream(url)) { +// if (in != null) { +// result = new ImageData(in, zoom); +// } +// } catch (SWTException e) { +// if (e.code != SWT.ERROR_INVALID_IMAGE) { +// throw e; +// // fall through otherwise +// } +// } catch (IOException e) { +// Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, e.getLocalizedMessage(), e)); +// } +// return result; +// } + /** * Returns a stream on the image contents. Returns null if a stream could * not be opened. diff --git a/features/org.eclipse.e4.rcp/feature.xml b/features/org.eclipse.e4.rcp/feature.xml index a9c6104ed35..d9657478cde 100644 --- a/features/org.eclipse.e4.rcp/feature.xml +++ b/features/org.eclipse.e4.rcp/feature.xml @@ -294,6 +294,10 @@ arch="aarch64" version="0.0.0"/> + + From a1278e0d33db085bd07b22b18a9a4a7c6e2df583 Mon Sep 17 00:00:00 2001 From: Michael Bangas Date: Tue, 5 Nov 2024 14:53:45 +0100 Subject: [PATCH 2/2] disabled icon logic --- .../jface/resource/URLImageDescriptor.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java index a2dda6a18c4..eb2cce6b4bd 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java @@ -95,7 +95,23 @@ public URLImageDataProvider(String url) { public ImageData getImageData(int zoom) { return URLImageDescriptor.getImageData(url, zoom); } +// +// @Override +// public ImageData getCustomizedImageData(int zoom, int flag) { +// return URLImageDescriptor.getCustomizedImageData(url, zoom, flag); +// } +// @Override +// public boolean supportsRasterizationFlag(int flag) { +// boolean supportsFlag = flag == SWT.IMAGE_DISABLE || flag == SWT.IMAGE_GRAY || flag == SWT.IMAGE_COPY; +// URL tempURL = getURL(url); +// if (tempURL != null) { +// if (tempURL.toString().endsWith(".svg") && supportsFlag) { //$NON-NLS-1$ +// return true; +// } +// } +// return false; +// } } private static long cumulativeTime; @@ -180,11 +196,11 @@ private static ImageData getImageData(URL url) { return result; } -// private static ImageData getImageData(URL url, int zoom) { +// private static ImageData getImageData(URL url, int zoom, int flag) { // ImageData result = null; // try (InputStream in = getStream(url)) { // if (in != null) { -// result = new ImageData(in, zoom); +// result = new ImageData(in, zoom, flag); // } // } catch (SWTException e) { // if (e.code != SWT.ERROR_INVALID_IMAGE) { @@ -195,6 +211,11 @@ private static ImageData getImageData(URL url) { // Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, e.getLocalizedMessage(), e)); // } // return result; +// } +// +// private static ImageData getCustomizedImageData(String url, int zoom, int flag) { +// URL tempURL = getURL(url); +// return getImageData(tempURL, zoom, flag); // } /**