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
This commit is contained in:
Stephan Bergmann
2012-08-23 14:25:41 +02:00
parent 8098a03d02
commit 86a60b3655
3 changed files with 24 additions and 23 deletions

View File

@@ -17,7 +17,7 @@
*/ */
package com.sun.star.report; package com.sun.star.report;
import java.awt.Dimension; import com.sun.star.awt.Size;
import java.io.InputStream; import java.io.InputStream;
@@ -48,7 +48,7 @@ public interface ImageService
* *
* @throws ReportExecutionException * @throws ReportExecutionException
* @return*/ * @return*/
Dimension getImageSize(final InputStream image) throws ReportExecutionException; Size getImageSize(final InputStream image) throws ReportExecutionException;
/** /**
* @param image * @param image
@@ -56,6 +56,6 @@ public interface ImageService
* *
* @throws ReportExecutionException * @throws ReportExecutionException
* @return*/ * @return*/
Dimension getImageSize(final byte[] image) throws ReportExecutionException; Size getImageSize(final byte[] image) throws ReportExecutionException;
} }

View File

@@ -32,8 +32,6 @@ import com.sun.star.lib.uno.adapter.InputStreamToXInputStreamAdapter;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext; import com.sun.star.uno.XComponentContext;
import java.awt.Dimension;
import java.io.InputStream; 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)); 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 try
{ {
final PropertyValue[] value = new PropertyValue[] final PropertyValue[] value = new PropertyValue[]
@@ -96,13 +94,15 @@ public class SOImageService implements ImageService
if (xInfo.hasPropertyByName("Size100thMM")) if (xInfo.hasPropertyByName("Size100thMM"))
{ {
Size imageSize = (Size) xImage.getPropertyValue("Size100thMM"); Size imageSize = (Size) xImage.getPropertyValue("Size100thMM");
dim.setSize(imageSize.Width, imageSize.Height); dim.Width = imageSize.Width;
if (dim.height == 0 && dim.width == 0) dim.Height = imageSize.Height;
if (dim.Height == 0 && dim.Width == 0)
{ {
imageSize = (Size) xImage.getPropertyValue("SizePixel"); imageSize = (Size) xImage.getPropertyValue("SizePixel");
final int dpi = java.awt.Toolkit.getDefaultToolkit().getScreenResolution(); final int dpi = java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
final double fac = 2540 / (double) dpi; 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")) else if (xInfo.hasPropertyByName("SizePixel"))
@@ -110,7 +110,8 @@ public class SOImageService implements ImageService
final Size imageSize = (Size) xImage.getPropertyValue("SizePixel"); final Size imageSize = (Size) xImage.getPropertyValue("SizePixel");
final int dpi = java.awt.Toolkit.getDefaultToolkit().getScreenResolution(); final int dpi = java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
final double fac = 2540 / dpi; 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; return dim;
} }
public Dimension getImageSize(final byte[] image) throws ReportExecutionException public Size getImageSize(final byte[] image) throws ReportExecutionException
{ {
return getImageSize(new ByteArrayToXInputStreamAdapter(image)); return getImageSize(new ByteArrayToXInputStreamAdapter(image));
} }

View File

@@ -17,13 +17,13 @@
*/ */
package com.sun.star.report.pentaho.output; package com.sun.star.report.pentaho.output;
import com.sun.star.awt.Size;
import com.sun.star.report.ImageService; import com.sun.star.report.ImageService;
import com.sun.star.report.InputRepository; import com.sun.star.report.InputRepository;
import com.sun.star.report.OutputRepository; import com.sun.star.report.OutputRepository;
import com.sun.star.report.ReportExecutionException; import com.sun.star.report.ReportExecutionException;
import com.sun.star.report.pentaho.DefaultNameGenerator; import com.sun.star.report.pentaho.DefaultNameGenerator;
import java.awt.Dimension;
import java.awt.Image; import java.awt.Image;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
@@ -271,7 +271,7 @@ public class ImageProducer
try try
{ {
final String mimeType = imageService.getMimeType(data); 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 // copy the image into the local output-storage
// todo: Implement data-fingerprinting so that we can detect the mime-type // todo: Implement data-fingerprinting so that we can detect the mime-type
@@ -290,8 +290,8 @@ public class ImageProducer
storage.closeOutputRepository(); storage.closeOutputRepository();
} }
final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getWidth() / 100.0); final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Width / 100.0);
final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getHeight() / 100.0); final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Height / 100.0);
final OfficeImage officeImage = new OfficeImage("Pictures/" + name, widthVal, heightVal); final OfficeImage officeImage = new OfficeImage("Pictures/" + name, widthVal, heightVal);
imageCache.put(imageKey, officeImage); imageCache.put(imageKey, officeImage);
return officeImage; return officeImage;
@@ -343,11 +343,11 @@ public class ImageProducer
inputStream.close(); inputStream.close();
} }
final byte[] data = bout.toByteArray(); final byte[] data = bout.toByteArray();
final Dimension dims = imageService.getImageSize(data); final Size dims = imageService.getImageSize(data);
final String mimeType = imageService.getMimeType(data); final String mimeType = imageService.getMimeType(data);
final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getWidth() / 100.0); final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Width / 100.0);
final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getHeight() / 100.0); final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Height / 100.0);
final String filename = copyToOutputRepository(mimeType, data); final String filename = copyToOutputRepository(mimeType, data);
final OfficeImage officeImage = new OfficeImage(filename, widthVal, heightVal); final OfficeImage officeImage = new OfficeImage(filename, widthVal, heightVal);
@@ -419,10 +419,10 @@ public class ImageProducer
} }
final byte[] data = bout.toByteArray(); final byte[] data = bout.toByteArray();
final Dimension dims = imageService.getImageSize(data); final Size dims = imageService.getImageSize(data);
final String mimeType = imageService.getMimeType(data); final String mimeType = imageService.getMimeType(data);
final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getWidth() / 100.0); final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Width / 100.0);
final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getHeight() / 100.0); final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.Height / 100.0);
if (preserveIRI) if (preserveIRI)
{ {