[Libreoffice-commits] .: Branch 'libreoffice-3-6' - reportbuilder/java

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Aug 29 20:29:07 PDT 2012


 reportbuilder/java/com/sun/star/report/ImageService.java                 |    6 +-
 reportbuilder/java/com/sun/star/report/SOImageService.java               |   21 +++++-----
 reportbuilder/java/com/sun/star/report/pentaho/output/ImageProducer.java |   20 ++++-----
 3 files changed, 24 insertions(+), 23 deletions(-)

New commits:
commit 3f8da6ae8b6584cf6a95fc9b1f4f9045270c0555
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Aug 23 14:25:41 2012 +0200

    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
    Signed-off-by: Lionel Elie Mamane <lionel at mamane.lu>

diff --git a/reportbuilder/java/com/sun/star/report/ImageService.java b/reportbuilder/java/com/sun/star/report/ImageService.java
index d7224ed..cdec26c 100644
--- a/reportbuilder/java/com/sun/star/report/ImageService.java
+++ b/reportbuilder/java/com/sun/star/report/ImageService.java
@@ -26,7 +26,7 @@
  ************************************************************************/
 package com.sun.star.report;
 
-import java.awt.Dimension;
+import com.sun.star.awt.Size;
 
 import java.io.InputStream;
 
@@ -57,7 +57,7 @@ public interface ImageService
      *
      * @throws ReportExecutionException
      * @return*/
-    Dimension getImageSize(final InputStream image) throws ReportExecutionException;
+    Size getImageSize(final InputStream image) throws ReportExecutionException;
 
     /**
      * @param image
@@ -65,6 +65,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 6d67eba..862f761 100644
--- a/reportbuilder/java/com/sun/star/report/SOImageService.java
+++ b/reportbuilder/java/com/sun/star/report/SOImageService.java
@@ -41,8 +41,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;
 
 
@@ -78,14 +76,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[]
@@ -105,13 +103,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"))
@@ -119,7 +119,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);
                 }
             }
         }
@@ -130,7 +131,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 b3d6485..51a4b66 100644
--- a/reportbuilder/java/com/sun/star/report/pentaho/output/ImageProducer.java
+++ b/reportbuilder/java/com/sun/star/report/pentaho/output/ImageProducer.java
@@ -26,13 +26,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;
@@ -280,7 +280,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
@@ -299,8 +299,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;
@@ -352,11 +352,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);
@@ -428,10 +428,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)
             {


More information about the Libreoffice-commits mailing list