Skip to content

Commit

Permalink
[FIXUP|SUGGESTION] Make swt.svg a fragment of o.e.swt
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HannesWell committed Dec 17, 2024
1 parent 4aead69 commit 44e6f19
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 26 deletions.
9 changes: 9 additions & 0 deletions bundles/org.eclipse.swt.svg/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,14 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="libs/jsvg-1.6.1.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.win32.win32.x86_64"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.win32.win32.aarch64"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.gtk.linux.x86_64"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.gtk.linux.riscv64"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.gtk.linux.ppc64le"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.gtk.linux.loongarch64"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.gtk.linux.aarch64"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.cocoa.macosx.x86_64"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt.cocoa.macosx.aarch64"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.incompleteClasspath=warning
2 changes: 1 addition & 1 deletion bundles/org.eclipse.swt.svg/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Bundle-SymbolicName: org.eclipse.swt.svg
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: org.eclipse.swt.svgPlugin
Bundle-RequiredExecutionEnvironment: JavaSE-17
Fragment-Host: org.eclipse.swt
Export-Package: org.eclipse.swt.svg
Import-Package: org.eclipse.swt.graphics
Bundle-ClassPath: ., libs/jsvg-1.6.1.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.eclipse.swt.svg.JSVGRasterizer
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.SVGRasterizerRegistry;

import com.github.weisj.jsvg.*;
import com.github.weisj.jsvg.geometry.size.*;
import com.github.weisj.jsvg.parser.*;
Expand All @@ -37,14 +35,6 @@ public class JSVGRasterizer implements SVGRasterizer {

private SVGLoader svgLoader;

/**
* Initializes the SVG rasterizer by registering an instance of this rasterizer
* with the {@link SVGRasterizerRegistry}.
*/
public static void intializeJSVGRasterizer() {
SVGRasterizerRegistry.register(new JSVGRasterizer());
}

private final static Map<Key, Object> RENDERING_HINTS = Map.of(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON, //
KEY_ALPHA_INTERPOLATION, VALUE_ALPHA_INTERPOLATION_QUALITY, //
KEY_COLOR_RENDERING, VALUE_COLOR_RENDER_QUALITY, //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ public interface SVGRasterizer {
* @throws IllegalArgumentException if the input stream is {@code null}.
*/
public boolean isSVGFile(InputStream stream) throws IOException;
//TODO: use optional above instead?
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,21 @@
*******************************************************************************/
package org.eclipse.swt.graphics;

import java.util.*;

/**
* A registry for managing the instance of an {@link SVGRasterizer} implementation.
* This allows for the registration and retrieval of a single rasterizer instance.
*
* @since 3.129
*/
public class SVGRasterizerRegistry {
//TODO: make this internal?

/**
* The instance of the registered {@link SVGRasterizer}.
*/
private static SVGRasterizer rasterizer;

/**
* Registers the provided implementation of {@link SVGRasterizer}.
* If a rasterizer has already been registered, subsequent calls to this method
* will have no effect.
*
* @param implementation the {@link SVGRasterizer} implementation to register.
*/
public static void register(SVGRasterizer implementation) {
if (rasterizer == null) {
rasterizer = implementation;
}
}
private static final SVGRasterizer RASTERIZER = ServiceLoader.load(SVGRasterizer.class).findFirst().orElse(null);

/**
* Retrieves the currently registered {@link SVGRasterizer} implementation.
Expand All @@ -44,6 +34,6 @@ public static void register(SVGRasterizer implementation) {
* has been registered.
*/
public static SVGRasterizer getRasterizer() {
return rasterizer;
return RASTERIZER;
}
}

0 comments on commit 44e6f19

Please sign in to comment.