[Libreoffice-commits] core.git: sw/qa sw/source writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Dec 8 12:39:26 UTC 2016


 sw/qa/extras/rtfexport/data/custom-doc-props.rtf |    3 ++
 sw/qa/extras/rtfexport/rtfexport.cxx             |    2 +
 sw/source/filter/ww8/rtfexport.cxx               |   25 ++++++++++++++++-------
 sw/source/filter/ww8/rtfexport.hxx               |    2 +
 writerfilter/source/rtftok/rtfdispatchvalue.cxx  |    3 ++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx   |    2 +
 6 files changed, 30 insertions(+), 7 deletions(-)

New commits:
commit fc8c4606e0834cd2128a228c2c95fc7c8f9eb7b1
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Dec 8 12:19:27 2016 +0100

    RTF filter: handle user-defined document properties of type number
    
    Previously only strings were handled.
    
    Change-Id: I2452cbabf48bfaa9f1a3044be4b8cbe4aa9dd0d9

diff --git a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf
index b36d864..3e6eee8 100644
--- a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf
+++ b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf
@@ -6,5 +6,8 @@
 {\propname urn:bails:IntellectualProperty:Authorization:StopValidity}
 \proptype30
 {\staticval None}
+{\propname n}
+\proptype3
+{\staticval 42}
 }
 }
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index 37e9ba7..2420cb0 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -1008,6 +1008,8 @@ DECLARE_RTFEXPORT_TEST(testCustomDocProps, "custom-doc-props.rtf")
     uno::Reference<beans::XPropertyContainer> xUserDefinedProperties = xDocumentProperties->getUserDefinedProperties();
     CPPUNIT_ASSERT_EQUAL(OUString("2016-03-08T10:55:18,531376147"), getProperty<OUString>(xUserDefinedProperties, "urn:bails:IntellectualProperty:Authorization:StartValidity"));
     CPPUNIT_ASSERT_EQUAL(OUString("None"), getProperty<OUString>(xUserDefinedProperties, "urn:bails:IntellectualProperty:Authorization:StopValidity"));
+    // Test roundtrip of numbers. This failed as getProperty() did not find "n".
+    CPPUNIT_ASSERT_EQUAL(42.0, getProperty<double>(xUserDefinedProperties, "n"));
 }
 
 DECLARE_RTFEXPORT_TEST(testTdf65642, "tdf65642.rtf")
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index 5e31a3c..bcc8fce 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -469,6 +469,13 @@ void RtfExport::WriteInfo()
     Strm().WriteChar('}');
 }
 
+void RtfExport::WriteUserPropValue(const OUString& rValue)
+{
+    Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_STATICVAL " ");
+    Strm().WriteCharPtr(msfilter::rtfutil::OutString(rValue, m_eDefaultEncoding).getStr());
+    Strm().WriteChar('}');
+}
+
 void RtfExport::WriteUserProps()
 {
     Strm().WriteChar('{').WriteCharPtr(OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_USERPROPS);
@@ -507,18 +514,22 @@ void RtfExport::WriteUserProps()
                 Strm().WriteCharPtr(msfilter::rtfutil::OutString(rProperty.Name, m_eDefaultEncoding).getStr());
                 Strm().WriteChar('}');
 
-                // Property value type.
+                // Property value.
                 OUString aValue;
-                if (xPropertySet->getPropertyValue(rProperty.Name) >>= aValue)
+                double fValue;
+                uno::Any aAny = xPropertySet->getPropertyValue(rProperty.Name);
+                if (aAny >>= aValue)
                 {
                     Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PROPTYPE);
                     OutULong(30);
+                    WriteUserPropValue(aValue);
+                }
+                else if (aAny >>= fValue)
+                {
+                    Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PROPTYPE);
+                    OutULong(3);
+                    WriteUserPropValue(OUString::number(fValue));
                 }
-
-                // Property value.
-                Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_STATICVAL " ");
-                Strm().WriteCharPtr(msfilter::rtfutil::OutString(aValue, m_eDefaultEncoding).getStr());
-                Strm().WriteChar('}');
             }
         }
 
diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx
index 71c55f0..a399f47 100644
--- a/sw/source/filter/ww8/rtfexport.hxx
+++ b/sw/source/filter/ww8/rtfexport.hxx
@@ -204,6 +204,8 @@ private:
     void WriteFootnoteSettings();
     void WriteMainText();
     void WriteInfo();
+    /// Writes a single user property value.
+    void WriteUserPropValue(const OUString& rValue);
     /// Writes the userprops group: user defined document properties.
     void WriteUserProps();
     /// Writes the writer-specific \pgdsctbl group.
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index 0a77075..dc49e64 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -1394,6 +1394,9 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
     {
         switch (nParam)
         {
+        case 3:
+            m_aStates.top().aPropType = cppu::UnoType<sal_Int32>::get();
+            break;
         case 30:
             m_aStates.top().aPropType = cppu::UnoType<OUString>::get();
             break;
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index a65d7b6..c92e3a9 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -2683,6 +2683,8 @@ RTFError RTFDocumentImpl::popState()
             uno::Any aAny;
             if (m_aStates.top().aPropType == cppu::UnoType<OUString>::get())
                 aAny = uno::makeAny(aStaticVal);
+            else if (m_aStates.top().aPropType == cppu::UnoType<sal_Int32>::get())
+                aAny = uno::makeAny(aStaticVal.toInt32());
 
             xPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aAny);
         }


More information about the Libreoffice-commits mailing list