[Libreoffice-commits] .: 4 commits - editeng/source sax/qa sax/source xmloff/source

Michael Stahl mst at kemper.freedesktop.org
Fri Apr 20 11:55:31 PDT 2012


 editeng/source/editeng/editdoc.cxx |    4 
 sax/qa/cppunit/test_converter.cxx  |   72 +++++++++++++++++
 sax/source/tools/converter.cxx     |  155 ++++++++++++++++++++++++++++++++++---
 xmloff/source/core/xmluconv.cxx    |    2 
 4 files changed, 219 insertions(+), 14 deletions(-)

New commits:
commit ee376102becc16c0c44d23e5eb2a322aadc45197
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Apr 20 18:39:36 2012 +0200

    fdo#48969: add unit test for Converter::convertDouble

diff --git a/sax/qa/cppunit/test_converter.cxx b/sax/qa/cppunit/test_converter.cxx
index 4a3d364..a8dad87 100644
--- a/sax/qa/cppunit/test_converter.cxx
+++ b/sax/qa/cppunit/test_converter.cxx
@@ -39,11 +39,13 @@
 #include <com/sun/star/util/DateTime.hpp>
 #include <com/sun/star/util/Date.hpp>
 #include <com/sun/star/util/Duration.hpp>
+#include <com/sun/star/util/MeasureUnit.hpp>
 
 #include "sax/tools/converter.hxx"
 
 
 using namespace ::com::sun::star;
+using namespace ::com::sun::star::util::MeasureUnit;
 using sax::Converter;
 
 
@@ -58,10 +60,12 @@ public:
 
     void testDuration();
     void testDateTime();
+    void testDouble();
 
     CPPUNIT_TEST_SUITE(ConverterTest);
     CPPUNIT_TEST(testDuration);
     CPPUNIT_TEST(testDateTime);
+    CPPUNIT_TEST(testDouble);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -249,6 +253,74 @@ void ConverterTest::testDateTime()
     OSL_TRACE("\nSAX CONVERTER TEST END");
 }
 
+void doTestDouble(char const*const pis, double const rd,
+        sal_Int16 const nSourceUnit, sal_Int16 const nTargetUnit)
+{
+    ::rtl::OUString const is(::rtl::OUString::createFromAscii(pis));
+    double od;
+    bool bSuccess(Converter::convertDouble(od, is, nSourceUnit, nTargetUnit));
+    OSL_TRACE("%f", od);
+    CPPUNIT_ASSERT(bSuccess);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(rd, od, 0.00000001);
+    ::rtl::OUStringBuffer buf;
+    Converter::convertDouble(buf, od, true, nTargetUnit, nSourceUnit);
+    OSL_TRACE("%s",
+        ::rtl::OUStringToOString(buf.getStr(), RTL_TEXTENCODING_UTF8).getStr());
+    CPPUNIT_ASSERT_EQUAL(is, buf.makeStringAndClear());
+}
+
+void ConverterTest::testDouble()
+{
+    doTestDouble("42", 42.0, TWIP, TWIP);
+    doTestDouble("42", 42.0, POINT, POINT);
+    doTestDouble("42", 42.0, MM_100TH, MM_100TH);
+    doTestDouble("42", 42.0, MM_10TH, MM_10TH);
+    doTestDouble("42", 42.0, MM, MM); // identity don't seem to add unit?
+    doTestDouble("42", 42.0, CM, CM);
+    doTestDouble("42", 42.0, INCH, INCH);
+    doTestDouble("2pt", 40.0, POINT, TWIP);
+    doTestDouble("20pc", 1, TWIP, POINT);
+    doTestDouble("4", 2.26771653543307, MM_100TH, TWIP);
+    doTestDouble("4", 22.6771653543307, MM_10TH, TWIP);
+    doTestDouble("4mm", 226.771653543307, MM, TWIP);
+    doTestDouble("4cm", 2267.71653543307, CM, TWIP);
+    doTestDouble("4in", 5760.0, INCH, TWIP);
+    doTestDouble("1440pc", 1.0, TWIP, INCH);
+    doTestDouble("567pc", 1.000125, TWIP, CM);
+    doTestDouble("56.7pc", 1.000125, TWIP, MM);
+    doTestDouble("5.67pc", 1.000125, TWIP, MM_10TH);
+    doTestDouble("0.567pc", 1.000125, TWIP, MM_100TH);
+    doTestDouble("42pt", 1.4816666666666, POINT, CM);
+    doTestDouble("42pt", 14.816666666666, POINT, MM);
+    doTestDouble("42pt", 148.16666666666, POINT, MM_10TH);
+    doTestDouble("42pt", 1481.6666666666, POINT, MM_100TH);
+    doTestDouble("72pt", 1.0, POINT, INCH);
+    doTestDouble("3.5in", 8.89, INCH, CM);
+    doTestDouble("3.5in", 88.9, INCH, MM);
+    doTestDouble("3.5in", 889.0, INCH, MM_10TH);
+    doTestDouble("3.5in", 8890.0, INCH, MM_100TH);
+    doTestDouble("2in", 144, INCH, POINT);
+    doTestDouble("5.08cm", 2.0, CM, INCH);
+    doTestDouble("3.5cm", 3500.0, CM, MM_100TH);
+    doTestDouble("3.5cm", 350.0, CM, MM_10TH);
+    doTestDouble("3.5cm", 35.0, CM, MM);
+    doTestDouble("10cm", 283.464566929134, CM, POINT);
+    doTestDouble("0.5cm", 283.464566929134, CM, TWIP);
+    doTestDouble("10mm", 28.3464566929134, MM, POINT);
+    doTestDouble("0.5mm", 28.3464566929134, MM, TWIP);
+    doTestDouble("10", 2.83464566929134, MM_10TH, POINT);
+    doTestDouble("0.5", 2.83464566929134, MM_10TH, TWIP);
+    doTestDouble("10", 0.283464566929134, MM_100TH, POINT);
+    doTestDouble("0.5", 0.283464566929134, MM_100TH, TWIP);
+    doTestDouble("10mm", 1.0, MM, CM);
+    doTestDouble("10mm", 100.0, MM, MM_10TH);
+    doTestDouble("20mm", 2000.0, MM, MM_100TH);
+    doTestDouble("300", 30.0, MM_10TH, MM);
+    doTestDouble("400", 4.0, MM_100TH, MM);
+    doTestDouble("600", 6000.0, MM_10TH, MM_100TH);
+    doTestDouble("700", 70.0, MM_100TH, MM_10TH);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(ConverterTest);
 
 }
