Skip to content

Commit 703913e

Browse files
committed
JSVGRasterizer now only accepts InputStream instead of byte array
1 parent 3bc3621 commit 703913e

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.awt.*;
1717
import java.awt.image.*;
1818
import java.io.*;
19-
import java.nio.charset.StandardCharsets;
2019
import java.util.*;
2120
import org.eclipse.swt.graphics.SVGRasterizer;
2221
import org.eclipse.swt.graphics.ImageData;
@@ -58,14 +57,12 @@ public static void intializeJSVGRasterizer() {
5857
);
5958

6059
@Override
61-
public ImageData rasterizeSVG(byte[] bytes, float scalingFactor) throws IOException {
60+
public ImageData rasterizeSVG(InputStream stream, float scalingFactor) throws IOException {
6261
if(svgLoader == null) {
6362
svgLoader = new SVGLoader();
6463
}
6564
SVGDocument svgDocument = null;
66-
try (InputStream stream = new ByteArrayInputStream(bytes)) {
67-
svgDocument = svgLoader.load(stream, null, LoaderContext.createDefault());
68-
}
65+
svgDocument = svgLoader.load(stream, null, LoaderContext.createDefault());
6966
if (svgDocument != null) {
7067
FloatSize size = svgDocument.size();
7168
double originalWidth = size.getWidth();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public interface SVGRasterizer {
2525
* Rasterizes an SVG image from the provided byte array, using the specified
2626
* zoom factor.
2727
*
28-
* @param bytes the SVG image as a byte array.
28+
* @param stream the SVG image as an {@link InputStream}.
2929
* @param scalingFactor the scaling ratio e.g. 2.0 for doubled size.
3030
* @return the {@link ImageData} for the rasterized image, or
3131
* {@code null} if the input is not a valid SVG file or cannot be
3232
* processed.
3333
* @throws IOException if an error occurs while reading the SVG data.
3434
*/
35-
public ImageData rasterizeSVG(byte[] bytes, float scalingFactor) throws IOException;
35+
public ImageData rasterizeSVG(InputStream stream, float scalingFactor) throws IOException;
3636

3737
/**
3838
* Determines whether the given {@link InputStream} contains a SVG file.

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ public ImageData[] load(InputStream stream, int zoom) {
189189
try (InputStream imageStream = new ByteArrayInputStream(bytes)) {
190190
if (rasterizer.isSVGFile(imageStream)) {
191191
float scalingFactor = zoom / 100.0f;
192-
ImageData rasterizedData = rasterizer.rasterizeSVG(bytes, scalingFactor);
193-
if (rasterizedData != null) {
194-
data = new ImageData[]{rasterizedData};
195-
return data;
192+
try (InputStream svgFileStream = new ByteArrayInputStream(bytes)) {
193+
ImageData rasterizedData = rasterizer.rasterizeSVG(svgFileStream, scalingFactor);
194+
if (rasterizedData != null) {
195+
data = new ImageData[]{rasterizedData};
196+
return data;
197+
}
196198
}
197199
}
198200
} catch (IOException e) {

0 commit comments

Comments
 (0)