summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-12-08 15:19:06 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-12-09 08:10:40 +0100
commit07b0cde32a7eebce996b8c32aa58545e4ec15003 (patch)
tree53ff7c9317281e6ba7ee227d4a850989935fa746
parent547de17fcb654e560a60d683c33482feeee84358 (diff)
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
-rw-r--r--sw/qa/extras/rtfexport/data/custom-doc-props.rtf3
-rw-r--r--sw/qa/extras/rtfexport/rtfexport.cxx6
-rw-r--r--sw/source/filter/ww8/rtfexport.cxx17
-rw-r--r--writerfilter/source/rtftok/rtfdispatchvalue.cxx3
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx25
5 files changed, 54 insertions, 0 deletions
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 27ca1af122b3..fa544ac7628f 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 e0fef9bace43..dd3490b69c40 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 eaa845ebc787..0cefa0114505 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 80859bfd1541..09c84a0d9eb3 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);
}