diff --git a/binaries/org.eclipse.swt.win32.win32.x86_64/META-INF/MANIFEST.MF b/binaries/org.eclipse.swt.win32.win32.x86_64/META-INF/MANIFEST.MF
index 72da35e932..d369bfb5ca 100644
--- a/binaries/org.eclipse.swt.win32.win32.x86_64/META-INF/MANIFEST.MF
+++ b/binaries/org.eclipse.swt.win32.win32.x86_64/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Fragment-Host: org.eclipse.swt;bundle-version="[3.128.0,4.0.0)"
Bundle-Name: %fragmentName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.swt.win32.win32.x86_64; singleton:=true
-Bundle-Version: 3.129.0.qualifier
+Bundle-Version: 4.0.0.qualifier
Bundle-ManifestVersion: 2
Bundle-Localization: fragment
Export-Package:
diff --git a/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java b/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java
index 22b21268f9..8c7f1dadf0 100644
--- a/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java
+++ b/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java
@@ -17,10 +17,24 @@
import java.awt.image.*;
import java.io.*;
import java.util.*;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
import org.eclipse.swt.graphics.SVGRasterizer;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
import com.github.weisj.jsvg.*;
import com.github.weisj.jsvg.geometry.size.*;
import com.github.weisj.jsvg.parser.*;
@@ -45,17 +59,39 @@ public class JSVGRasterizer implements SVGRasterizer {
KEY_STROKE_CONTROL, VALUE_STROKE_PURE, //
KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_ON //
);
-
+
@Override
public ImageData rasterizeSVG(InputStream stream, float scalingFactor) throws IOException {
if (stream == null) {
throw new IllegalArgumentException("InputStream cannot be null");
}
- stream.mark(Integer.MAX_VALUE);
if(svgLoader == null) {
svgLoader = new SVGLoader();
}
+ return rasterize(stream, scalingFactor);
+ }
+
+ @Override
+ public ImageData rasterizeDisabledSVG(InputStream stream, float scalingFactor) throws IOException {
+ if(svgLoader == null) {
+ svgLoader = new SVGLoader();
+ }
+ InputStream disabledStream = applyDisabledLook(stream);
+ return rasterize(disabledStream, scalingFactor);
+ }
+
+ @Override
+ public ImageData rasterizeGraySVG(InputStream stream, float scalingFactor) throws IOException {
+ if(svgLoader == null) {
+ svgLoader = new SVGLoader();
+ }
+ InputStream disabledStream = applyGrayLook(stream);
+ return rasterize(disabledStream, scalingFactor);
+ }
+
+ private ImageData rasterize(InputStream stream, float scalingFactor) throws IOException {
SVGDocument svgDocument = null;
+ stream.mark(Integer.MAX_VALUE);
InputStream nonClosingStream = new FilterInputStream(stream) {
@Override
public void close() throws IOException {
@@ -81,6 +117,82 @@ public void close() throws IOException {
return null;
}
+ private static InputStream applyDisabledLook(InputStream svgInputStream) throws IOException {
+ Document svgDocument = parseSVG(svgInputStream);
+ addDisabledFilter(svgDocument);
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+ writeSVG(svgDocument, outputStream);
+ return new ByteArrayInputStream(outputStream.toByteArray());
+ }
+ }
+
+ private static InputStream applyGrayLook(InputStream svgInputStream) throws IOException {
+ Document svgDocument = parseSVG(svgInputStream);
+ addGrayFilter(svgDocument);
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+ writeSVG(svgDocument, outputStream);
+ return new ByteArrayInputStream(outputStream.toByteArray());
+ }
+ }
+
+ private static Document parseSVG(InputStream inputStream) throws IOException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder;
+ try {
+ builder = factory.newDocumentBuilder();
+ return builder.parse(inputStream);
+ } catch (SAXException | IOException | ParserConfigurationException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ private static void addDisabledFilter(Document document) {
+ addFilter(document, 0.64f, 0.4f);
+ }
+
+ private static void addGrayFilter(Document document) {
+ addFilter(document, 0.64f, 0.1f);
+ }
+
+ private static void addFilter(Document document, float slope, float intercept) {
+ Element defs = (Element) document.getElementsByTagName("defs").item(0);
+ if (defs == null) {
+ defs = document.createElement("defs");
+ document.getDocumentElement().appendChild(defs);
+ }
+
+ Element filter = document.createElement("filter");
+ filter.setAttribute("id", "customizedLook");
+
+ Element colorMatrix = document.createElement("feColorMatrix");
+ colorMatrix.setAttribute("type", "saturate");
+ colorMatrix.setAttribute("values", "0");
+ filter.appendChild(colorMatrix);
+
+ Element componentTransfer = document.createElement("feComponentTransfer");
+ for (String channel : new String[] { "R", "G", "B" }) {
+ Element func = document.createElement("feFunc" + channel);
+ func.setAttribute("type", "linear");
+ func.setAttribute("slope", Float.toString(slope));
+ func.setAttribute("intercept", Float.toString(intercept));
+ componentTransfer.appendChild(func);
+ }
+ filter.appendChild(componentTransfer);
+ defs.appendChild(filter);
+ document.getDocumentElement().setAttribute("filter", "url(#customizedLook)");
+ }
+
+ private static void writeSVG(Document document, OutputStream outputStream) throws IOException {
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer;
+ try {
+ transformer = transformerFactory.newTransformer();
+ transformer.transform(new DOMSource(document), new StreamResult(outputStream));
+ } catch (TransformerException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
private ImageData convertToSWT(BufferedImage bufferedImage) {
if (bufferedImage.getColorModel() instanceof DirectColorModel) {
DirectColorModel colorModel = (DirectColorModel)bufferedImage.getColorModel();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/ImageLoader.java
index 6d1ca19b53..f414eadf7c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/ImageLoader.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/ImageLoader.java
@@ -176,26 +176,37 @@ public ImageData[] load(InputStream stream) {
*
ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format
*
*
- * @since 3.129
+ * @since 4.0
*/
-public ImageData[] load(InputStream stream, int zoom) {
+public ImageData[] load(InputStream stream, int zoom, int flag) {
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
reset();
if (!stream.markSupported()) {
stream = new BufferedInputStream(stream);
}
+ ImageData rasterizedData = null;
SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
if (rasterizer != null && zoom != 0) {
- try {
+ try {
if (rasterizer.isSVGFile(stream)) {
- float scalingFactor = zoom / 100.0f;
- ImageData rasterizedData = rasterizer.rasterizeSVG(stream, scalingFactor);
- if (rasterizedData != null) {
+ float scalingFactor = zoom / 100.0f;
+ switch(flag) {
+ case SWT.IMAGE_DISABLE:
+ rasterizedData = rasterizer.rasterizeDisabledSVG(stream, scalingFactor);
+ break;
+ case SWT.IMAGE_GRAY:
+ rasterizedData = rasterizer.rasterizeGraySVG(stream, scalingFactor);
+ break;
+ case SWT.IMAGE_COPY:
+ rasterizedData = rasterizer.rasterizeSVG(stream, scalingFactor);
+ break;
+ }
+ if (rasterizedData != null) {
data = new ImageData[]{rasterizedData};
- return data;
+ return data;
}
}
- } catch (IOException e) {
+ } catch (IOException e) {
//ignore.
}
}
@@ -258,12 +269,12 @@ public ImageData[] load(String filename) {
* ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
*
*
- * @since 3.129
+ * @since 4.0
*/
-public ImageData[] load(String filename, int zoom) {
+public ImageData[] load(String filename, int zoom, int flag) {
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
try (InputStream stream = new FileInputStream(filename)) {
- return load(stream, zoom);
+ return load(stream, zoom, flag);
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java
index a0d03843db..842c978c63 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java
@@ -331,7 +331,7 @@ scanlinePad, checkData(data), 0, null,
* @see ImageLoader#load(InputStream)
*/
public ImageData(InputStream stream) {
- this(stream, 0);
+ this(stream, 0, SWT.IMAGE_COPY);
}
/**
@@ -360,10 +360,10 @@ public ImageData(InputStream stream) {
*
*
* @see ImageLoader#load(InputStream)
- * @since 3.129
+ * @since 4.0
*/
-public ImageData(InputStream stream, int zoom) {
- ImageData[] data = ImageDataLoader.load(stream, zoom);
+public ImageData(InputStream stream, int zoom, int flag) {
+ ImageData[] data = ImageDataLoader.load(stream, zoom, flag);
if (data.length < 1) SWT.error(SWT.ERROR_INVALID_IMAGE);
ImageData i = data[0];
setAllFields(
@@ -409,7 +409,7 @@ public ImageData(InputStream stream, int zoom) {
*
*/
public ImageData(String filename) {
- this(filename, 0);
+ this(filename, 0, SWT.IMAGE_COPY);
}
/**
@@ -435,10 +435,10 @@ public ImageData(String filename) {
* ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
*
*
- * @since 3.129
+ * @since 4.0
*/
-public ImageData(String filename, int zoom) {
- ImageData[] data = ImageDataLoader.load(filename, zoom);
+public ImageData(String filename, int zoom, int flag) {
+ ImageData[] data = ImageDataLoader.load(filename, zoom, flag);
if (data.length < 1) SWT.error(SWT.ERROR_INVALID_IMAGE);
ImageData i = data[0];
setAllFields(
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java
index 9c9da788bf..ebf1979e8f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java
@@ -25,16 +25,16 @@ public static ImageData[] load(InputStream stream) {
return new ImageLoader().load(stream);
}
- public static ImageData[] load(InputStream stream, int zoom) {
- return new ImageLoader().load(stream, zoom);
+ public static ImageData[] load(InputStream stream, int zoom, int flag) {
+ return new ImageLoader().load(stream, zoom, flag);
}
- public static ImageData[] load(String filename) {
+ public static ImageData[] load(String filename) {
return new ImageLoader().load(filename);
}
- public static ImageData[] load(String filename, int zoom) {
- return new ImageLoader().load(filename, zoom);
+ public static ImageData[] load(String filename, int zoom, int flag) {
+ return new ImageLoader().load(filename, zoom, flag);
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataProvider.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataProvider.java
index bfa0ec70a7..bf1c5a9f62 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataProvider.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataProvider.java
@@ -25,7 +25,6 @@
*/
public interface ImageDataProvider {
-
/**
* Returns the image data for the given zoom level.
*
@@ -43,4 +42,17 @@ public interface ImageDataProvider {
*/
ImageData getImageData (int zoom);
+ /**
+ * @since 4.0
+ */
+ default ImageData getCustomizedImageData(int zoom, int flag) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @since 4.0
+ */
+ default boolean supportsRasterizationFlag(int flag) {
+ return false;
+ }
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java
index 82dc18e917..4774a2f2f0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java
@@ -17,7 +17,7 @@
* Defines the interface for an SVG rasterizer, responsible for converting SVG
* data into rasterized images.
*
- * @since 3.129
+ * @since 4.0
*/
public interface SVGRasterizer {
@@ -34,6 +34,10 @@ public interface SVGRasterizer {
*/
public ImageData rasterizeSVG(InputStream stream, float scalingFactor) throws IOException;
+ public ImageData rasterizeDisabledSVG(InputStream stream, float scalingFactor) throws IOException;
+
+ public ImageData rasterizeGraySVG(InputStream stream, float scalingFactor) throws IOException;
+
/**
* Determines whether the given {@link InputStream} contains a SVG file.
*
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizerRegistry.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizerRegistry.java
index 62af643674..e088d1ccdd 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizerRegistry.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizerRegistry.java
@@ -17,7 +17,7 @@
* 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
+ * @since 4.0
*/
class SVGRasterizerRegistry {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java
index bf748338f5..c7d74c0c52 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java
@@ -186,26 +186,37 @@ public ImageData[] load(InputStream stream) {
*
ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format
*
*
- * @since 3.129
+ * @since 4.0
*/
-public ImageData[] load(InputStream stream, int zoom) {
+public ImageData[] load(InputStream stream, int zoom, int flag) {
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
reset();
if (!stream.markSupported()) {
stream = new BufferedInputStream(stream);
}
+ ImageData rasterizedData = null;
SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
if (rasterizer != null && zoom != 0) {
- try {
+ try {
if (rasterizer.isSVGFile(stream)) {
- float scalingFactor = zoom / 100.0f;
- ImageData rasterizedData = rasterizer.rasterizeSVG(stream, scalingFactor);
- if (rasterizedData != null) {
+ float scalingFactor = zoom / 100.0f;
+ switch(flag) {
+ case SWT.IMAGE_DISABLE:
+ rasterizedData = rasterizer.rasterizeDisabledSVG(stream, scalingFactor);
+ break;
+ case SWT.IMAGE_GRAY:
+ rasterizedData = rasterizer.rasterizeGraySVG(stream, scalingFactor);
+ break;
+ case SWT.IMAGE_COPY:
+ rasterizedData = rasterizer.rasterizeSVG(stream, scalingFactor);
+ break;
+ }
+ if (rasterizedData != null) {
data = new ImageData[]{rasterizedData};
- return data;
+ return data;
}
}
- } catch (IOException e) {
+ } catch (IOException e) {
//ignore.
}
}
@@ -376,12 +387,12 @@ public ImageData[] load(String filename) {
* ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
*
*
- * @since 3.129
+ * @since 4.0
*/
-public ImageData[] load(String filename, int zoom) {
+public ImageData[] load(String filename, int zoom, int flag) {
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
try (InputStream stream = new FileInputStream(filename)) {
- return load(stream, zoom);
+ return load(stream, zoom, flag);
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
index f6c5e7c34c..80ca08147c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
@@ -235,6 +235,14 @@ public Image(Device device, Image srcImage, int flag) {
long srcImageHandle = win32_getHandle(srcImage, getZoom());
switch (flag) {
case SWT.IMAGE_COPY: {
+ ImageData data = null;
+ Image newImage = createWithSVG(device, flag);
+ if(newImage != null) {
+ data = newImage.getImageData(newImage.getZoom());
+ init(data, getZoom());
+ newImage.dispose();
+ break;
+ }
switch (type) {
case SWT.BITMAP:
/* Get the HDC for the device */
@@ -270,13 +278,29 @@ public Image(Device device, Image srcImage, int flag) {
break;
}
case SWT.IMAGE_DISABLE: {
- ImageData data = srcImage.getImageData(srcImage.getZoom());
+ ImageData data = null;
+ Image disabledImage = createWithSVG(device, flag);
+ if(disabledImage != null) {
+ data = disabledImage.getImageData(disabledImage.getZoom());
+ init(data, getZoom());
+ disabledImage.dispose();
+ break;
+ }
+ data = srcImage.getImageData(srcImage.getZoom());
ImageData newData = applyDisableImageData(data, rect.height, rect.width);
init (newData, getZoom());
break;
}
case SWT.IMAGE_GRAY: {
- ImageData data = srcImage.getImageData(srcImage.getZoom());
+ ImageData data = null;
+ Image grayImage = createWithSVG(device, flag);
+ if(grayImage != null) {
+ data = grayImage.getImageData(grayImage.getZoom());
+ init(data, getZoom());
+ grayImage.dispose();
+ break;
+ }
+ data = srcImage.getImageData(srcImage.getZoom());
ImageData newData = applyGrayImageData(data, rect.height, rect.width);
init (newData, getZoom());
break;
@@ -288,6 +312,26 @@ public Image(Device device, Image srcImage, int flag) {
this.device.registerResourceWithZoomSupport(this);
}
+private Image createWithSVG(Device device, int flag) {
+ Image customizedImage = null;
+ if (imageFileNameProvider != null) {
+ ElementAtZoom fileName = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, getZoom());
+ try (InputStream stream = new BufferedInputStream(new FileInputStream(fileName.element()))){
+ SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
+ if(rasterizer != null && rasterizer.isSVGFile(stream)) {
+ customizedImage = new Image(device, imageFileNameProvider, flag);
+ }
+ } catch (IOException e) {
+ SWT.error(SWT.ERROR_IO, e);
+ }
+ } else if (imageDataProvider != null) {
+ if(imageDataProvider.supportsRasterizationFlag(flag)) {
+ customizedImage = new Image(device, imageDataProvider, flag);
+ }
+ }
+ return customizedImage;
+}
+
/**
* Constructs an empty instance of this class with the
* width and height of the specified rectangle. The result
@@ -468,7 +512,7 @@ public Image(Device device, ImageData source, ImageData mask) {
public Image (Device device, InputStream stream) {
super(device);
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
- ImageData data = DPIUtil.autoScaleUp(device, new ElementAtZoom<>(new ImageData (stream, getZoom()), 100));
+ ImageData data = DPIUtil.autoScaleUp(device, new ElementAtZoom<>(new ImageData (stream, getZoom(), SWT.IMAGE_COPY), 100));
init(data, getZoom());
init();
this.device.registerResourceWithZoomSupport(this);
@@ -510,7 +554,7 @@ public Image (Device device, String filename) {
super(device);
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
- ImageData data = DPIUtil.autoScaleUp(device, new ElementAtZoom<>(new ImageData (filename, getZoom()), 100));
+ ImageData data = DPIUtil.autoScaleUp(device, new ElementAtZoom<>(new ImageData (filename, getZoom(), SWT.IMAGE_COPY), 100));
init(data, getZoom());
init();
this.device.registerResourceWithZoomSupport(this);
@@ -546,6 +590,13 @@ public Image (Device device, String filename) {
* @since 3.104
*/
public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
+ this(device, imageFileNameProvider, SWT.IMAGE_COPY);
+}
+
+/**
+ * @since 4.0
+ */
+public Image(Device device, ImageFileNameProvider imageFileNameProvider, int flag) {
super(device);
this.imageFileNameProvider = imageFileNameProvider;
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
@@ -553,10 +604,10 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
if (fileName.zoom() == getZoom()) {
ImageHandle imageMetadata = initNative (fileName.element(), getZoom());
if (imageMetadata == null) {
- init(new ImageData (fileName.element(), getZoom()), getZoom());
+ init(new ImageData (fileName.element(), getZoom(), flag), getZoom());
}
} else {
- ImageData resizedData = DPIUtil.autoScaleImageData (device, new ImageData (fileName.element(), getZoom()), fileName.zoom());
+ ImageData resizedData = DPIUtil.autoScaleImageData (device, new ImageData (fileName.element(), getZoom(), flag), fileName.zoom());
init(resizedData, getZoom());
}
init();
@@ -603,6 +654,16 @@ public Image(Device device, ImageDataProvider imageDataProvider) {
this.device.registerResourceWithZoomSupport(this);
}
+private Image(Device device, ImageDataProvider imageDataProvider, int flag) {
+ super(device);
+ this.imageDataProvider = imageDataProvider;
+ initialNativeZoom = DPIUtil.getNativeDeviceZoom();
+ ImageData data = imageDataProvider.getCustomizedImageData(getZoom(), flag);
+ init (data, getZoom());
+ init();
+ this.device.registerResourceWithZoomSupport(this);
+}
+
private ImageData adaptImageDataIfDisabledOrGray(ImageData data) {
ImageData returnImageData = null;
switch (this.styleFlag) {
@@ -753,7 +814,7 @@ private ImageHandle getImageMetadata(int zoom) {
if (imageFileNameProvider != null) {
ElementAtZoom imageCandidate = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, zoom);
- ImageData imageData = new ImageData (imageCandidate.element(), zoom);
+ ImageData imageData = new ImageData (imageCandidate.element(), zoom, SWT.IMAGE_COPY);
if (imageCandidate.zoom() == zoom) {
/* Release current native resources */
ImageHandle imageMetadata = initNative(imageCandidate.element(), zoom);
@@ -1389,7 +1450,7 @@ public ImageData getImageData (int zoom) {
return DPIUtil.scaleImageData (device, data.element(), zoom, data.zoom());
} else if (imageFileNameProvider != null) {
ElementAtZoom fileName = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, zoom);
- return DPIUtil.scaleImageData (device, new ImageData (fileName.element(), zoom), zoom, fileName.zoom());
+ return DPIUtil.scaleImageData (device, new ImageData (fileName.element(), zoom, SWT.IMAGE_COPY), zoom, fileName.zoom());
}
// if a GC is initialized with an Image (memGC != null), the image data must not be resized, because it would
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java
index a7bd3e9675..b1b8780b41 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java
@@ -173,26 +173,37 @@ public ImageData[] load(InputStream stream) {
* ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format
*
*
- * @since 3.129
+ * @since 4.0
*/
-public ImageData[] load(InputStream stream, int zoom) {
+public ImageData[] load(InputStream stream, int zoom, int flag) {
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
reset();
if (!stream.markSupported()) {
stream = new BufferedInputStream(stream);
}
+ ImageData rasterizedData = null;
SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
if (rasterizer != null && zoom != 0) {
- try {
+ try {
if (rasterizer.isSVGFile(stream)) {
- float scalingFactor = zoom / 100.0f;
- ImageData rasterizedData = rasterizer.rasterizeSVG(stream, scalingFactor);
- if (rasterizedData != null) {
+ float scalingFactor = zoom / 100.0f;
+ switch(flag) {
+ case SWT.IMAGE_DISABLE:
+ rasterizedData = rasterizer.rasterizeDisabledSVG(stream, scalingFactor);
+ break;
+ case SWT.IMAGE_GRAY:
+ rasterizedData = rasterizer.rasterizeGraySVG(stream, scalingFactor);
+ break;
+ case SWT.IMAGE_COPY:
+ rasterizedData = rasterizer.rasterizeSVG(stream, scalingFactor);
+ break;
+ }
+ if (rasterizedData != null) {
data = new ImageData[]{rasterizedData};
- return data;
+ return data;
}
}
- } catch (IOException e) {
+ } catch (IOException e) {
//ignore.
}
}
@@ -203,7 +214,7 @@ private ImageData[] loadDefault(InputStream stream) {
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
reset();
data = FileFormat.load(stream, this);
- return data;
+ return data;
}
/**
@@ -255,12 +266,12 @@ public ImageData[] load(String filename) {
* ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
*
*
- * @since 3.129
+ * @since 4.0
*/
-public ImageData[] load(String filename, int zoom) {
+public ImageData[] load(String filename, int zoom, int flag) {
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
try (InputStream stream = new FileInputStream(filename)) {
- return load(stream, zoom);
+ return load(stream, zoom, flag);
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
}