From fc3eb493ac9e8dec35060524db4dc8ca3210631a Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 15 Jul 2014 18:18:19 +0200 Subject: Related: bnc#875718 DOCX import: fix missing character grab-bag on fields The problem was that in case: 1) The paragraph only had a single text portion, which was a field and char grab-bag was set on it and 2) The paragraph had a style which also set the character grab-bag then during import the field's gra-bag was set on the paragraph (as it's the only portion) and later the paragraph style overwrote this, in case that had a grab-bag, too. Work this around by ensuring that in case of portion fields (i.e. not ToC, which has its own paragraphs), there are always at least two portions in a paragraph (the second is removed later). This also fixes the fake paragraph problem at the end of the bnc#875718 testcase. (There was an empty paragraph at the end of the document, but not in the file itself.) Change-Id: Ie404bc043d46157ea6157b18c4a46395cf496118 --- writerfilter/source/dmapper/DomainMapper_Impl.cxx | 28 ++++++++++++++++++++++- writerfilter/source/dmapper/DomainMapper_Impl.hxx | 2 ++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'writerfilter') diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index e74383ee4629..6645e235710e 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -208,7 +208,8 @@ DomainMapper_Impl::DomainMapper_Impl( m_bIgnoreNextTab(false), m_bFrameBtLr(false), m_bIsSplitPara(false), - m_vTextFramesForChaining() + m_vTextFramesForChaining(), + m_bParaHadField(false) { appendTableManager( ); @@ -1112,7 +1113,27 @@ void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap ) rAppendContext.pLastParagraphProperties->SetEndingRange(xTextRange->getEnd()); } else + { + uno::Reference xCursor; + if (m_bParaHadField) + { + // Workaround to make sure char props of the field are not lost. + OUString sMarker("X"); + xCursor = xTextAppend->getText()->createTextCursor(); + if (xCursor.is()) + xCursor->gotoEnd(false); + PropertyMapPtr pEmpty(new PropertyMap()); + appendTextPortion("X", pEmpty); + } + xTextRange = xTextAppend->finishParagraph( aProperties ); + + if (xCursor.is()) + { + xCursor->goLeft(1, true); + xCursor->setString(OUString()); + } + } getTableManager( ).handle(xTextRange); // Get the end of paragraph character inserted @@ -1153,6 +1174,7 @@ void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap ) } SetIsOutsideAParagraph(true); + m_bParaHadField = false; #ifdef DEBUG_DOMAINMAPPER dmapper_logger->endElement(); #endif @@ -2426,6 +2448,7 @@ uno::Reference< beans::XPropertySet > DomainMapper_Impl::FindOrCreateFieldMaster -----------------------------------------------------------------------*/ void DomainMapper_Impl::PushFieldContext() { + m_bParaHadField = true; if(m_bDiscardHeaderFooter) return; #ifdef DEBUG_DOMAINMAPPER @@ -3134,6 +3157,7 @@ void DomainMapper_Impl::handleToc } } pContext->SetTOC( xTOC ); + m_bParaHadField = false; OUString sMarker("Y"); //insert index @@ -3171,6 +3195,7 @@ void DomainMapper_Impl::handleBibliography xTOC->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ), uno::makeAny(OUString())); pContext->SetTOC( xTOC ); + m_bParaHadField = false; uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY ); appendTextContent(xToInsert, uno::Sequence< beans::PropertyValue >() ); @@ -3215,6 +3240,7 @@ void DomainMapper_Impl::handleIndex } } pContext->SetTOC( xTOC ); + m_bParaHadField = false; uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY ); appendTextContent(xToInsert, uno::Sequence< beans::PropertyValue >() ); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index e577c86f1e97..60c8c654b979 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -812,6 +812,8 @@ public: private: void PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType); std::vector > m_vTextFramesForChaining ; + /// Current paragraph had at least one field in it. + bool m_bParaHadField; }; // export just for test -- cgit