diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-08-23 14:25:41 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-08-23 14:34:56 +0200 |
commit | 86a60b36552d5785a33bc9eed1e082bd5c54100f (patch) | |
tree | 2af85231f9f7024392406b3f23785fa89c4530c0 /reportbuilder | |
parent | 8098a03d025a0c8fee90322e3835079edb45ade3 (diff) |
fdo#38791: Do not use java.awt, causes problems on Mac OS X
On Mac OS X, it apparently suffices to execute "new java.awt.Dimension()" to run
into "Apple AWT Java VM was loaded on first thread -- can't start AWT" (see
<http://developer.apple.com/library/mac/#technotes/tn2005/tn2147.html> "JNI
Development on Mac OS X - Thread-Safe JNI Programming - Calling AWT/Swing From
AppKit").
The solution here is simple, in that uses of java.awt.Dimension can be replaced
with com.sun.star.awt.Size without loss of functionality. However, there are
still occurrences of java.awt.Image and java.awt.Toolkit lurking
(reportbuilder/java/com/sun/star/report/SOImageService.java,
reportbuilder/java/com/sun/star/report/pentaho/output/ImageProducer.java,
reportbuilder/java/com/sun/star/report/pentaho/output/OfficeDocumentReportTarget.java)
for which it might be sheer luck that they do not seem to cause trouble yet.
Change-Id: I33e9f74c50ebddc11bd1d9a48c55dc8f8700345d
Diffstat (limited to 'reportbuilder')
3 files changed, 24 insertions, 23 deletions
diff --git a/reportbuilder/java/com/sun/star/report/ImageService.java b/reportbuilder/java/com/sun/star/report/ImageService.java index 4c106f9bbea2..31c05e12e409 100644 --- a/reportbuilder/java/com/sun/star/report/ImageService.java +++ b/reportbuilder/java/com/sun/star/report/ImageService.java @@ -17,7 +17,7 @@ */ package com.sun.star.report; -import java.awt.Dimension; +import com.sun.star.awt.Size; import java.io.InputStream; @@ -48,7 +48,7 @@ public interface ImageService * * @throws ReportExecutionException * @return*/ - Dimension getImageSize(final InputStream image) throws ReportExecutionException; + Size getImageSize(final InputStream image) throws ReportExecutionException; /** * @param image @@ -56,6 +56,6 @@ public interface ImageService * * @throws ReportExecutionException * @return*/ - Dimension getImageSize(final byte[] image) throws ReportExecutionException; + Size getImageSize(final byte[] image) throws ReportExecutionException; } diff --git a/reportbuilder/java/com/sun/star/report/SOImageService.java b/reportbuilder/java/com/sun/star/report/SOImageService.java index 81d3b10f92fe..e9c073984ba1 100644 --- a/reportbuilder/java/com/sun/star/report/SOImageService.java +++ b/reportbuilder/java/com/sun/star/report/SOImageService.java @@ -32,8 +32,6 @@ import com.sun.star.lib.uno.adapter.InputStreamToXInputStreamAdapter; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; -import java.awt.Dimension; - import java.io.InputStream; @@ -69,14 +67,14 @@ public class SOImageService implements ImageService } } - public Dimension getImageSize(final InputStream image) throws ReportExecutionException + public Size getImageSize(final InputStream image) throws ReportExecutionException { return getImageSize(new InputStreamToXInputStreamAdapter(image)); } - private Dimension getImageSize(final XInputStream image) throws ReportExecutionException + private Size getImageSize(final XInputStream image) throws ReportExecutionException { - final Dimension dim = new Dimension(); + final Size dim = new Size(); try { final PropertyValue[] value = new PropertyValue[] @@ -96,13 +94,15 @@ public class SOImageService implements ImageService if (xInfo.hasPropertyByName("Size100thMM")) { Size imageSize = (Size) xImage.getPropertyValue("Size100thMM"); - dim.setSize(imageSize.Width, imageSize.Height); - if (dim.height == 0 && dim.width == 0) + dim.Width = imageSize.Width; + dim.Height = imageSize.Height; + if (dim.Height == 0 && dim.Width == 0) { imageSize = (Size) xImage.getPropertyValue("SizePixel"); final int dpi = java.awt.Toolkit.getDefaultToolkit().getScreenResolution(); final double fac = 2540 / (double) dpi; - dim.setSize(imageSize.Width * fac, imageSize.Height * fac); + dim.Width = (int) (imageSize.Width * fac); + dim.Height = (int) (imageSize.Height * fac); } } else if (xInfo.hasPropertyByName("SizePixel")) @@ -110,7 +110,8 @@ public class SOImageService implements ImageService final Size imageSize = (Size) xImage.getPropertyValue("SizePixel"); final int dpi = java.awt.Toolkit.getDefaultToolkit().getScreenResolution(); final double fac = 2540 / dpi; - dim.setSize(imageSize.Width * fac, imageSize.Height * fac); + dim.Width = (int) (imageSize.Width * fac); + dim.Height = (int) (imageSize.Height * fac); } } } @@ -121,7 +122,7 @@ public class SOImageService implements ImageService return dim; } - public Dimension getImageSize(final byte[] image) throws ReportExecutionException + public Size getImageSize(final byte[] image) throws ReportExecutionException { return getImageSize(new ByteArrayToXInputStreamAdapter(image)); } diff --git a/reportbuilder/java/com/sun/star/report/pentaho/output/ImageProducer.java b/reportbuilder/java/com/sun/star/report/pentaho/output/ImageProducer.java index 9e08814fea1f..a40b82680c5f 100644 --- a/reportbuilder/java/com/sun/star/report/pentaho/output/ImageProducer.java +++ b/reportbuilder/java/com/sun/star/report/pentaho/output/ImageProducer.java @@ -17,13 +17,13 @@ */ package com.sun.star.report.pentaho.output; +import com.sun.star.awt.Size; import com.sun.star.report.ImageService; import com.sun.star.report.InputRepository; import com.sun.star.report.OutputRepository; import com.sun.star.report.ReportExecutionException; import com.sun.star.report.pentaho.DefaultNameGenerator; -import java.awt.Dimension; import java.awt.Image; import java.io.BufferedInputStream; @@ -271,7 +271,7 @@ public class ImageProducer try { final String mimeType = imageService.getMimeType(data); - final Dimension dims = imageService.getImageSize(data); + final Size dims = imageService.getImageSize(data); // copy the image into the local output-storage // todo: Implement data-fingerprinting so that we can detect the mime-type @@ -290,8 +290,8 @@ public class ImageProducer storage.closeOutputRepository(); } - final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getWidth() / 100.0); - final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getHeight() / 100.0); + final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Width / 100.0); + final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Height / 100.0); final OfficeImage officeImage = new OfficeImage("Pictures/" + name, widthVal, heightVal); imageCache.put(imageKey, officeImage); return officeImage; @@ -343,11 +343,11 @@ public class ImageProducer inputStream.close(); } final byte[] data = bout.toByteArray(); - final Dimension dims = imageService.getImageSize(data); + final Size dims = imageService.getImageSize(data); final String mimeType = imageService.getMimeType(data); - final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getWidth() / 100.0); - final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getHeight() / 100.0); + final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Width / 100.0); + final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Height / 100.0); final String filename = copyToOutputRepository(mimeType, data); final OfficeImage officeImage = new OfficeImage(filename, widthVal, heightVal); @@ -419,10 +419,10 @@ public class ImageProducer } final byte[] data = bout.toByteArray(); - final Dimension dims = imageService.getImageSize(data); + final Size dims = imageService.getImageSize(data); final String mimeType = imageService.getMimeType(data); - final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getWidth() / 100.0); - final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getHeight() / 100.0); + final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Width / 100.0); + final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Height / 100.0); if (preserveIRI) { |