Skip to content

Commit 757e9d6

Browse files
committed
remove inner class DynamicImageFileFormat and make SVGFileFormat directly inherit FileFormat
1 parent f609aee commit 757e9d6

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,6 @@ List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom)
8787
}
8888
}
8989

90-
static abstract class DynamicImageFileFormat extends FileFormat {
91-
92-
abstract ImageData[] loadFromByteStream(int targetZoom);
93-
94-
@Override
95-
List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom) {
96-
return Arrays.stream(loadFromByteStream(targetZoom)).map(d -> new ElementAtZoom<>(d, fileZoom)).toList();
97-
}
98-
}
99-
10090
LEDataInputStream inputStream;
10191
LEDataOutputStream outputStream;
10292
ImageLoader loader;

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/SVGFileFormat.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,35 @@
1919
import org.eclipse.swt.*;
2020
import org.eclipse.swt.graphics.*;
2121
import org.eclipse.swt.internal.*;
22-
import org.eclipse.swt.internal.image.FileFormat.*;
22+
import org.eclipse.swt.internal.DPIUtil.*;
2323

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 {
2532

2633
/** The instance of the registered {@link SVGRasterizer}. */
2734
private static final SVGRasterizer RASTERIZER = ServiceLoader.load(SVGRasterizer.class).findFirst().orElse(null);
2835

2936
@Override
3037
boolean isFileFormat(LEDataInputStream stream) throws IOException {
3138
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");
3643
}
3744

3845
@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) {
4051
try {
4152
if (RASTERIZER != null && targetZoom != 0) {
4253
return RASTERIZER.rasterizeSVG(inputStream, targetZoom);

0 commit comments

Comments
 (0)