Skip to content

Commit 3e77046

Browse files
committed
Logic for SVG rasterization
1 parent 98ff2aa commit 3e77046

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@
3535
import org.eclipse.swt.SWT;
3636
import org.eclipse.swt.SWTException;
3737
import org.eclipse.swt.graphics.Device;
38+
import org.eclipse.swt.graphics.ISVGRasterizer;
3839
import org.eclipse.swt.graphics.Image;
3940
import org.eclipse.swt.graphics.ImageData;
4041
import org.eclipse.swt.graphics.ImageDataProvider;
4142
import org.eclipse.swt.graphics.ImageFileNameProvider;
43+
import org.eclipse.swt.graphics.SVGRasterizerRegistry;
44+
import org.eclipse.swt.graphics.SVGUtil;
4245

4346
/**
4447
* An ImageDescriptor that gets its information from a URL. This class is not
@@ -59,6 +62,16 @@ public URLImageFileNameProvider(String url) {
5962
public String getImagePath(int zoom) {
6063
URL tempURL = getURL(url);
6164
if (tempURL != null) {
65+
ISVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
66+
if (rasterizer != null) {
67+
try (InputStream in = getStream(tempURL)) {
68+
if (SVGUtil.isSVGFile(in)) {
69+
return getFilePath(tempURL, false);
70+
}
71+
} catch (IOException e) {
72+
// ignore.
73+
}
74+
}
6275
final boolean logIOException = zoom == 100;
6376
if (zoom == 100) {
6477
return getFilePath(tempURL, logIOException);
@@ -139,12 +152,24 @@ public ImageData getImageData(int zoom) {
139152
private static ImageData getImageData(String url, int zoom) {
140153
URL tempURL = getURL(url);
141154
if (tempURL != null) {
155+
ISVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
156+
if (rasterizer != null) {
157+
try {
158+
try (InputStream in = getStream(tempURL)) {
159+
if (SVGUtil.isSVGFile(in)) {
160+
return getImageData(tempURL, zoom);
161+
}
162+
}
163+
} catch (IOException e) {
164+
// ignore.
165+
}
166+
}
142167
if (zoom == 100) {
143-
return getImageData(tempURL);
168+
return getImageData(tempURL, zoom);
144169
}
145170
URL xUrl = getxURL(tempURL, zoom);
146171
if (xUrl != null) {
147-
ImageData xdata = getImageData(xUrl);
172+
ImageData xdata = getImageData(xUrl, zoom);
148173
if (xdata != null) {
149174
return xdata;
150175
}
@@ -153,18 +178,22 @@ private static ImageData getImageData(String url, int zoom) {
153178
if (xpath != null) {
154179
URL xPathUrl = getURL(xpath);
155180
if (xPathUrl != null) {
156-
return getImageData(xPathUrl);
181+
return getImageData(xPathUrl, zoom);
157182
}
158183
}
159184
}
160185
return null;
161186
}
162187

163188
private static ImageData getImageData(URL url) {
189+
return getImageData(url, 0);
190+
}
191+
192+
private static ImageData getImageData(URL url, int zoom) {
164193
ImageData result = null;
165194
try (InputStream in = getStream(url)) {
166195
if (in != null) {
167-
result = new ImageData(in);
196+
result = new ImageData(in, zoom);
168197
}
169198
} catch (SWTException e) {
170199
if (e.code != SWT.ERROR_INVALID_IMAGE) {

bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
113113
org.eclipse.e4.ui.workbench.addons.swt;bundle-version="0.10.0",
114114
org.eclipse.e4.ui.services;bundle-version="1.3.0",
115115
org.eclipse.emf.ecore.xmi;bundle-version="2.11.0",
116-
org.eclipse.e4.core.di.extensions;bundle-version="0.13.0"
116+
org.eclipse.e4.core.di.extensions;bundle-version="0.13.0",
117+
org.eclipse.swt.svg;bundle-version="1.0.0"
117118
Import-Package: com.ibm.icu.util,
118119
jakarta.annotation;version="[2.1.0,3.0.0)",
119120
jakarta.inject;version="[2.0.0,3.0.0)",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
import org.eclipse.swt.graphics.Point;
157157
import org.eclipse.swt.graphics.Rectangle;
158158
import org.eclipse.swt.graphics.Transform;
159+
import org.eclipse.swt.svg.SVGRasterizer;
159160
import org.eclipse.swt.widgets.Display;
160161
import org.eclipse.swt.widgets.Listener;
161162
import org.eclipse.swt.widgets.Monitor;
@@ -567,6 +568,7 @@ public static Workbench getInstance() {
567568
*/
568569
public static int createAndRunWorkbench(final Display display, final WorkbenchAdvisor advisor) {
569570
final int[] returnCode = new int[1];
571+
SVGRasterizer.intializeSVGRasterizer();
570572
Realm.runWithDefault(DisplayRealm.getRealm(display), () -> {
571573
boolean showProgress = PrefUtil.getAPIPreferenceStore()
572574
.getBoolean(IWorkbenchPreferenceConstants.SHOW_PROGRESS_ON_STARTUP);

0 commit comments

Comments
 (0)