-
For the next release, we'd like to consume some of our SVG-based icons in the GEF project directly, rather than their PNG counterpart. But to remain compatible with older Eclipse releases, we need to check whether this is supported by the SWT version of the running application. My current ideas are:
The first two are not really possible for Draw2D as it may be executed without OSGi and the latter are not very clean, either. So my question: Does SWT have an easy way to check whether the SVG (or any given file format) is currently supported? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
To answer my own question: SVG support can be required via the following entry in the manifest header:
This capability must be marked as optional, to remain backwards compatible. To then check whether SVG is supported, following snippet can be used: private static Boolean isSvgSupported;
public static boolean isSvgSupported() {
if (isSvgSupported != null) {
return isSvgSupported;
}
isSvgSupported = false;
BundleWiring wiring = FrameworkUtil.getBundle(InternalGEFPlugin.class).adapt(BundleWiring.class);
if (wiring == null) {
return false;
}
List<BundleRequirement> requirements = wiring.getRequirements("eclipse.swt"); //$NON-NLS-1$
for (BundleRequirement requirement : requirements) {
String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
if ("(image.format=svg)".equals(filter)) { //$NON-NLS-1$
isSvgSupported = true;
break;
}
}
return isSvgSupported;
} Though this only works if used with OSGi. Otherwise something like a system property must be used... |
Beta Was this translation helpful? Give feedback.
To answer my own question: SVG support can be required via the following entry in the manifest header:
This capability must be marked as optional, to remain backwards compatible. To then check whether SVG is supported, following snippet can be used: