Skip to content

Commit

Permalink
update cocoa and gtk according to win32
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael5601 committed Dec 12, 2024
1 parent b5365d8 commit 4aead69
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,6 @@ public ImageData[] load(InputStream stream) {
return loadDefault(stream);
}

private ImageData[] loadDefault(InputStream stream) {
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
reset();
data = FileFormat.load(stream, this);
return data;
}

/**
* Loads an array of <code>ImageData</code> objects from the
* specified input stream. If the stream is a SVG File and zoom is not 0,
Expand All @@ -188,36 +181,32 @@ private ImageData[] loadDefault(InputStream stream) {
public ImageData[] load(InputStream stream, int zoom) {
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
reset();
byte[] bytes = null;
try {
bytes = stream.readAllBytes();
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
if (!stream.markSupported()) {
stream = new BufferedInputStream(stream);
}
ISVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
if (rasterizer != null && zoom != 0) {
try {
float scalingFactor = zoom / 100.0f;
BufferedImage image = rasterizer.rasterizeSVG(bytes, scalingFactor);
if(image != null) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ImageIO.write(image, "png", baos);
try (InputStream in = new ByteArrayInputStream(baos.toByteArray())) {
data = FileFormat.load(in, this);
return data;
}
}
}
} catch (IOException e) {
// try standard method
}
}
try (InputStream fallbackStream = new ByteArrayInputStream(bytes)) {
return loadDefault(fallbackStream);
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
try {
if (rasterizer.isSVGFile(stream)) {
float scalingFactor = zoom / 100.0f;
ImageData rasterizedData = rasterizer.rasterizeSVG(stream, scalingFactor);
if (rasterizedData != null) {
data = new ImageData[]{rasterizedData};
return data;
}
}
} catch (IOException e) {
//ignore.
}
}
return null;
return loadDefault(stream);
}

private ImageData[] loadDefault(InputStream stream) {
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
reset();
data = FileFormat.load(stream, this);
return data;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,6 @@ public ImageData[] load(InputStream stream) {
return loadDefault(stream);
}

private ImageData[] loadDefault(InputStream stream) {
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
reset();
data = getImageDataArrayFromStream(stream);
return data;
}

/**
* Loads an array of <code>ImageData</code> objects from the
* specified input stream. If the stream is a SVG File and zoom is not 0,
Expand All @@ -198,37 +191,32 @@ private ImageData[] loadDefault(InputStream stream) {
public ImageData[] load(InputStream stream, int zoom) {
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
reset();
byte[] bytes = null;
try {
bytes = stream.readAllBytes();
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
if (!stream.markSupported()) {
stream = new BufferedInputStream(stream);
}
ISVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
if (rasterizer != null && zoom != 0) {
try {
float scalingFactor = zoom / 100.0f;
BufferedImage image = rasterizer.rasterizeSVG(bytes, scalingFactor);
if(image != null) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ImageIO.write(image, "png", baos);
try (InputStream in = new ByteArrayInputStream(baos.toByteArray())) {
data = getImageDataArrayFromStream(in);
return data;
}
}
}
} catch (IOException e) {
// try standard method
}
}
try (InputStream fallbackStream = new ByteArrayInputStream(bytes)) {
data = getImageDataArrayFromStream(stream);
return data;
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
try {
if (rasterizer.isSVGFile(stream)) {
float scalingFactor = zoom / 100.0f;
ImageData rasterizedData = rasterizer.rasterizeSVG(stream, scalingFactor);
if (rasterizedData != null) {
data = new ImageData[]{rasterizedData};
return data;
}
}
} catch (IOException e) {
//ignore.
}
}
return null;
return loadDefault(stream);
}

private ImageData[] loadDefault(InputStream stream) {
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
reset();
data = getImageDataArrayFromStream(stream);
return data;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ public ImageData[] load(InputStream stream, int zoom) {
if (!stream.markSupported()) {
stream = new BufferedInputStream(stream);
}

SVGRasterizer rasterizer = SVGRasterizerRegistry.getRasterizer();
if (rasterizer != null && zoom != 0) {
try {
Expand Down

0 comments on commit 4aead69

Please sign in to comment.