summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-07-15 18:18:19 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-07-15 19:05:06 +0200
commitfc3eb493ac9e8dec35060524db4dc8ca3210631a (patch)
treeee91f13e4806ac8d7eb74469a90de563298799a6
parent6d3269ad94bbad8abae5703edc86d8888356bf14 (diff)
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
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx2
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx28
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx2
3 files changed, 30 insertions, 2 deletions
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 8d85f1dba7b7..efbfebb33f77 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -2190,7 +2190,7 @@ DECLARE_OOXMLIMPORT_TEST(testBnc875718, "bnc875718.docx")
// Also check that the footer contents are not in the body text.
uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XText> text(textDocument->getText(), uno::UNO_QUERY);
- CPPUNIT_ASSERT_EQUAL( OUString( "Text\n" ), text->getString());
+ CPPUNIT_ASSERT_EQUAL( OUString( "Text" ), text->getString());
}
DECLARE_OOXMLIMPORT_TEST(testCaption, "caption.docx")
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<text::XTextCursor> 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<css::uno::Reference< css::drawing::XShape > > m_vTextFramesForChaining ;
+ /// Current paragraph had at least one field in it.
+ bool m_bParaHadField;
};
// export just for test