diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-09-07 19:32:54 +0300 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-09-11 08:33:55 +0200 |
commit | da8e60218adac676e33b0031c70859027ec5f328 (patch) | |
tree | 8b2fe6f7060efb97357056e1273a0214dacca131 | |
parent | 8902243c9691096184cc6d058a7687735398c42a (diff) |
tdf#157136: apply top context properties to the text input field
Change-Id: Ie3877811e482c1ec395a00ec6bf67155220b2b64
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156675
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156729
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf157136_TwoContentControls.docx | bin | 0 -> 22502 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport18.cxx | 55 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SdtHelper.cxx | 5 |
3 files changed, 59 insertions, 1 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf157136_TwoContentControls.docx b/sw/qa/extras/ooxmlexport/data/tdf157136_TwoContentControls.docx Binary files differnew file mode 100644 index 000000000000..f4e898cb057f --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf157136_TwoContentControls.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx index ad18b6afc246..36b492c5d294 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx @@ -268,6 +268,61 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf150966_regularInset) assertXPathAttrs(pXmlDoc, "//wps:bodyPr", { { "tIns", "179640" }, { "bIns", "360000" } }); } +CPPUNIT_TEST_FIXTURE(Test, testTdf157136) +{ + // Given a document with two content controls - one block, one inline + load(DATA_DIRECTORY, "tdf157136_TwoContentControls.docx"); + + // Both of them must import with the correct character style + + { + // 1st paragraph - block content control + auto xRun = getRun(getParagraph(1), 1); + CPPUNIT_ASSERT_EQUAL(OUString("Click or tap here to enter text.\r"), xRun->getString()); + // Without the fix in place, this would fail with + // - Expected: Placeholder Text + // - Actual : + CPPUNIT_ASSERT_EQUAL(OUString("Placeholder Text"), + getProperty<OUString>(xRun, "CharStyleName")); + } + + { + // 2nd paragraph - inline content control + auto xRun = getRun(getParagraph(2), 1); + auto xContentControl + = getProperty<css::uno::Reference<css::text::XTextRange>>(xRun, "ContentControl"); + CPPUNIT_ASSERT_EQUAL(OUString("Click or tap here to enter text."), + xContentControl->getString()); + CPPUNIT_ASSERT_EQUAL(OUString("Placeholder Text"), + getProperty<OUString>(xRun, "CharStyleName")); + } + + // Test the same after round-trip + reload("Office Open XML Text", ""); + + { + // 1st paragraph - becomes inline content control after roundtrip + auto xRun = getRun(getParagraph(1), 1); + auto xContentControl + = getProperty<css::uno::Reference<css::text::XTextRange>>(xRun, "ContentControl"); + CPPUNIT_ASSERT_EQUAL(OUString("Click or tap here to enter text."), + xContentControl->getString()); + CPPUNIT_ASSERT_EQUAL(OUString("Placeholder Text"), + getProperty<OUString>(xRun, "CharStyleName")); + } + + { + // 2nd paragraph - inline content control + auto xRun = getRun(getParagraph(2), 1); + auto xContentControl + = getProperty<css::uno::Reference<css::text::XTextRange>>(xRun, "ContentControl"); + CPPUNIT_ASSERT_EQUAL(OUString("Click or tap here to enter text."), + xContentControl->getString()); + CPPUNIT_ASSERT_EQUAL(OUString("Placeholder Text"), + getProperty<OUString>(xRun, "CharStyleName")); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx index 99fd0de0de9d..8a75679ef73a 100644 --- a/writerfilter/source/dmapper/SdtHelper.cxx +++ b/writerfilter/source/dmapper/SdtHelper.cxx @@ -288,8 +288,11 @@ void SdtHelper::createPlainTextControl() xPropertySet->setPropertyValue("Content", uno::makeAny(aDefaultText)); + PropertyMap aMap; + aMap.InsertProps(m_rDM_Impl.GetTopContext()); + // add it into document - m_rDM_Impl.appendTextContent(xControlModel, uno::Sequence<beans::PropertyValue>()); + m_rDM_Impl.appendTextContent(xControlModel, aMap.GetPropertyValues()); // Store all unused sdt parameters from grabbag xPropertySet->setPropertyValue(UNO_NAME_MISC_OBJ_INTEROPGRABBAG, |