[Libreoffice-commits] .: Branch 'libreoffice-3-5-3' - 5 commits - sax/qa sax/source writerfilter/source xmloff/source

David Tardon dtardon at kemper.freedesktop.org
Sun Apr 22 22:31:13 PDT 2012


 sax/qa/cppunit/test_converter.cxx              |   72 +++++++++++
 sax/source/tools/converter.cxx                 |  155 +++++++++++++++++++++++--
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |    2 
 xmloff/source/core/xmluconv.cxx                |    2 
 4 files changed, 218 insertions(+), 13 deletions(-)

New commits:
commit 70ba1b80ced76c40ad5d43101db9a1f60a00011c
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Fri Apr 20 22:30:26 2012 +0200

    Minor backporting fix
    
    Signed-off-by: Michael Stahl <mstahl at redhat.com>
    Signed-off-by: Miklos Vajna <vmiklos at suse.cz>
    Signed-off-by: David Tardon <dtardon at redhat.com>

diff --git a/sax/qa/cppunit/test_converter.cxx b/sax/qa/cppunit/test_converter.cxx
index a8dad87..023177f 100644
--- a/sax/qa/cppunit/test_converter.cxx
+++ b/sax/qa/cppunit/test_converter.cxx
@@ -266,7 +266,7 @@ void doTestDouble(char const*const pis, double const rd,
     Converter::convertDouble(buf, od, true, nTargetUnit, nSourceUnit);
     OSL_TRACE("%s",
         ::rtl::OUStringToOString(buf.getStr(), RTL_TEXTENCODING_UTF8).getStr());
-    CPPUNIT_ASSERT_EQUAL(is, buf.makeStringAndClear());
+    CPPUNIT_ASSERT(buf.makeStringAndClear().equals(is));
 }
 
 void ConverterTest::testDouble()
commit 30878ae72d0881e9e3990bc6911a7e5ee4b64cd6
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Apr 20 18:39:36 2012 +0200

    fdo#48969: add unit test for Converter::convertDouble
    
    Signed-off-by: Fridrich Å trba <fridrich.strba at bluewin.ch>
    Signed-off-by: Miklos Vajna <vmiklos at suse.cz>
    Signed-off-by: David Tardon <dtardon at redhat.com>

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 cf12c5e164575935a30ce626e3b4ea59183980db
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.
    
    Signed-off-by: Fridrich Å trba <fridrich.strba at bluewin.ch>
    Signed-off-by: Miklos Vajna <vmiklos at suse.cz>
    Signed-off-by: David Tardon <dtardon at redhat.com>

diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index cf5a5b5..51be183 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -1820,9 +1820,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:
                     {
@@ -1861,31 +1868,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;
             }
@@ -1894,9 +1919,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:
                     {
@@ -1907,7 +1932,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;
@@ -1919,10 +1943,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;
@@ -1935,10 +1965,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:
                     {
@@ -1949,7 +1979,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;
@@ -1961,6 +1990,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:
                     {
@@ -1973,6 +2008,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)
@@ -2003,6 +2081,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:
                     {
@@ -2014,6 +2098,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 691325d67ef395ec9a758e5f8acc46767455ac98
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.
    
    Signed-off-by: Fridrich Å trba <fridrich.strba at bluewin.ch>
    Signed-off-by: Miklos Vajna <vmiklos at suse.cz>
    Signed-off-by: David Tardon <dtardon at redhat.com>

diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index eb22e0f..cf5a5b5 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -644,8 +644,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 6ceb885..f1ad2a1 100644
--- a/xmloff/source/core/xmluconv.cxx
+++ b/xmloff/source/core/xmluconv.cxx
@@ -340,7 +340,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 8b8d2680ca96254c606c4be023b3f0e8caacae9b
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Fri Apr 20 12:42:23 2012 +0200

    fdo#48356 fix RTF import of special unicode characters
    
    The \'0d string should not be an exception when ignoring characters
    after the \u control word.
    
    Signed-off-by: Andras Timar <atimar at suse.com>
    Signed-off-by: Caolán McNamara <caolanm at redhat.com>
    Signed-off-by: David Tardon <dtardon at redhat.com>

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 9633176..016943d 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -784,7 +784,7 @@ int RTFDocumentImpl::resolveChars(char ch)
     bool bSkipped = false;
     while(!Strm().IsEof() && ch != '{' && ch != '}' && ch != '\\')
     {
-        if (ch != 0x0d && ch != 0x0a)
+        if (m_aStates.top().nInternalState == INTERNAL_HEX || (ch != 0x0d && ch != 0x0a))
         {
             if (m_aStates.top().nCharsToSkip == 0)
             {


More information about the Libreoffice-commits mailing list