From 8e2308c3ff142e3b7232908bacdcdb85ac1f9683 Mon Sep 17 00:00:00 2001 From: Frank Schönheit Date: Thu, 17 Sep 2009 21:11:28 +0000 Subject: setZoom: care for rounding errors which occur during implicit conversion from float to double --- toolkit/source/awt/vclxwindow.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'toolkit') diff --git a/toolkit/source/awt/vclxwindow.cxx b/toolkit/source/awt/vclxwindow.cxx index 93486d86e739..501ed7f009f1 100644 --- a/toolkit/source/awt/vclxwindow.cxx +++ b/toolkit/source/awt/vclxwindow.cxx @@ -2586,7 +2586,14 @@ void VCLXWindow::setZoom( float fZoomX, float /*fZoomY*/ ) throw(::com::sun::sta ::vos::OGuard aGuard( GetMutex() ); if ( GetWindow() ) - GetWindow()->SetZoom( Fraction( fZoomX ) ); + { + // Fraction::Fraction takes a double, but we have a float only. + // The implicit conversion from float to double can result in a precision loss, i.e. 1.2 is converted to + // 1.200000000047something. To prevent this, we convert explicitly to double, and round it. + double nZoom( fZoomX ); + nZoom = ::rtl::math::round( nZoom, 4 ); + GetWindow()->SetZoom( Fraction( nZoom ) ); + } } // ::com::sun::star::lang::XEventListener -- cgit v1.2.3