writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx | 23 ++++++++++ writerfilter/qa/cppunittests/dmapper/data/content-control-data-binding-color.docx |binary writerfilter/source/dmapper/DomainMapper_Impl.cxx | 7 +++ 3 files changed, 30 insertions(+)
New commits: commit 4b46aa3a20205eed7500545c79a7e8b92c488583 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Feb 15 14:20:02 2023 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Feb 16 09:24:52 2023 +0000 tdf#147258 DOCX import: fix bad char format w/ inline <w:sdt> and data binding The bugdoc had an inline SDT in placeholder mode, where the placeholder had a char style to define a red text color. This red color is not in Word, but it was in Writer. This went wrong with commit de90c192cb8f1f03a4028493d8bfe9a127a76b2a (sw content controls, plain text: enable DOCX filter with data binding, 2022-09-19), because previously we didn't map <w:sdt> to Writer content controls for plain text with data binding. Fix the problem by resetting the char style back to default when the value of the content control comes from data binding. Interestingly office.com renders the document the way Writer did previously, but let's try to match what desktop Word does, that's probably the reference for DOCX files. Change-Id: I7eccdb843d5ab63ccf573644c61832e2ef7dae14 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147088 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins (cherry picked from commit 1c45e1971cdd88f54a3cfb89622fdfa6fa8fcf31) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147073 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx index 728dd218cb65..359c051fb0df 100644 --- a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx @@ -301,6 +301,29 @@ CPPUNIT_TEST_FIXTURE(Test, testContentControlDateDataBinding) // i.e. the date was from document.xml, which is considered outdated. CPPUNIT_ASSERT_EQUAL(OUString("4/26/2012"), xParagraph->getString()); } + +CPPUNIT_TEST_FIXTURE(Test, testContentControlDataBindingColor) +{ + // Given a document with an inline content control with data binding, placeholder char color is + // set to red, when loading that document: + loadFromURL(u"content-control-data-binding-color.docx"); + + // Then make sure that the placeholder char color is not in the document, since data binding is + // active: + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xCursor->gotoEnd(/*bExpand=*/false); + xCursor->goLeft(/*nCount=*/1, /*bExpand=*/false); + uno::Reference<beans::XPropertySet> xCursorProps(xCursor, uno::UNO_QUERY); + Color nColor; + CPPUNIT_ASSERT(xCursorProps->getPropertyValue("CharColor") >>= nColor); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: rgba[ffffff00] + // - Actual : rgba[ff0000ff] + // i.e. the char color was red, not the default / automatic. + CPPUNIT_ASSERT_EQUAL(COL_AUTO, nColor); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/data/content-control-data-binding-color.docx b/writerfilter/qa/cppunittests/dmapper/data/content-control-data-binding-color.docx new file mode 100644 index 000000000000..0aae9439209b Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/content-control-data-binding-color.docx differ diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 3b310349b031..16ce9c9b5f96 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -906,6 +906,13 @@ void DomainMapper_Impl::PopSdt() { // Data binding has a value for us, prefer that over the in-document value. xCursor->setString(*oData); + + // Such value is always a plain text string, remove the char style of the placeholder. + uno::Reference<beans::XPropertyState> xPropertyState(xCursor, uno::UNO_QUERY); + if (xPropertyState.is()) + { + xPropertyState->setPropertyToDefault("CharStyleName"); + } } uno::Reference<text::XTextContent> xContentControl(