[Libreoffice-commits] core.git: Branch 'libreoffice-7-1' - writerfilter/CppunitTest_writerfilter_dmapper.mk writerfilter/qa writerfilter/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Tue Feb 9 10:05:45 UTC 2021
writerfilter/CppunitTest_writerfilter_dmapper.mk | 1
writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx | 23 ++++++++++
writerfilter/qa/cppunittests/dmapper/data/create-date-preserve.docx |binary
writerfilter/source/dmapper/DomainMapper_Impl.cxx | 7 +++
4 files changed, 31 insertions(+)
New commits:
commit 793fc8c7c70faec4e6c1e9ad0c4d9f47193a181c
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Feb 8 21:03:04 2021 +0100
Commit: Michael Stahl <michael.stahl at allotropia.de>
CommitDate: Tue Feb 9 11:05:11 2021 +0100
tdf#134592 DOCX import: preserve formatting of CREATEDATE fields
The create date of a document doesn't really change, so we can only
loose if the cached result of the field is not preserved.
(cherry picked from commit 3b928391b3398c1113e675ea6a542d05d9611e0a)
Change-Id: I0105d9c5bb9a06cacc1f5fed2a10b6626fa80fd7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110622
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl at allotropia.de>
diff --git a/writerfilter/CppunitTest_writerfilter_dmapper.mk b/writerfilter/CppunitTest_writerfilter_dmapper.mk
index 7fe8b9035d3d..48b4ee87e087 100644
--- a/writerfilter/CppunitTest_writerfilter_dmapper.mk
+++ b/writerfilter/CppunitTest_writerfilter_dmapper.mk
@@ -33,6 +33,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerfilter_dmapper, \
sal \
test \
unotest \
+ vcl \
))
$(eval $(call gb_CppunitTest_use_sdk_api,writerfilter_dmapper))
diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
index 77bd616f37d6..da7501e2ef2e 100644
--- a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
@@ -19,6 +19,8 @@
#include <com/sun/star/text/XTextTablesSupplier.hpp>
#include <com/sun/star/text/XTextTable.hpp>
+#include <vcl/scheduler.hxx>
+
using namespace ::com::sun::star;
namespace
@@ -189,6 +191,27 @@ CPPUNIT_TEST_FIXTURE(Test, testFieldIfInsideIf)
// i.e. some of the inner fields escaped outside the outer field.
CPPUNIT_ASSERT_EQUAL(OUString("25"), xCell->getString());
}
+
+CPPUNIT_TEST_FIXTURE(Test, testCreateDatePreserve)
+{
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "create-date-preserve.docx";
+ getComponent() = loadFromDesktop(aURL);
+ // Trigger idle layout.
+ Scheduler::ProcessEventsToIdle();
+ uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
+ uno::Reference<container::XEnumerationAccess> xPortionEnumAccess(xParaEnum->nextElement(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xPortionEnum = xPortionEnumAccess->createEnumeration();
+ uno::Reference<text::XTextRange> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 7/7/2020 10:11:00 AM
+ // - Actual : 07/07/2020
+ // i.e. the formatting of the create date field was lost.
+ CPPUNIT_ASSERT_EQUAL(OUString("7/7/2020 10:11:00 AM"), xPortion->getString());
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/qa/cppunittests/dmapper/data/create-date-preserve.docx b/writerfilter/qa/cppunittests/dmapper/data/create-date-preserve.docx
new file mode 100644
index 000000000000..4a587ce0d2ef
Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/create-date-preserve.docx differ
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 580de1b9730c..0aee6c1d6598 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -6245,6 +6245,13 @@ void DomainMapper_Impl::SetFieldResult(OUString const& rResult)
xFieldProperties->setPropertyValue(
getPropertyName(bHasContent && sValue.isEmpty()? PROP_CONTENT : PROP_CURRENT_PRESENTATION),
uno::makeAny( rResult ));
+
+ if (xServiceInfo->supportsService(
+ "com.sun.star.text.TextField.DocInfo.CreateDateTime"))
+ {
+ // Creation time is const, don't try to update it.
+ xFieldProperties->setPropertyValue("IsFixed", uno::makeAny(true));
+ }
}
}
catch( const beans::UnknownPropertyException& )
More information about the Libreoffice-commits
mailing list