diff options
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx | 21 | ||||
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/data/sdt-run-in-para.docx | bin | 0 -> 11987 bytes | |||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 10 |
3 files changed, 31 insertions, 0 deletions
diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx index 88ba238fae29..21d5c84cae4e 100644 --- a/writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx +++ b/writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx @@ -74,6 +74,27 @@ CPPUNIT_TEST_FIXTURE(Test, testLargeParaTopMargin) // -> wrap around a TextBox), which shifted the triangle shape out of the page frame. CPPUNIT_ASSERT_EQUAL(nExpected, nParaTopMargin); } + +CPPUNIT_TEST_FIXTURE(Test, testSdtRunInPara) +{ + // Given a document with a block SDT, and inside that some content + a run SDT: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "sdt-run-in-para.docx"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure the content inside the block SDT but outside the run SDT is not lost: + 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<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: first-second + // - Actual : second + // i.e. the block-SDT-only string was lost. + CPPUNIT_ASSERT_EQUAL(OUString("first-second"), xPara->getString()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/data/sdt-run-in-para.docx b/writerfilter/qa/cppunittests/dmapper/data/sdt-run-in-para.docx Binary files differnew file mode 100644 index 000000000000..863bc9213b5b --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/data/sdt-run-in-para.docx diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index cd89b3d7d7ae..224f8c2aa902 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -1074,6 +1074,16 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) } if (nName == NS_ooxml::LN_CT_SdtRun_sdtContent) { + if (m_pImpl->GetSdtStarts().empty() && !m_pImpl->m_pSdtHelper->getSdtTexts().isEmpty()) + { + // A non-inline SDT is already started, first convert that to a field and only + // then map the inline SDT to a content control. + if (m_pImpl->m_pSdtHelper->getControlType() == SdtControlType::plainText) + { + m_pImpl->m_pSdtHelper->createPlainTextControl(); + } + } + m_pImpl->m_pSdtHelper->setControlType(SdtControlType::richText); m_pImpl->PushSdt(); break; |