From 28dddd4f7e255c74c17c0c6b263303f4567b5678 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Fri, 28 Aug 2020 15:32:11 +0300 Subject: tdf#132149 ww8export: respect ginormous paragraphs This handles the extremely unlikely case where a single paragraph contains multiple soft-page-breaks from spanning more than two pages. But it makes the unit tests I designed look much better, so I am happy. I think it might help to make the code slightly more understandable too, and it convinces me that I am understanding this section as I write multiple fixes against it. [Better evidence than all of this is that Michael Stahl came the the same conclusion from a code read - I just beat him to it.] (P.S. It isn't enough to change CurrentPageDesc, because that is reset from rNode.FindPageDesc on every WriteText. So the effective pageDesc needs to be kept track of.) Change-Id: I5852e90571a74f3df4362caf058f7960f413dad3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101545 Tested-by: Jenkins Reviewed-by: Justin Luth Reviewed-by: Miklos Vajna --- sw/source/filter/ww8/wrtw8nds.cxx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'sw/source/filter') diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index 0c04d094e505..96d12e8afe43 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -2265,6 +2265,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode ) // Let's decide if we need to split the paragraph because of a section break bool bNeedParaSplit = NeedTextNodeSplit( rNode, softBreakList ) && !IsInTable(); + const SwPageDesc* pNextSplitParaPageDesc = m_pCurrentPageDesc; auto aBreakIt = softBreakList.begin(); // iterate through portions on different pages @@ -2273,7 +2274,13 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode ) sal_Int32 nCurrentPos = *aBreakIt; if( softBreakList.size() > 1 ) // not for empty paragraph - ++aBreakIt; + { + // no need to split again if the page style won't change anymore + if ( pNextSplitParaPageDesc == pNextSplitParaPageDesc->GetFollow() ) + aBreakIt = --softBreakList.end(); + else + ++aBreakIt; + } AttrOutput().StartParagraph( pTextNodeInfo ); @@ -2718,9 +2725,9 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode ) // if paragraph is split, put the section break between the parts if( bNeedParaSplit && *aBreakIt != rNode.GetText().getLength() ) { - const SwPageDesc* pNextPageDesc = m_pCurrentPageDesc->GetFollow(); - assert(pNextPageDesc); - PrepareNewPageDesc( rNode.GetpSwAttrSet(), rNode, nullptr , pNextPageDesc); + pNextSplitParaPageDesc = pNextSplitParaPageDesc->GetFollow(); + assert(pNextSplitParaPageDesc); + PrepareNewPageDesc( rNode.GetpSwAttrSet(), rNode, nullptr , pNextSplitParaPageDesc); } else { -- cgit