|
19 | 19 | import org.eclipse.swt.*; |
20 | 20 | import org.eclipse.swt.graphics.*; |
21 | 21 | import org.eclipse.swt.internal.*; |
22 | | -import org.eclipse.swt.internal.image.FileFormat.*; |
| 22 | +import org.eclipse.swt.internal.DPIUtil.*; |
23 | 23 |
|
24 | | -public class SVGFileFormat extends DynamicImageFileFormat { |
| 24 | +/** |
| 25 | + * A {@link FileFormat} implementation for handling SVG (Scalable Vector Graphics) files. |
| 26 | + * <p> |
| 27 | + * This class detects SVG files based on their header and uses a registered |
| 28 | + * {@link SVGRasterizer} service to rasterize SVG content. |
| 29 | + * </p> |
| 30 | + */ |
| 31 | +public class SVGFileFormat extends FileFormat { |
25 | 32 |
|
26 | 33 | /** The instance of the registered {@link SVGRasterizer}. */ |
27 | 34 | private static final SVGRasterizer RASTERIZER = ServiceLoader.load(SVGRasterizer.class).findFirst().orElse(null); |
28 | 35 |
|
29 | 36 | @Override |
30 | 37 | boolean isFileFormat(LEDataInputStream stream) throws IOException { |
31 | 38 | byte[] firstBytes = new byte[5]; |
32 | | - int bytesRead = stream.read(firstBytes); |
33 | | - stream.unread(firstBytes); |
34 | | - String header = new String(firstBytes, 0, bytesRead, StandardCharsets.UTF_8).trim(); |
35 | | - return header.startsWith("<?xml") || header.startsWith("<svg"); |
| 39 | + int bytesRead = stream.read(firstBytes); |
| 40 | + stream.unread(firstBytes); |
| 41 | + String header = new String(firstBytes, 0, bytesRead, StandardCharsets.UTF_8).trim(); |
| 42 | + return header.startsWith("<?xml") || header.startsWith("<svg"); |
36 | 43 | } |
37 | 44 |
|
38 | 45 | @Override |
39 | | - ImageData[] loadFromByteStream(int targetZoom) { |
| 46 | + List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom) { |
| 47 | + return Arrays.stream(loadFromByteStream(targetZoom)).map(d -> new ElementAtZoom<>(d, fileZoom)).toList(); |
| 48 | + } |
| 49 | + |
| 50 | + private ImageData[] loadFromByteStream(int targetZoom) { |
40 | 51 | try { |
41 | 52 | if (RASTERIZER != null && targetZoom != 0) { |
42 | 53 | return RASTERIZER.rasterizeSVG(inputStream, targetZoom); |
|
0 commit comments