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 de90c192cb (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 <vmiklos@collabora.com>
Tested-by: Jenkins
This commit is contained in:
@@ -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: */
|
||||
|
||||
Binary file not shown.
@@ -916,6 +916,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(
|
||||
|
||||
Reference in New Issue
Block a user