javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/graphics/gfxos.cpp
changeset 56 abc41079b313
parent 49 35baca0e7a2e
child 57 59b3b4473dc8
--- a/javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/graphics/gfxos.cpp	Fri Jul 09 16:35:45 2010 +0300
+++ b/javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/graphics/gfxos.cpp	Fri Jul 23 12:27:20 2010 +0300
@@ -11,6 +11,11 @@
 #include <QFont>
 #include <QFontMetrics>
 #include <QSharedDataPointer>
+#include <QByteArray>
+#include <QBuffer>
+#include <QImageReader>
+#include <QSize>
+#include <QSvgRenderer>
 
 #include <org_eclipse_swt_internal_qt_graphics_OS.h>
 #include "graphics.h"
@@ -1244,6 +1249,46 @@
     GFX_CATCH
 }
 
+JNIEXPORT jobject JNICALL Java_org_eclipse_swt_internal_qt_graphics_OS_imageLoader_1getImageSize
+  (JNIEnv *aJniEnv, jclass, jbyteArray aData)
+{
+    jobject size = NULL;
+    GFX_TRY
+    {
+        SWT_LOG_JNI_CALL();
+        
+        jbyte* data = NULL;
+        data = aJniEnv->GetByteArrayElements(aData, NULL);
+        int length = aJniEnv->GetArrayLength(aData);
+        
+        QByteArray array = QByteArray::fromRawData(reinterpret_cast<const char*>(data), length);
+        QBuffer buffer(&array);
+        buffer.open(QIODevice::ReadOnly);
+
+        // Initialize imageReader
+        QImageReader imgReader(&buffer);
+        QSize imageSize(-1,-1);
+        
+        if (imgReader.supportsOption(QImageIOHandler::Size))
+        {
+            imageSize = imgReader.size();
+        }
+        else //if (imgReader.format() == "svg") 
+        {
+            // Qt SVG plugin does not support QImageIOHandler::Size option, 
+            // use QSvgRenderer to get the default size of the image instead.
+            QSvgRenderer svg(array);
+            imageSize = svg.defaultSize();
+        }
+        
+        size = swtApp->jniUtils().NewJavaPoint( aJniEnv, QPoint(imageSize.width(), imageSize.height()));
+        
+        aJniEnv->ReleaseByteArrayElements(aData, data, JNI_ABORT);
+    }
+    GFX_CATCH
+    
+    return size;
+}
 //
 // FontUtils
 //