Skip to content

Commit 4aead69

Browse files
committed
update cocoa and gtk according to win32
1 parent b5365d8 commit 4aead69

File tree

3 files changed

+46
-70
lines changed

3 files changed

+46
-70
lines changed

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

+23-34
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,6 @@ public ImageData[] load(InputStream stream) {
155155
return loadDefault(stream);
156156
}
157157

158-
private ImageData[] loadDefault(InputStream stream) {
159-
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
160-
reset();
161-
data = FileFormat.load(stream, this);
162-
return data;
163-
}
164-
165158
/**
166159
* Loads an array of <code>ImageData</code> objects from the
167160
* specified input stream. If the stream is a SVG File and zoom is not 0,
@@ -188,36 +181,32 @@ private ImageData[] loadDefault(InputStream stream) {
188181
public ImageData[] load(InputStream stream, int zoom) {
189182
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
190183
reset();
191-
byte[] bytes = null;
192-
try {
193-
bytes = stream.readAllBytes();
194-
} catch (IOException e) {
195-
SWT.error(SWT.ERROR_IO, e);
184+
if (!stream.markSupported()) {
185+
stream = new BufferedInputStream(stream);
196186
}
197-
ISVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
187+
SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
198188
if (rasterizer != null && zoom != 0) {
199-
try {
200-
float scalingFactor = zoom / 100.0f;
201-
BufferedImage image = rasterizer.rasterizeSVG(bytes, scalingFactor);
202-
if(image != null) {
203-
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
204-
ImageIO.write(image, "png", baos);
205-
try (InputStream in = new ByteArrayInputStream(baos.toByteArray())) {
206-
data = FileFormat.load(in, this);
207-
return data;
208-
}
209-
}
210-
}
211-
} catch (IOException e) {
212-
// try standard method
213-
}
214-
}
215-
try (InputStream fallbackStream = new ByteArrayInputStream(bytes)) {
216-
return loadDefault(fallbackStream);
217-
} catch (IOException e) {
218-
SWT.error(SWT.ERROR_IO, e);
189+
try {
190+
if (rasterizer.isSVGFile(stream)) {
191+
float scalingFactor = zoom / 100.0f;
192+
ImageData rasterizedData = rasterizer.rasterizeSVG(stream, scalingFactor);
193+
if (rasterizedData != null) {
194+
data = new ImageData[]{rasterizedData};
195+
return data;
196+
}
197+
}
198+
} catch (IOException e) {
199+
//ignore.
200+
}
219201
}
220-
return null;
202+
return loadDefault(stream);
203+
}
204+
205+
private ImageData[] loadDefault(InputStream stream) {
206+
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
207+
reset();
208+
data = FileFormat.load(stream, this);
209+
return data;
221210
}
222211

223212
/**

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

+23-35
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,6 @@ public ImageData[] load(InputStream stream) {
165165
return loadDefault(stream);
166166
}
167167

168-
private ImageData[] loadDefault(InputStream stream) {
169-
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
170-
reset();
171-
data = getImageDataArrayFromStream(stream);
172-
return data;
173-
}
174-
175168
/**
176169
* Loads an array of <code>ImageData</code> objects from the
177170
* specified input stream. If the stream is a SVG File and zoom is not 0,
@@ -198,37 +191,32 @@ private ImageData[] loadDefault(InputStream stream) {
198191
public ImageData[] load(InputStream stream, int zoom) {
199192
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
200193
reset();
201-
byte[] bytes = null;
202-
try {
203-
bytes = stream.readAllBytes();
204-
} catch (IOException e) {
205-
SWT.error(SWT.ERROR_IO, e);
194+
if (!stream.markSupported()) {
195+
stream = new BufferedInputStream(stream);
206196
}
207-
ISVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
197+
SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
208198
if (rasterizer != null && zoom != 0) {
209-
try {
210-
float scalingFactor = zoom / 100.0f;
211-
BufferedImage image = rasterizer.rasterizeSVG(bytes, scalingFactor);
212-
if(image != null) {
213-
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
214-
ImageIO.write(image, "png", baos);
215-
try (InputStream in = new ByteArrayInputStream(baos.toByteArray())) {
216-
data = getImageDataArrayFromStream(in);
217-
return data;
218-
}
219-
}
220-
}
221-
} catch (IOException e) {
222-
// try standard method
223-
}
224-
}
225-
try (InputStream fallbackStream = new ByteArrayInputStream(bytes)) {
226-
data = getImageDataArrayFromStream(stream);
227-
return data;
228-
} catch (IOException e) {
229-
SWT.error(SWT.ERROR_IO, e);
199+
try {
200+
if (rasterizer.isSVGFile(stream)) {
201+
float scalingFactor = zoom / 100.0f;
202+
ImageData rasterizedData = rasterizer.rasterizeSVG(stream, scalingFactor);
203+
if (rasterizedData != null) {
204+
data = new ImageData[]{rasterizedData};
205+
return data;
206+
}
207+
}
208+
} catch (IOException e) {
209+
//ignore.
210+
}
230211
}
231-
return null;
212+
return loadDefault(stream);
213+
}
214+
215+
private ImageData[] loadDefault(InputStream stream) {
216+
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
217+
reset();
218+
data = getImageDataArrayFromStream(stream);
219+
return data;
232220
}
233221

234222
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ public ImageData[] load(InputStream stream, int zoom) {
181181
if (!stream.markSupported()) {
182182
stream = new BufferedInputStream(stream);
183183
}
184-
185184
SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
186185
if (rasterizer != null && zoom != 0) {
187186
try {

0 commit comments

Comments
 (0)