Skip to content

Commit 44e6f19

Browse files
committed
[FIXUP|SUGGESTION] Make swt.svg a fragment of o.e.swt
and add the other swt-fragments containing the native code explicitly to the build-path of swt.svg. Because the classloader of the host is shared by all fragments, the plain Java ServiceLoader can now be used to get an implementation of SVGRasterizer.
1 parent 4aead69 commit 44e6f19

File tree

7 files changed

+18
-26
lines changed

7 files changed

+18
-26
lines changed

bundles/org.eclipse.swt.svg/.classpath

+9
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,14 @@
44
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
55
<classpathentry kind="src" path="src"/>
66
<classpathentry kind="lib" path="libs/jsvg-1.6.1.jar"/>
7+
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.win32.win32.x86_64"/>
8+
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.win32.win32.aarch64"/>
9+
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.gtk.linux.x86_64"/>
10+
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.gtk.linux.riscv64"/>
11+
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.gtk.linux.ppc64le"/>
12+
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.gtk.linux.loongarch64"/>
13+
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.gtk.linux.aarch64"/>
14+
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.cocoa.macosx.x86_64"/>
15+
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.cocoa.macosx.aarch64"/>
716
<classpathentry kind="output" path="bin"/>
817
</classpath>

bundles/org.eclipse.swt.svg/.settings/org.eclipse.jdt.core.prefs

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
77
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
88
org.eclipse.jdt.core.compiler.release=enabled
99
org.eclipse.jdt.core.compiler.source=17
10+
org.eclipse.jdt.core.incompleteClasspath=warning

bundles/org.eclipse.swt.svg/META-INF/MANIFEST.MF

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ Bundle-SymbolicName: org.eclipse.swt.svg
55
Bundle-Version: 1.0.0.qualifier
66
Automatic-Module-Name: org.eclipse.swt.svgPlugin
77
Bundle-RequiredExecutionEnvironment: JavaSE-17
8+
Fragment-Host: org.eclipse.swt
89
Export-Package: org.eclipse.swt.svg
9-
Import-Package: org.eclipse.swt.graphics
1010
Bundle-ClassPath: ., libs/jsvg-1.6.1.jar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.swt.svg.JSVGRasterizer

bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java

-10
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import org.eclipse.swt.graphics.ImageData;
2222
import org.eclipse.swt.graphics.PaletteData;
2323
import org.eclipse.swt.graphics.RGB;
24-
import org.eclipse.swt.graphics.SVGRasterizerRegistry;
25-
2624
import com.github.weisj.jsvg.*;
2725
import com.github.weisj.jsvg.geometry.size.*;
2826
import com.github.weisj.jsvg.parser.*;
@@ -37,14 +35,6 @@ public class JSVGRasterizer implements SVGRasterizer {
3735

3836
private SVGLoader svgLoader;
3937

40-
/**
41-
* Initializes the SVG rasterizer by registering an instance of this rasterizer
42-
* with the {@link SVGRasterizerRegistry}.
43-
*/
44-
public static void intializeJSVGRasterizer() {
45-
SVGRasterizerRegistry.register(new JSVGRasterizer());
46-
}
47-
4838
private final static Map<Key, Object> RENDERING_HINTS = Map.of(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON, //
4939
KEY_ALPHA_INTERPOLATION, VALUE_ALPHA_INTERPOLATION_QUALITY, //
5040
KEY_COLOR_RENDERING, VALUE_COLOR_RENDER_QUALITY, //

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ public interface SVGRasterizer {
4444
* @throws IllegalArgumentException if the input stream is {@code null}.
4545
*/
4646
public boolean isSVGFile(InputStream stream) throws IOException;
47+
//TODO: use optional above instead?
4748
}

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizerRegistry.java

+5-15
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,21 @@
1111
*******************************************************************************/
1212
package org.eclipse.swt.graphics;
1313

14+
import java.util.*;
15+
1416
/**
1517
* A registry for managing the instance of an {@link SVGRasterizer} implementation.
1618
* This allows for the registration and retrieval of a single rasterizer instance.
1719
*
1820
* @since 3.129
1921
*/
2022
public class SVGRasterizerRegistry {
23+
//TODO: make this internal?
2124

2225
/**
2326
* The instance of the registered {@link SVGRasterizer}.
2427
*/
25-
private static SVGRasterizer rasterizer;
26-
27-
/**
28-
* Registers the provided implementation of {@link SVGRasterizer}.
29-
* If a rasterizer has already been registered, subsequent calls to this method
30-
* will have no effect.
31-
*
32-
* @param implementation the {@link SVGRasterizer} implementation to register.
33-
*/
34-
public static void register(SVGRasterizer implementation) {
35-
if (rasterizer == null) {
36-
rasterizer = implementation;
37-
}
38-
}
28+
private static final SVGRasterizer RASTERIZER = ServiceLoader.load(SVGRasterizer.class).findFirst().orElse(null);
3929

4030
/**
4131
* Retrieves the currently registered {@link SVGRasterizer} implementation.
@@ -44,6 +34,6 @@ public static void register(SVGRasterizer implementation) {
4434
* has been registered.
4535
*/
4636
public static SVGRasterizer getRasterizer() {
47-
return rasterizer;
37+
return RASTERIZER;
4838
}
4939
}

0 commit comments

Comments
 (0)