Kaydet (Commit) daaa5501 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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
üst 8dd75128
......@@ -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 \
......
......@@ -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();
}
}
......
......@@ -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 );
};
}; }; }; };
......
......@@ -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:
......@@ -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
......
......@@ -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 {
......
......@@ -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;
......
......@@ -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 ); }
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment