|
16 | 16 | import java.awt.*;
|
17 | 17 | import java.awt.image.*;
|
18 | 18 | import java.io.*;
|
| 19 | +import java.nio.charset.StandardCharsets; |
19 | 20 | import java.util.*;
|
20 | 21 | import org.eclipse.swt.graphics.SVGRasterizer;
|
21 | 22 | import org.eclipse.swt.graphics.ImageData;
|
22 | 23 | import org.eclipse.swt.graphics.PaletteData;
|
23 | 24 | import org.eclipse.swt.graphics.RGB;
|
24 | 25 | import org.eclipse.swt.graphics.SVGRasterizerRegistry;
|
25 |
| -import org.eclipse.swt.graphics.SVGUtil; |
26 | 26 |
|
27 | 27 | import com.github.weisj.jsvg.*;
|
28 | 28 | import com.github.weisj.jsvg.geometry.size.*;
|
@@ -63,7 +63,7 @@ public ImageData rasterizeSVG(byte[] bytes, float scalingFactor) throws IOExcept
|
63 | 63 | svgLoader = new SVGLoader();
|
64 | 64 | }
|
65 | 65 | SVGDocument svgDocument = null;
|
66 |
| - if (SVGUtil.isSVGFile(bytes)) { |
| 66 | + if (isSVGFile(bytes)) { |
67 | 67 | try (InputStream stream = new ByteArrayInputStream(bytes)) {
|
68 | 68 | svgDocument = svgLoader.load(stream, null, LoaderContext.createDefault());
|
69 | 69 | }
|
@@ -154,4 +154,17 @@ else if (bufferedImage.getColorModel() instanceof ComponentColorModel) {
|
154 | 154 | }
|
155 | 155 | return null;
|
156 | 156 | }
|
| 157 | + |
| 158 | + private boolean isSVGFile(byte[] data) throws IOException { |
| 159 | + String content = new String(data, 0, Math.min(data.length, 512), StandardCharsets.UTF_8); |
| 160 | + return content.contains("<svg"); |
| 161 | + } |
| 162 | + |
| 163 | + public boolean isSVGFile(InputStream inputStream) throws IOException { |
| 164 | + if (inputStream == null) { |
| 165 | + throw new IllegalArgumentException("InputStream cannot be null"); |
| 166 | + } |
| 167 | + byte[] data = inputStream.readNBytes(512); |
| 168 | + return isSVGFile(data); |
| 169 | + } |
157 | 170 | }
|
0 commit comments