Kaydet (Commit) 35545d3d authored tarafından Miklos Vajna's avatar Miklos Vajna

DOCX import: handle w:sdt around w:r followed by a field

Change-Id: Ic0cf71efc8d57a98e7cff050ce68a0c4303ca6b1
üst 851b5a97
......@@ -599,6 +599,15 @@ DECLARE_OOXMLEXPORT_TEST(testfdo82123, "fdo82123.docx")
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:p/w:sdt[1]/w:sdtContent/w:r",1);
}
DECLARE_OOXMLEXPORT_TEST(testSdtBeforeField, "sdt-before-field.docx")
{
if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
{
// Make sure the field doesn't sneak inside the SDT: the SDT should contain only a single run (there were 6 ones).
assertXPath(pXmlDoc, "//w:sdt/w:sdtContent/w:r", 1);
}
}
DECLARE_OOXMLEXPORT_TEST(testfdo81946, "fdo81946.docx")
{
xmlDocPtr pXmlDoc = parseExport("word/header1.xml");
......
......@@ -2830,8 +2830,9 @@ void DomainMapper::lcl_startCharacterGroup()
m_pImpl->GetTopContext()->Insert(PROP_CHAR_ROTATION, uno::makeAny(sal_Int16(900)));
if (m_pImpl->isSdtEndDeferred())
{
// Fields have an empty character group before the real one, so don't
// call setSdtEndDeferred(false) here, that will happen only in lcl_utext().
m_pImpl->GetTopContext()->Insert(PROP_SDT_END_BEFORE, uno::makeAny(true), true, CHAR_GRAB_BAG);
m_pImpl->setSdtEndDeferred(false);
}
// Remember formatting of the date control as it only supports plain strings natively.
......@@ -2937,6 +2938,17 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
aBuffer.append( (const sal_Unicode *) data_, len);
sText = aBuffer.makeStringAndClear();
if (m_pImpl->isSdtEndDeferred())
{
// In case we have a field context, then save the property there, so
// SDT's ending right before a field start are handled as well.
PropertyMapPtr pContext = m_pImpl->GetTopContext();
if (m_pImpl->IsOpenField())
pContext = m_pImpl->GetTopFieldContext()->getProperties();
pContext->Insert(PROP_SDT_END_BEFORE, uno::makeAny(true), true, CHAR_GRAB_BAG);
m_pImpl->setSdtEndDeferred(false);
}
if (!m_pImpl->m_pSdtHelper->getDropDownItems().empty())
{
m_pImpl->m_pSdtHelper->getSdtTexts().append(sText);
......
......@@ -4231,13 +4231,16 @@ void DomainMapper_Impl::PopFieldContext()
xToInsert = uno::Reference< text::XTextContent >(pContext->GetTextField(), uno::UNO_QUERY);
if( xToInsert.is() && !m_bStartTOC && !m_bStartIndex && !m_bStartBibliography)
{
uno::Sequence<beans::PropertyValue> aValues;
PropertyMap aMap;
// Character properties of the field show up here the
// last (always empty) run. Inherit character
// properties from there.
// Also merge in the properties from the field context,
// e.g. SdtEndBefore.
if (m_pLastCharacterContext.get())
aValues = m_pLastCharacterContext->GetPropertyValues();
appendTextContent(xToInsert, aValues);
aMap.InsertProps(m_pLastCharacterContext);
aMap.InsertProps(m_aFieldStack.top()->getProperties());
appendTextContent(xToInsert, aMap.GetPropertyValues());
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment