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 0dd30a8387..812bba8772 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 @@ -63,24 +63,22 @@ public ImageData rasterizeSVG(byte[] bytes, float scalingFactor) throws IOExcept svgLoader = new SVGLoader(); } SVGDocument svgDocument = null; - if (isSVGFile(bytes)) { - try (InputStream stream = new ByteArrayInputStream(bytes)) { - svgDocument = svgLoader.load(stream, null, LoaderContext.createDefault()); - } - if (svgDocument != null) { - FloatSize size = svgDocument.size(); - double originalWidth = size.getWidth(); - double originalHeight = size.getHeight(); - int scaledWidth = (int) Math.round(originalWidth * scalingFactor); - int scaledHeight = (int) Math.round(originalHeight * scalingFactor); - BufferedImage image = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB); - Graphics2D g = image.createGraphics(); - g.setRenderingHints(RENDERING_HINTS); - g.scale(scalingFactor, scalingFactor); - svgDocument.render(null, g); - g.dispose(); - return convertToSWT(image); - } + try (InputStream stream = new ByteArrayInputStream(bytes)) { + svgDocument = svgLoader.load(stream, null, LoaderContext.createDefault()); + } + if (svgDocument != null) { + FloatSize size = svgDocument.size(); + double originalWidth = size.getWidth(); + double originalHeight = size.getHeight(); + int scaledWidth = (int) Math.round(originalWidth * scalingFactor); + int scaledHeight = (int) Math.round(originalHeight * scalingFactor); + BufferedImage image = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = image.createGraphics(); + g.setRenderingHints(RENDERING_HINTS); + g.scale(scalingFactor, scalingFactor); + svgDocument.render(null, g); + g.dispose(); + return convertToSWT(image); } return null; } 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 92d97bf6f2..6928deedbc 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 @@ -186,16 +186,18 @@ public ImageData[] load(InputStream stream, int zoom) { } SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer(); if (rasterizer != null && zoom != 0) { - float scalingFactor = zoom / 100.0f; - try { + try (InputStream imageStream = new ByteArrayInputStream(bytes)) { + if (rasterizer.isSVGFile(imageStream)) { + float scalingFactor = zoom / 100.0f; ImageData rasterizedData = rasterizer.rasterizeSVG(bytes, scalingFactor); if (rasterizedData != null) { data = new ImageData[]{rasterizedData}; return data; } - } catch (IOException e) { - //ignore. } + } catch (IOException e) { + //ignore. + } } try (InputStream fallbackStream = new ByteArrayInputStream(bytes)) { return loadDefault(fallbackStream);