commit 62a0b2405798a3be6a4e38652f1da7a685c84bfc
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Apr 20 18:36:16 2012 +0200

    fdo#48969: GetConversionFactor: add inch as source unit
    
    Also, add whole bunch of missing cases while at it.

diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index 4fe6d7f..e8fe38e 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -1788,9 +1788,16 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
                 switch(nTargetUnit)
                 {
                     case MeasureUnit::MM_100TH:
+                    {
+                        // 0.01mm = 0.57twip (exactly)
+                        fRetval = ((25400.0 / 1440.0) / 10.0);
+                        break;
+                    }
                     case MeasureUnit::MM_10TH:
                     {
-                        OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for twip values");
+                        // 0.01mm = 0.57twip (exactly)
+                        fRetval = ((25400.0 / 1440.0) / 100.0);
+                        break;
                     }
                     case MeasureUnit::MM:
                     {
@@ -1829,31 +1836,49 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
             {
                 switch(nTargetUnit)
                 {
+                    case MeasureUnit::MM_100TH:
+                    {
+                        // 1mm = 72 / 25.4 pt (exactly)
+                        fRetval = ( 2540.0 / 72.0 );
+                        break;
+                    }
+                    case MeasureUnit::MM_10TH:
+                    {
+                        // 1mm = 72 / 25.4 pt (exactly)
+                        fRetval = ( 254.0 / 72.0 );
+                        break;
+                    }
                     case MeasureUnit::MM:
+                    {
                         // 1mm = 72 / 25.4 pt (exactly)
                         fRetval = ( 25.4 / 72.0 );
                         psUnit = gpsMM;
                         break;
 
+                    }
                     case MeasureUnit::CM:
+                    {
                         // 1cm = 72 / 2.54 pt (exactly)
                         fRetval = ( 2.54 / 72.0 );
                         psUnit = gpsCM;
                         break;
-
+                    }
                     case MeasureUnit::TWIP:
+                    {
                         // 1twip = 72 / 1440 pt (exactly)
                         fRetval = 20.0;     // 1440.0 / 72.0
                         psUnit = gpsPC;
                         break;
-
+                    }
                     case MeasureUnit::INCH:
                     default:
+                    {
                         OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for pt values");
                         // 1in = 72 pt (exactly)
                         fRetval = ( 1.0 / 72.0 );
                         psUnit = gpsINCH;
                         break;
+                    }
                 }
                 break;
             }
@@ -1862,9 +1887,9 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
                 switch(nTargetUnit)
                 {
                     case MeasureUnit::MM_100TH:
-                    case MeasureUnit::MM_10TH:
                     {
-                        OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for 1/100mm values");
+                        fRetval = 10.0;
+                        break;
                     }
                     case MeasureUnit::MM:
                     {
@@ -1875,7 +1900,6 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
                     }
                     case MeasureUnit::CM:
                     {
-                        // 0.001mm = 1 mm/100 (exactly)
                         fRetval = ((10.0 / 1.0) / 1000.0);
                         psUnit = gpsCM;
                         break;
@@ -1887,10 +1911,16 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
                         psUnit = gpsPT;
                         break;
                     }
+                    case MeasureUnit::TWIP:
+                    {
+                        fRetval = ((20.0 * 72000.0 / 2540.0) / 100.0);
+                        psUnit = gpsPC;
+                        break;
+                    }
                     case MeasureUnit::INCH:
                     default:
                     {
-                        OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for 1/100mm values");
+                        OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for 1/10mm values");
                         // 0.0001in = 0.254 mm/100 (exactly)
                         fRetval = ((100000.0 / 2540.0) / 10000.0);
                         psUnit = gpsINCH;
@@ -1903,10 +1933,10 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
             {
                 switch(nTargetUnit)
                 {
-                    case MeasureUnit::MM_100TH:
                     case MeasureUnit::MM_10TH:
                     {
-                        OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for 1/100mm values");
+                        fRetval = ((10.0 / 1.0) / 100.0);
+                        break;
                     }
                     case MeasureUnit::MM:
                     {
@@ -1917,7 +1947,6 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
                     }
                     case MeasureUnit::CM:
                     {
-                        // 0.001mm = 1 mm/100 (exactly)
                         fRetval = ((10.0 / 1.0) / 10000.0);
                         psUnit = gpsCM;
                         break;
@@ -1929,6 +1958,12 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
                         psUnit = gpsPT;
                         break;
                     }
+                    case MeasureUnit::TWIP:
+                    {
+                        fRetval = ((20.0 * 72000.0 / 2540.0) / 1000.0);
+                        psUnit = gpsPC;
+                        break;
+                    }
                     case MeasureUnit::INCH:
                     default:
                     {
@@ -1941,6 +1976,49 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
                 }
                 break;
             }
+            case MeasureUnit::MM:
+            {
+                switch(nTargetUnit)
+                {
+                    case MeasureUnit::MM_100TH:
+                    {
+                        fRetval = 100.0;
+                        break;
+                    }
+                    case MeasureUnit::MM_10TH:
+                    {
+                        fRetval = 10.0;
+                        break;
+                    }
+                    case MeasureUnit::CM:
+                    {
+                        fRetval = 0.1;
+                        psUnit = gpsCM;
+                        break;
+                    }
+                    case MeasureUnit::POINT:
+                    {
+                        fRetval = 72.0 / (2.54 * 10);
+                        psUnit = gpsPT;
+                        break;
+                    }
+                    case MeasureUnit::TWIP:
+                    {
+                        fRetval = (20.0 * 72.0) / (2.54 * 10);
+                        psUnit = gpsPC;
+                        break;
+                    }
+                    case MeasureUnit::INCH:
+                    default:
+                    {
+                        OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for cm values");
+                        fRetval = 1 / (2.54 * 10);
+                        psUnit = gpsINCH;
+                        break;
+                    }
+                }
+                break;
+            }
             case MeasureUnit::CM:
             {
                 switch(nTargetUnit)
@@ -1971,6 +2049,12 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
                         psUnit = gpsPT;
                         break;
                     }
+                    case MeasureUnit::TWIP:
+                    {
+                        fRetval = (20.0 * 72.0) / 2.54;
+                        psUnit = gpsPC;
+                        break;
+                    }
                     case MeasureUnit::INCH:
                     default:
                     {
@@ -1982,6 +2066,54 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS
                 }
                 break;
             }
+            case MeasureUnit::INCH:
+            {
+                switch (nTargetUnit)
+                {
+                    case MeasureUnit::MM_100TH:
+                    {
+                        fRetval = 2540;
+                        break;
+                    }
+                    case MeasureUnit::MM_10TH:
+                    {
+                        fRetval = 254;
+                        break;
+                    }
+                    case MeasureUnit::MM:
+                    {
+                        fRetval = 25.4;
+                        psUnit = gpsMM;
+                        break;
+                    }
+                    case MeasureUnit::CM:
+                    {
+                        fRetval = 2.54;
+                        psUnit = gpsCM;
+                        break;
+                    }
+                    case MeasureUnit::POINT:
+                    {
+                        fRetval = 72.0;
+                        psUnit = gpsPT;
+                        break;
+                    }
+                    case MeasureUnit::TWIP:
+                    {
+                        fRetval = 72.0 * 20.0;
+                        psUnit = gpsPC;
+                        break;
+                    }
+                    default:
+                    {
+                        OSL_FAIL("output unit not supported for in values");
+                        fRetval = 1;
+                        psUnit = gpsINCH;
+                        break;
+                    }
+                }
+                break;
+            }
             default:
                 OSL_ENSURE(false, "sax::Converter::GetConversionFactor(): "
                         "source unit not supported");
commit 84aeb737c7c013c8d98d8c40abfca44f6f70cee8
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Apr 20 17:22:29 2012 +0200

    fdo#48969: switch units in Converter::convertDouble
    
    The factor here is used to divide, so the parameters have to be
    switched; this has always been broken but probably before
    3ca2bef76886450058d1667703aeafe4c2e456c3 nothing called this.
    This also reverts 7bf1fa3757133f12cf6ca624f8cee6ba5363e7d8 because
    that was a workaround for the problem in the wrong place.

diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index 95f6494..4fe6d7f 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -628,8 +628,9 @@ bool Converter::convertDouble(double& rValue,
     if(eStatus == rtl_math_ConversionStatus_Ok)
     {
         OUStringBuffer sUnit;
+        // fdo#48969: switch source and target because factor is used to divide!
         double const fFactor =
-            GetConversionFactor(sUnit, nSourceUnit, nTargetUnit);
+            GetConversionFactor(sUnit, nTargetUnit, nSourceUnit);
         if(fFactor != 1.0 && fFactor != 0.0)
             rValue /= fFactor;
     }
diff --git a/xmloff/source/core/xmluconv.cxx b/xmloff/source/core/xmluconv.cxx
index f6e0621..804bdae 100644
--- a/xmloff/source/core/xmluconv.cxx
+++ b/xmloff/source/core/xmluconv.cxx
@@ -294,7 +294,7 @@ sal_Bool SvXMLUnitConverter::convertDouble(double& rValue,
                 rString, m_pImpl->m_eCoreMeasureUnit);
 
         return ::sax::Converter::convertDouble(rValue, rString,
-            m_pImpl->m_eCoreMeasureUnit, eSrcUnit);
+            eSrcUnit, m_pImpl->m_eCoreMeasureUnit);
     }
     else
     {
commit b37becd401e342bf658f9e9be69dbf7385781f45
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Apr 20 16:45:12 2012 +0200

    CharAttribList::OptimizeRanges: de-optimize to not crash so fast
    
    Crashes on import of bugdoc from fdo#48969 with
     Assertion `n < this->size()' failed.
    (regression from b35980d9b28f1e3985f94238f7d8c9962f654bd0)

diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx
index c24e72b..23549a7 100644
--- a/editeng/source/editeng/editdoc.cxx
+++ b/editeng/source/editeng/editdoc.cxx
@@ -2682,10 +2682,10 @@ void CharAttribList::ResortAttribs()
 
 void CharAttribList::OptimizeRanges( SfxItemPool& rItemPool )
 {
-    for (size_t i = 0, n = aAttribs.size(); i < n; ++i)
+    for (size_t i = 0; i < aAttribs.size(); ++i)
     {
         EditCharAttrib& rAttr = aAttribs[i];
-        for (size_t nNext = i+1; nNext < n; ++nNext)
+        for (size_t nNext = i+1; nNext < aAttribs.size(); ++nNext)
         {
             EditCharAttrib& rNext = aAttribs[nNext];
             if (!rAttr.IsFeature() && rNext.GetStart() == rAttr.GetEnd() && rNext.Which() == rAttr.Which())


More information about the Libreoffice-commits mailing list