sw/qa/extras/rtfexport/data/custom-doc-props.rtf | 15 +++++ sw/qa/extras/rtfexport/rtfexport.cxx | 15 +++++ sw/source/filter/ww8/rtfexport.cxx | 67 +++++++++++++++++++---- sw/source/filter/ww8/rtfexport.hxx | 4 + writerfilter/source/rtftok/rtfdispatchvalue.cxx | 12 ++++ writerfilter/source/rtftok/rtfdocumentimpl.cxx | 31 ++++++++++ 6 files changed, 135 insertions(+), 9 deletions(-)
New commits: commit dc3ab0c5e493276bc5500c10437491e9c312f676 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Thu Dec 8 17:25:07 2016 +0100 RTF filter: handle user-defined document properties of type double This was the last unhandled type. Change-Id: Ife9b93ac81ddab9409c6790228eec03e92920e01 (cherry picked from commit 51c400dc4cd6a88c01b245e41d0de737d4df4017) diff --git a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf index 361631d6ab3b..8c921e45a475 100644 --- a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf +++ b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf @@ -18,5 +18,8 @@ {\propname d} \proptype64 {\staticval 2016. 01. 30.} +{\propname pi} +\proptype5 +{\staticval 3.14} } } diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 4b8a3ec4083a..93679768cfd9 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -1020,6 +1020,9 @@ DECLARE_RTFEXPORT_TEST(testCustomDocProps, "custom-doc-props.rtf") CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(2016), aDate.Year); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), aDate.Month); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(30), aDate.Day); + + // Test real number. + CPPUNIT_ASSERT_EQUAL(3.14, getProperty<double>(xUserDefinedProperties, "pi")); } DECLARE_RTFEXPORT_TEST(testTdf65642, "tdf65642.rtf") diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 53fcc34f06d5..d0b7c857b737 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -542,8 +542,19 @@ void RtfExport::WriteUserProps() } else if (aAny >>= fValue) { - WriteUserPropType(3); - WriteUserPropValue(OUString::number(fValue)); + aValue = OUString::number(fValue); + if (aValue.indexOf('.') == -1) + { + // Integer. + WriteUserPropType(3); + WriteUserPropValue(aValue); + } + else + { + // Real number. + WriteUserPropType(5); + WriteUserPropValue(aValue); + } } else if (aAny >>= aDate) { diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx index b10ac6e2a022..809976a628ce 100644 --- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx +++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx @@ -1396,6 +1396,9 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) case 3: m_aStates.top().aPropType = cppu::UnoType<sal_Int32>::get(); break; + case 5: + m_aStates.top().aPropType = cppu::UnoType<double>::get(); + break; case 11: m_aStates.top().aPropType = cppu::UnoType<bool>::get(); break; diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 6fd58c4550a0..d6e2998a465e 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -2734,6 +2734,8 @@ RTFError RTFDocumentImpl::popState() aAny = uno::makeAny(aStaticVal.toBoolean()); else if (m_aStates.top().aPropType == cppu::UnoType<util::DateTime>::get()) aAny = uno::makeAny(getDateTimeFromUserProp(aStaticVal)); + else if (m_aStates.top().aPropType == cppu::UnoType<double>::get()) + aAny = uno::makeAny(aStaticVal.toDouble()); xPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aAny); } commit 0e4108cf1e1f7be7e236acd189b01460fa55d5c4 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Thu Dec 8 15:19:06 2016 +0100 RTF filter: handle user-defined document properties of type date The date format is undefined by the RTF spec, but Word seems to work with 'YYYY. MM. DD.'. Change-Id: I79a10984963851c86cba92892eab13cec1e37072 (cherry picked from commit 07b0cde32a7eebce996b8c32aa58545e4ec15003) diff --git a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf index e774659bbf56..361631d6ab3b 100644 --- a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf +++ b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf @@ -15,5 +15,8 @@ {\propname bn} \proptype11 {\staticval 0} +{\propname d} +\proptype64 +{\staticval 2016. 01. 30.} } } diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 1f9df4a3c6bb..4b8a3ec4083a 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -1014,6 +1014,12 @@ DECLARE_RTFEXPORT_TEST(testCustomDocProps, "custom-doc-props.rtf") CPPUNIT_ASSERT(getProperty<bool>(xUserDefinedProperties, "by")); // Test boolean "no". CPPUNIT_ASSERT(!getProperty<bool>(xUserDefinedProperties, "bn")); + + // Test roundtrip of date in general, and year/month/day in particular. + util::DateTime aDate = getProperty<util::DateTime>(xUserDefinedProperties, "d"); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(2016), aDate.Year); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), aDate.Month); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(30), aDate.Day); } DECLARE_RTFEXPORT_TEST(testTdf65642, "tdf65642.rtf") diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index d32697fafcc8..53fcc34f06d5 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -528,6 +528,7 @@ void RtfExport::WriteUserProps() OUString aValue; double fValue; bool bValue; + util::DateTime aDate; uno::Any aAny = xPropertySet->getPropertyValue(rProperty.Name); if (aAny >>= bValue) { @@ -544,6 +545,22 @@ void RtfExport::WriteUserProps() WriteUserPropType(3); WriteUserPropValue(OUString::number(fValue)); } + else if (aAny >>= aDate) + { + WriteUserPropType(64); + // Format is 'YYYY. MM. DD.'. + aValue += OUString::number(aDate.Year); + aValue += ". "; + if (aDate.Month < 10) + aValue += "0"; + aValue += OUString::number(aDate.Month); + aValue += ". "; + if (aDate.Day < 10) + aValue += "0"; + aValue += OUString::number(aDate.Day); + aValue += "."; + WriteUserPropValue(aValue); + } } } diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx index ef9c9ab89f67..b10ac6e2a022 100644 --- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx +++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx @@ -1402,6 +1402,9 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) case 30: m_aStates.top().aPropType = cppu::UnoType<OUString>::get(); break; + case 64: + m_aStates.top().aPropType = cppu::UnoType<util::DateTime>::get(); + break; } } break; diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index b9d67beb86a5..6fd58c4550a0 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -50,6 +50,29 @@ using namespace com::sun::star; +namespace +{ +/// Returns an util::DateTime from a 'YYYY. MM. DD.' string. +util::DateTime getDateTimeFromUserProp(const OUString& rString) +{ + util::DateTime aRet; + sal_Int32 nLen = rString.getLength(); + if (nLen >= 4) + { + aRet.Year = rString.copy(0, 4).toInt32(); + + if (nLen >= 8 && rString.copy(4, 2) == ". ") + { + aRet.Month = rString.copy(6, 2).toInt32(); + + if (nLen >= 12 && rString.copy(8, 2) == ". ") + aRet.Day = rString.copy(10, 2).toInt32(); + } + } + return aRet; +} +} // anonymous namespace + namespace writerfilter { namespace rtftok @@ -2709,6 +2732,8 @@ RTFError RTFDocumentImpl::popState() aAny = uno::makeAny(aStaticVal.toInt32()); else if (m_aStates.top().aPropType == cppu::UnoType<bool>::get()) aAny = uno::makeAny(aStaticVal.toBoolean()); + else if (m_aStates.top().aPropType == cppu::UnoType<util::DateTime>::get()) + aAny = uno::makeAny(getDateTimeFromUserProp(aStaticVal)); xPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aAny); } commit 45e5d04b9b932b02d280983f87aa61bc0d28c35c Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Thu Dec 8 14:33:41 2016 +0100 RTF filter: handle user-defined document properties of type bool Next to number and string. Change-Id: I76f78197412606f00559c1c2790b7c70117ef1c1 Reviewed-on: https://gerrit.libreoffice.org/31767 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> (cherry picked from commit 547de17fcb654e560a60d683c33482feeee84358) diff --git a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf index 3e6eee854f8c..e774659bbf56 100644 --- a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf +++ b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf @@ -9,5 +9,11 @@ {\propname n} \proptype3 {\staticval 42} +{\propname by} +\proptype11 +{\staticval 1} +{\propname bn} +\proptype11 +{\staticval 0} } } diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index ae46296c64bc..1f9df4a3c6bb 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -1010,6 +1010,10 @@ DECLARE_RTFEXPORT_TEST(testCustomDocProps, "custom-doc-props.rtf") 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")); + // Test boolean "yes". + CPPUNIT_ASSERT(getProperty<bool>(xUserDefinedProperties, "by")); + // Test boolean "no". + CPPUNIT_ASSERT(!getProperty<bool>(xUserDefinedProperties, "bn")); } DECLARE_RTFEXPORT_TEST(testTdf65642, "tdf65642.rtf") diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index b7d44ca0cec5..d32697fafcc8 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -473,6 +473,12 @@ void RtfExport::WriteInfo() Strm().WriteChar('}'); } +void RtfExport::WriteUserPropType(int nType) +{ + Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PROPTYPE); + OutULong(nType); +} + void RtfExport::WriteUserPropValue(const OUString& rValue) { Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_STATICVAL " "); @@ -521,17 +527,21 @@ void RtfExport::WriteUserProps() // Property value. OUString aValue; double fValue; + bool bValue; uno::Any aAny = xPropertySet->getPropertyValue(rProperty.Name); - if (aAny >>= aValue) + if (aAny >>= bValue) + { + WriteUserPropType(11); + WriteUserPropValue(OUString::number(static_cast<int>(bValue))); + } + else if (aAny >>= aValue) { - Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PROPTYPE); - OutULong(30); + WriteUserPropType(30); WriteUserPropValue(aValue); } else if (aAny >>= fValue) { - Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PROPTYPE); - OutULong(3); + WriteUserPropType(3); WriteUserPropValue(OUString::number(fValue)); } } diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx index 609f33776d3a..89912f80d2ff 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 type. + void WriteUserPropType(int nType); /// Writes a single user property value. void WriteUserPropValue(const OUString& rValue); /// Writes the userprops group: user defined document properties. diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx index 611ed768c734..ef9c9ab89f67 100644 --- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx +++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx @@ -1396,6 +1396,9 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) case 3: m_aStates.top().aPropType = cppu::UnoType<sal_Int32>::get(); break; + case 11: + m_aStates.top().aPropType = cppu::UnoType<bool>::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 2dd9728b6254..b9d67beb86a5 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -2707,6 +2707,8 @@ RTFError RTFDocumentImpl::popState() aAny = uno::makeAny(aStaticVal); else if (m_aStates.top().aPropType == cppu::UnoType<sal_Int32>::get()) aAny = uno::makeAny(aStaticVal.toInt32()); + else if (m_aStates.top().aPropType == cppu::UnoType<bool>::get()) + aAny = uno::makeAny(aStaticVal.toBoolean()); xPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aAny); } commit 057d3be6e30b66501c698a9de8ec8f892152dc10 Author: Miklos Vajna <vmik...@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 (cherry picked from commit fc8c4606e0834cd2128a228c2c95fc7c8f9eb7b1) diff --git a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf index b36d864f2969..3e6eee854f8c 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 5ca24e1c3324..ae46296c64bc 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 2cd959a8643c..b7d44ca0cec5 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -473,6 +473,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); @@ -511,18 +518,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 ecef9ee60217..609f33776d3a 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 b6672901742c..611ed768c734 100644 --- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx +++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx @@ -1393,6 +1393,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 a1df2d08ee76..2dd9728b6254 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -2705,6 +2705,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); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits