[Libreoffice-commits] .: Branch 'libreoffice-3-5' - reportdesign/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Thu Jul 5 00:52:01 PDT 2012


 reportdesign/source/ui/inspection/GeometryHandler.cxx |   19 ++++++++++++++++++
 1 file changed, 19 insertions(+)

New commits:
commit 2c37b5ba27d5289b3ec5c0ad3273cdb7d7fa9848
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Wed Jul 4 17:46:44 2012 +0200

    fdo#43556 round pos&dim of report controls & sections to nearest 10^-4m
    
    Change-Id: I3fa331d246160935f4feed21de69f9ec0c2e9994
    Signed-off-by: Miklos Vajna <vmiklos at suse.cz>

diff --git a/reportdesign/source/ui/inspection/GeometryHandler.cxx b/reportdesign/source/ui/inspection/GeometryHandler.cxx
index fe765ca..a3d32cd 100644
--- a/reportdesign/source/ui/inspection/GeometryHandler.cxx
+++ b/reportdesign/source/ui/inspection/GeometryHandler.cxx
@@ -129,6 +129,7 @@ namespace rptui
 //........................................................................
 using namespace ::com::sun::star;
 
+namespace{
 // comparing two property instances
 struct PropertyCompare : public ::std::binary_function< beans::Property, ::rtl::OUString , bool >
 {
@@ -196,6 +197,22 @@ void lcl_convertFormulaTo(const uno::Any& _aPropertyValue,uno::Any& _rControlVal
         _rControlValue <<= aFormula.getUndecoratedContent();
     }
 }
+
+// return value rounded to the nearest multiple of base
+// if equidistant of two multiples, round up (for positive numbers)
+// T is assumed to be an integer type
+template <typename T, T base> T lcl_round(T value)
+{
+    OSL_ENSURE(value >= 0, "lcl_round: positive numbers only please");
+    const T threshold = (base % 2 == 0) ? (base/2) : (base/2 + 1);
+    const T rest = value % base;
+    if ( rest >= threshold )
+        return value + (base - rest);
+    else
+        return value - rest;
+}
+
+} // anonymous namespace
 // -----------------------------------------------------------------------------
 bool GeometryHandler::impl_isDataField(const ::rtl::OUString& _sName) const
 {
@@ -635,6 +652,8 @@ void SAL_CALL GeometryHandler::setPropertyValue(const ::rtl::OUString & Property
                 {
                     sal_Int32 nNewValue = 0;
                     Value >>= nNewValue;
+                    OSL_ENSURE(nNewValue >= 0, "A position/dimension should not be negative!");
+                    nNewValue = lcl_round<sal_Int32, 10>(nNewValue);
                     awt::Point aAwtPoint = xSourceReportComponent->getPosition();
                     awt::Size aAwtSize = xSourceReportComponent->getSize();
                     if ( nId == PROPERTY_ID_POSITIONX )


More information about the Libreoffice-commits mailing list