summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tlillqvist@suse.com>2012-06-18 22:32:35 +0300
committerTor Lillqvist <tlillqvist@suse.com>2012-06-18 22:38:41 +0300
commitdaaa550121a97d80e1ab43cbd5c73da6915e4ac4 (patch)
treef4842b51515bfb2c51354adb38f1b6e48839b1e9
parent8dd75128a5a7e068ae63f3d1cc6b41410f7d7122 (diff)
Pass also scale and offset to createScreenCompatibleDeviceUsingBuffer()
Pass on to VirtualDevice where used to set the MapMode of the device appropriately. Adapt DocumentLoader, use to scale the page rendering to exactly fit the virtual device. Change-Id: I4b0bc67e12114d3d9d493ff1aca2ef5d2cc78912
-rw-r--r--Library_merged.mk6
-rw-r--r--android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java90
-rw-r--r--offapi/com/sun/star/awt/XToolkit2.idl6
-rw-r--r--toolkit/Library_tk.mk6
-rw-r--r--toolkit/inc/toolkit/awt/vclxtoolkit.hxx2
-rw-r--r--toolkit/source/awt/vclxtoolkit.cxx7
-rw-r--r--touch/source/uno/Document.cxx2
-rw-r--r--vcl/inc/vcl/virdev.hxx2
-rw-r--r--vcl/source/gdi/virdev.cxx17
9 files changed, 96 insertions, 42 deletions
diff --git a/Library_merged.mk b/Library_merged.mk
index d689e42938ee..49c90cfae2ae 100644
--- a/Library_merged.mk
+++ b/Library_merged.mk
@@ -75,6 +75,12 @@ $(eval $(call gb_Library_use_libraries,merged,\
))
endif
+ifeq ($(OS),ANDROID)
+$(eval $(call gb_Library_use_libraries,merged,\
+ libotouch \
+))
+endif
+
ifeq ($(OS),MACOSX)
$(eval $(call gb_Library_use_libraries,merged,\
objc \
diff --git a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
index a458d02e90b1..412c57d1a6a3 100644
--- a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
+++ b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
@@ -44,6 +44,7 @@ import android.widget.ViewFlipper;
import com.polites.android.GestureImageView;
+import com.sun.star.awt.Size;
import com.sun.star.awt.XBitmap;
import com.sun.star.awt.XControl;
import com.sun.star.awt.XDevice;
@@ -202,40 +203,75 @@ public class DocumentLoader
ByteBuffer renderPage(int number)
{
- ByteBuffer bb;
-
- bb = ByteBuffer.allocateDirect(1024*1024*4);
- long wrapped_bb = Bootstrap.new_byte_buffer_wrapper(bb);
- Log.i(TAG, "bb is " + bb);
- XDevice device = toolkit.createScreenCompatibleDeviceUsingBuffer(1024, 1024, wrapped_bb);
+ try {
+ // A small device with no scale of offset just to find out the paper size of this page
- dumpUNOObject("device", device);
+ ByteBuffer smallbb = ByteBuffer.allocateDirect(128*128*4);
+ long wrapped_smallbb = Bootstrap.new_byte_buffer_wrapper(smallbb);
+ XDevice device = toolkit.createScreenCompatibleDeviceUsingBuffer(128, 128, 1, 1, 0, 0, wrapped_smallbb);
- PropertyValue renderProps[] = new PropertyValue[3];
- renderProps[0] = new PropertyValue();
- renderProps[0].Name = "IsPrinter";
- renderProps[0].Value = new Boolean(true);
- renderProps[1] = new PropertyValue();
- renderProps[1].Name = "RenderDevice";
- renderProps[1].Value = device;
- renderProps[2] = new PropertyValue();
- renderProps[2].Name = "View";
- renderProps[2].Value = new MyXController();
+ PropertyValue renderProps[] = new PropertyValue[3];
+ renderProps[0] = new PropertyValue();
+ renderProps[0].Name = "IsPrinter";
+ renderProps[0].Value = new Boolean(true);
+ renderProps[1] = new PropertyValue();
+ renderProps[1].Name = "RenderDevice";
+ renderProps[1].Value = device;
+ renderProps[2] = new PropertyValue();
+ renderProps[2].Name = "View";
+ renderProps[2].Value = new MyXController();
- try {
+ // getRenderer returns a set of properties that include the PageSize
long t0 = System.currentTimeMillis();
- renderable.render(number, doc, renderProps);
+ PropertyValue rendererProps[] = renderable.getRenderer(number, doc, renderProps);
long t1 = System.currentTimeMillis();
+ Log.i(TAG, "renderer properties: (took " + ((t1-t0)-timingOverhead) + " ms)");
+
+ int pageWidth = 0, pageHeight = 0;
+ for (int i = 0; i < rendererProps.length; i++) {
+ if (rendererProps[i].Name.equals("PageSize")) {
+ pageWidth = ((Size) rendererProps[i].Value).Width;
+ pageHeight = ((Size) rendererProps[i].Value).Height;
+ Log.i(TAG, " PageSize: " + pageWidth + "x" + pageHeight);
+ }
+ }
+
+ // Create a new device with the correct scale and offset
+ ByteBuffer bb = ByteBuffer.allocateDirect(1024*1024*4);
+ long wrapped_bb = Bootstrap.new_byte_buffer_wrapper(bb);
+
+ Log.i(TAG, "bb is " + bb);
+
+ if (pageWidth == 0) {
+ // Huh?
+ device = toolkit.createScreenCompatibleDeviceUsingBuffer(1024, 1024, 1, 1, 0, 0, wrapped_bb);
+ } else {
+ // Scale so that it fits our device which has a resolution of 96/in (see
+ // SvpSalGraphics::GetResolution()). The page size returned from getRenderer() is in 1/mm * 100.
+ int scaleDenumerator = Math.max(pageWidth, pageHeight) / 2540 * 96;
+ Log.i(TAG, "Scaling with 1024/" + scaleDenumerator);
+
+ device = toolkit.createScreenCompatibleDeviceUsingBuffer(1024, 1024, 1024, scaleDenumerator, 0, 0, wrapped_bb);
+ }
+
+ // Update the property that points to the device
+ renderProps[1].Value = device;
+
+ t0 = System.currentTimeMillis();
+ renderable.render(number, doc, renderProps);
+ t1 = System.currentTimeMillis();
Log.i(TAG, "Rendering page " + number + " took " + ((t1-t0)-timingOverhead) + " ms");
+
+ Bootstrap.force_full_alpha_bb(bb, 0, 1024 * 1024 * 4);
+
+ return bb;
}
catch (Exception e) {
e.printStackTrace(System.err);
- System.exit(1);
+ finish();
}
- Bootstrap.force_full_alpha_bb(bb, 0, 1024 * 1024 * 4);
-
- return bb;
+ return null;
}
class Page
@@ -415,7 +451,7 @@ public class DocumentLoader
ByteBuffer smallbb = ByteBuffer.allocateDirect(128*128*4);
long wrapped_smallbb = Bootstrap.new_byte_buffer_wrapper(smallbb);
- XDevice smalldevice = toolkit.createScreenCompatibleDeviceUsingBuffer(128, 128, wrapped_smallbb);
+ XDevice smalldevice = toolkit.createScreenCompatibleDeviceUsingBuffer(128, 128, 1, 1, 0, 0, wrapped_smallbb);
PropertyValue renderProps[] = new PropertyValue[3];
renderProps[0] = new PropertyValue();
@@ -428,8 +464,10 @@ public class DocumentLoader
renderProps[2].Name = "View";
renderProps[2].Value = new MyXController();
+ t0 = System.currentTimeMillis();
pageCount = renderable.getRendererCount(doc, renderProps);
- Log.i(TAG, "getRendererCount: " + pageCount);
+ t1 = System.currentTimeMillis();
+ Log.i(TAG, "getRendererCount: " + pageCount + ", took " + ((t1-t0)-timingOverhead) + " ms");
flipper = new ViewFlipper(this);
@@ -450,7 +488,7 @@ public class DocumentLoader
}
catch (Exception e) {
e.printStackTrace(System.err);
- System.exit(1);
+ finish();
}
}
diff --git a/offapi/com/sun/star/awt/XToolkit2.idl b/offapi/com/sun/star/awt/XToolkit2.idl
index c174d2787c4b..1c5327c6c69f 100644
--- a/offapi/com/sun/star/awt/XToolkit2.idl
+++ b/offapi/com/sun/star/awt/XToolkit2.idl
@@ -36,7 +36,11 @@ interface XToolkit2: XToolkit
com::sun::star::awt::XDevice createScreenCompatibleDeviceUsingBuffer( [in] long Width,
[in] long Height,
- [in] hyper addressOfMemoryBufferForSharedArrayWrapper );
+ [in] long ScaleNumerator,
+ [in] long ScaleDenominator,
+ [in] long XOffset,
+ [in] long YOffset,
+ [in] hyper AddressOfMemoryBufferForSharedArrayWrapper );
};
}; }; }; };
diff --git a/toolkit/Library_tk.mk b/toolkit/Library_tk.mk
index 1ba1efd4164d..ddcfa82f7a85 100644
--- a/toolkit/Library_tk.mk
+++ b/toolkit/Library_tk.mk
@@ -148,4 +148,10 @@ $(eval $(call gb_Library_use_libraries,tk,\
endif
endif
+ifeq ($(OS),ANDROID)
+$(eval $(call gb_Library_use_libraries,tk,\
+ libotouch \
+))
+endif
+
# vim: set noet sw=4 ts=4:
diff --git a/toolkit/inc/toolkit/awt/vclxtoolkit.hxx b/toolkit/inc/toolkit/awt/vclxtoolkit.hxx
index dc085b810536..6192f8f329dc 100644
--- a/toolkit/inc/toolkit/awt/vclxtoolkit.hxx
+++ b/toolkit/inc/toolkit/awt/vclxtoolkit.hxx
@@ -129,7 +129,7 @@ public:
~VCLXToolkit();
// ::com::sun::star::awt::XToolkit2
- ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > SAL_CALL createScreenCompatibleDeviceUsingBuffer( sal_Int32 Width, sal_Int32 Height, sal_Int64 addressOfMemoryBufferForSharedArrayWrapper ) throw
+ ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > SAL_CALL createScreenCompatibleDeviceUsingBuffer( sal_Int32 Width, sal_Int32 Height, sal_Int32 ScaleNumerator, sal_Int32 ScaleDenominator, sal_Int32 XOffset, sal_Int32 YOffset, sal_Int64 AddressOfMemoryBufferForSharedArrayWrapper ) throw
(::com::sun::star::uno::RuntimeException);
// ::com::sun::star::awt::XToolkit
diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx
index c799393daac7..e027b235a21f 100644
--- a/toolkit/source/awt/vclxtoolkit.cxx
+++ b/toolkit/source/awt/vclxtoolkit.cxx
@@ -567,10 +567,10 @@ void SAL_CALL VCLXToolkit::disposing()
::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) throw(::com::sun::star::uno::RuntimeException)
{
- return createScreenCompatibleDeviceUsingBuffer( Width, Height, 0 );
+ return createScreenCompatibleDeviceUsingBuffer( Width, Height, 1, 1, 0, 0, 0 );
}
-::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXToolkit::createScreenCompatibleDeviceUsingBuffer( sal_Int32 Width, sal_Int32 Height, sal_Int64 addressOfMemoryBufferForSharedArrayWrapper ) throw(::com::sun::star::uno::RuntimeException)
+::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXToolkit::createScreenCompatibleDeviceUsingBuffer( sal_Int32 Width, sal_Int32 Height, sal_Int32 ScaleNumerator, sal_Int32 ScaleDenominator, sal_Int32 XOffset, sal_Int32 YOffset, sal_Int64 addressOfMemoryBufferForSharedArrayWrapper ) throw(::com::sun::star::uno::RuntimeException)
{
::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
@@ -583,7 +583,8 @@ void SAL_CALL VCLXToolkit::disposing()
if ( addressOfMemoryBufferForSharedArrayWrapper != 0 ) {
#if defined(ANDROID)
ByteBufferWrapper *bbw = (ByteBufferWrapper *) (intptr_t) addressOfMemoryBufferForSharedArrayWrapper;
- pV->SetOutputSizePixelAndBuffer( Size( Width, Height ), basebmp::RawMemorySharedArray( bbw->pointer(), *bbw ));
+ pV->SetOutputSizePixelScaleOffsetAndBuffer( Size( Width, Height ), Fraction(ScaleNumerator, ScaleDenominator), Point( XOffset, YOffset), basebmp::RawMemorySharedArray( bbw->pointer(), *bbw ));
+#else
OSL_FAIL( "rendering to a pre-allocated buffer not done yet for this OS" );
#endif
} else {
diff --git a/touch/source/uno/Document.cxx b/touch/source/uno/Document.cxx
index 5163ef4b28e7..506e4e55f12a 100644
--- a/touch/source/uno/Document.cxx
+++ b/touch/source/uno/Document.cxx
@@ -216,7 +216,7 @@ public:
selection <<= m_xComponent;
- uno::Reference< awt::XDevice > device( m_xToolkit->createScreenCompatibleDeviceUsingBuffer( width, height, buffer ) );
+ uno::Reference< awt::XDevice > device( m_xToolkit->createScreenCompatibleDeviceUsingBuffer( width, height, 1, 1, 0, 0, buffer ) );
beans::PropertyValues renderProps;
diff --git a/vcl/inc/vcl/virdev.hxx b/vcl/inc/vcl/virdev.hxx
index 32a316721dcb..9a5b01d2c130 100644
--- a/vcl/inc/vcl/virdev.hxx
+++ b/vcl/inc/vcl/virdev.hxx
@@ -106,7 +106,7 @@ public:
virtual ~VirtualDevice();
sal_Bool SetOutputSizePixel( const Size& rNewSize, sal_Bool bErase = sal_True );
- sal_Bool SetOutputSizePixelAndBuffer( const Size& rNewSize, const basebmp::RawMemorySharedArray &pBuffer );
+ sal_Bool SetOutputSizePixelScaleOffsetAndBuffer( const Size& rNewSize, const Fraction& rScale, const Point& rNewOffset, const basebmp::RawMemorySharedArray &pBuffer );
sal_Bool SetOutputSize( const Size& rNewSize, sal_Bool bErase = sal_True )
{ return SetOutputSizePixel( LogicToPixel( rNewSize ), bErase ); }
diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx
index 93aec4fd94e1..2c67355888f2 100644
--- a/vcl/source/gdi/virdev.cxx
+++ b/vcl/source/gdi/virdev.cxx
@@ -368,16 +368,15 @@ sal_Bool VirtualDevice::SetOutputSizePixel( const Size& rNewSize, sal_Bool bEras
return ImplSetOutputSizePixel( rNewSize, bErase, basebmp::RawMemorySharedArray() );
}
-sal_Bool VirtualDevice::SetOutputSizePixelAndBuffer( const Size& rNewSize, const basebmp::RawMemorySharedArray &pBuffer )
+sal_Bool VirtualDevice::SetOutputSizePixelScaleOffsetAndBuffer( const Size& rNewSize, const Fraction& rScale, const Point& rNewOffset, const basebmp::RawMemorySharedArray &pBuffer )
{
- // Is this the place to put in scaling and offsetting, passed in as parameters from createScreenCompatibleDeviceUsingBuffer?
- // Bogus test just to see that something happens:
- // if (pBuffer) {
- // MapMode mm = GetMapMode();
- // mm.SetScaleX(Fraction(4, 1));
- // mm.SetScaleY(Fraction(4, 1));
- // SetMapMode(mm);
- //}
+ if (pBuffer) {
+ MapMode mm = GetMapMode();
+ mm.SetOrigin( rNewOffset );
+ mm.SetScaleX( rScale );
+ mm.SetScaleY( rScale );
+ SetMapMode( mm );
+ }
return ImplSetOutputSizePixel( rNewSize, sal_True, pBuffer);
}