sw/qa/extras/rtfexport/data/custom-doc-props.rtf | 6 ++++ sw/qa/extras/rtfexport/rtfexport.cxx | 9 ++++++ sw/source/filter/ww8/rtfexport.cxx | 32 +++++++++++++++++++++-- writerfilter/source/rtftok/rtfdispatchvalue.cxx | 6 ++++ writerfilter/source/rtftok/rtfdocumentimpl.cxx | 27 +++++++++++++++++++ 5 files changed, 78 insertions(+), 2 deletions(-)
New commits: commit 51c400dc4cd6a88c01b245e41d0de737d4df4017 Author: Miklos Vajna <[email protected]> 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 diff --git a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf index 361631d..8c921e4 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 fa544ac..ce74f91 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 dd3490b..fd8ade2 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -538,8 +538,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 0cefa01..8c6075e 100644 --- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx +++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx @@ -1397,6 +1397,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 09c84a0..c113167 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -2712,6 +2712,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 07b0cde32a7eebce996b8c32aa58545e4ec15003 Author: Miklos Vajna <[email protected]> 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 diff --git a/sw/qa/extras/rtfexport/data/custom-doc-props.rtf b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf index e774659..361631d 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 27ca1af..fa544ac 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 e0fef9b..dd3490b 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -524,6 +524,7 @@ void RtfExport::WriteUserProps() OUString aValue; double fValue; bool bValue; + util::DateTime aDate; uno::Any aAny = xPropertySet->getPropertyValue(rProperty.Name); if (aAny >>= bValue) { @@ -540,6 +541,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 eaa845e..0cefa01 100644 --- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx +++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx @@ -1403,6 +1403,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 80859bf..09c84a0 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -51,6 +51,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 @@ -2687,6 +2710,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); } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
