diff options
author | László Németh <nemeth@numbertext.org> | 2019-07-17 13:37:44 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2019-07-18 14:42:07 +0200 |
commit | e8bae67b3dbcc90ace8264b6b1aefaf0ce459aba (patch) | |
tree | da9f4b0fb93b09667d7a381cd0f8a88ed7b01eaa | |
parent | 69899866063d360f087f8a08c51ec6bbfee28b36 (diff) |
tdf#125894: DOCX: import tracked changes in frames
Tracked changes weren't imported in frames, losing also
the actual text content: also tracked deletion reappeared
as normal text here, not only the tracked insertions.
Change-Id: I5fc8135cfb7402ad71c5c24eae606aa7ed707dfc
Reviewed-on: https://gerrit.libreoffice.org/75779
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf125894.docx | bin | 0 -> 23870 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 8 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 47 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 5 |
5 files changed, 59 insertions, 3 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf125894.docx b/sw/qa/extras/ooxmlexport/data/tdf125894.docx Binary files differnew file mode 100644 index 000000000000..1214f2c09cb7 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf125894.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index 98e137327787..c542a7b4394b 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -883,6 +883,14 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf126245, "tdf126245.docx") assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:pPrChange/w:pPr/w:numPr/w:numId", "val", "1"); } +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf125894, "tdf125894.docx") +{ + xmlDocPtr pXmlDoc = parseExport("word/document.xml"); + // import change tracking in frames + assertXPath(pXmlDoc, "//w:del", 2); + assertXPath(pXmlDoc, "//w:ins"); +} + DECLARE_OOXMLEXPORT_TEST(testTdf118691, "tdf118691.docx") { uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 173a0a1f99aa..f219330d52a2 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -1991,6 +1991,8 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pContext.get() ); if (pParaContext) pParaContext->SetFrameMode(); + + m_pImpl->m_bIsActualParagraphFramed = true; } else { diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 51b5c1e2cf96..21beb6965bf9 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -251,6 +251,7 @@ DomainMapper_Impl::DomainMapper_Impl( m_bCheckFirstFootnoteTab(false), m_bIgnoreNextTab(false), m_bIsSplitPara(false), + m_bIsActualParagraphFramed( false ), m_vTextFramesForChaining(), m_bParaHadField(false), m_bParaAutoBefore(false), @@ -2085,7 +2086,6 @@ void DomainMapper_Impl::CreateRedline(uno::Reference<text::XTextRange> const& xR default: throw lang::IllegalArgumentException("illegal redline token type", nullptr, 0); } - uno::Reference < text::XRedline > xRedline( xRange, uno::UNO_QUERY_THROW ); beans::PropertyValues aRedlineProperties( 3 ); beans::PropertyValue * pRedlineProperties = aRedlineProperties.getArray( ); pRedlineProperties[0].Name = getPropertyName( PROP_REDLINE_AUTHOR ); @@ -2094,7 +2094,17 @@ void DomainMapper_Impl::CreateRedline(uno::Reference<text::XTextRange> const& xR pRedlineProperties[1].Value <<= ConversionHelper::ConvertDateStringToDateTime( pRedline->m_sDate ); pRedlineProperties[2].Name = getPropertyName( PROP_REDLINE_REVERT_PROPERTIES ); pRedlineProperties[2].Value <<= pRedline->m_aRevertProperties; - xRedline->makeRedline( sType, aRedlineProperties ); + if (!m_bIsActualParagraphFramed) + { + uno::Reference < text::XRedline > xRedline( xRange, uno::UNO_QUERY_THROW ); + xRedline->makeRedline( sType, aRedlineProperties ); + } + else + { + aFramedRedlines.push_back( uno::makeAny(xRange) ); + aFramedRedlines.push_back( uno::makeAny(sType) ); + aFramedRedlines.push_back( uno::makeAny(aRedlineProperties) ); + } } catch( const uno::Exception & ) { @@ -5709,15 +5719,46 @@ void DomainMapper_Impl::ExecuteFrameConversion() try { uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( GetTopTextAppend(), uno::UNO_QUERY_THROW ); - xTextAppendAndConvert->convertToTextFrame( + // convert redline ranges to cursor movement and character length + std::vector<sal_Int32> redPos, redLen; + for( size_t i = 0; i < aFramedRedlines.size(); i+=3) + { + uno::Reference< text::XTextRange > xRange; + aFramedRedlines[i] >>= xRange; + uno::Reference<text::XTextCursor> xRangeCursor = GetTopTextAppend()->createTextCursorByRange( xRange ); + sal_Int32 nLen = xRange->getString().getLength(); + redLen.push_back(nLen); + xRangeCursor->gotoRange(m_xFrameStartRange, true); + redPos.push_back(xRangeCursor->getString().getLength() - nLen); + } + + const uno::Reference< text::XTextContent >& xTextContent = xTextAppendAndConvert->convertToTextFrame( m_xFrameStartRange, m_xFrameEndRange, comphelper::containerToSequence(m_aFrameProperties) ); + + // create redlines in the previous frame + for( size_t i = 0; i < aFramedRedlines.size(); i+=3) + { + OUString sType; + beans::PropertyValues aRedlineProperties( 3 ); + aFramedRedlines[i+1] >>= sType; + aFramedRedlines[i+2] >>= aRedlineProperties; + uno::Reference< text::XTextFrame > xFrame( xTextContent, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextCursor > xCrsr = xFrame->getText()->createTextCursor(); + xCrsr->goRight(redPos[i/3], false); + xCrsr->goRight(redLen[i/3], true); + uno::Reference < text::XRedline > xRedline( xCrsr, uno::UNO_QUERY_THROW ); + xRedline->makeRedline( sType, aRedlineProperties ); + } } catch( const uno::Exception&) { DBG_UNHANDLED_EXCEPTION( "writerfilter.dmapper", "Exception caught when converting to frame"); } + + m_bIsActualParagraphFramed = false; + aFramedRedlines.clear(); } m_xFrameStartRange = nullptr; m_xFrameEndRange = nullptr; diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 040b8df0cc28..185c143af47b 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -1004,6 +1004,11 @@ public: /// start/end node. void ClearPreviousParagraph(); + /// Handle redline text portions in frames: + /// store their data, and create them after frame creation + bool m_bIsActualParagraphFramed; + std::vector<css::uno::Any> aFramedRedlines; + private: void PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType); std::vector<css::uno::Reference< css::drawing::XShape > > m_vTextFramesForChaining ; |