sw/source/core/docnode/ndtbl.cxx | 43 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-)
New commits: commit 3146edaf76f4533f5872dc687a76a55c691ce4e9 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Fri Mar 22 14:27:01 2024 +0100 Commit: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> CommitDate: Fri Mar 22 19:54:03 2024 +0100 tdf#157241 sw: assert when importing ToX in table in rhbz589883-2.docx ndtbl.cxx:1417: SwNodes::TextToTable(): Assertion `!rNode.IsSectionNode()' failed. (regression from commit 62cb3b8b8d6106c6aeb073b12d84973a107182ef) Change-Id: Iec12282573cb914d1924f4da4a28e26e01b866df Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165164 Tested-by: Michael Stahl <michael.st...@allotropia.de> Reviewed-by: Michael Stahl <michael.st...@allotropia.de> (cherry picked from commit df6fdb0041f8bfd251a4b03030b8bc47f0614c36) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165173 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165193 Tested-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index d052ed7eda4b..f3b3a07d63b5 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -1413,16 +1413,19 @@ SwTableNode* SwNodes::TextToTable( const SwNodes::TableRanges_t & rTableNodes, // delete frames of all contained content nodes for( nLines = 0; aNodeIndex <= rTableNodes.rbegin()->rbegin()->aEnd; ++aNodeIndex,++nLines ) { - SwNode& rNode = aNodeIndex.GetNode(); - assert(!rNode.IsSectionNode()); // not possible in writerfilter import - if (rNode.IsTableNode()) + SwNode* pNode(&aNodeIndex.GetNode()); + while (pNode->IsSectionNode()) // could be ToX field in table { - lcl_RemoveBreaksTable(static_cast<SwTableNode&>(rNode), + pNode = pNode->GetNodes()[pNode->GetIndex()+1]; + } + if (pNode->IsTableNode()) + { + lcl_RemoveBreaksTable(static_cast<SwTableNode&>(*pNode), (0 == nLines) ? pTableFormat : nullptr); } - else if (rNode.IsContentNode()) + else if (pNode->IsContentNode()) { - lcl_RemoveBreaks(static_cast<SwContentNode&>(rNode), + lcl_RemoveBreaks(static_cast<SwContentNode&>(*pNode), (0 == nLines) ? pTableFormat : nullptr); } } commit 8506ffb5cef6e18c01350874231e66080efbaf5e Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Wed Mar 13 18:57:21 2024 +0100 Commit: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> CommitDate: Fri Mar 22 19:53:57 2024 +0100 tdf#157241 sw: fix crash on RTF paste or insert of nested tables The problem is that there are tables with only empty cell frames in the layout, which causes a crash in IsAllHiddenCell() added in commit ab7893544dc6be6dc192dffefd57cd5ddd421c35. This happens because first inner tables are created, with layout frames because the layout already exists. Then when SwNodes::TextToTable() is called for the outer table, it deletes the SwTextFrames, but not the SwTabFrames/SwCellFrames, so they remain uselessly in the layout. Delete these too, they will be recreated when the frame for the outer table is created. Also the transfer of any existing break to the outer table was missing. Change-Id: Idc2bc1d4c6572702510ae4355e4015c42770eb3e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164788 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> (cherry picked from commit 62cb3b8b8d6106c6aeb073b12d84973a107182ef) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164813 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> (cherry picked from commit df5bb0c4343b4a090de3343c7d454a93099989c0) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165003 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Tested-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index a7a2bee478da..d052ed7eda4b 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -888,6 +888,34 @@ const SwTable* SwDoc::TextToTable( const SwInsertTableOptions& rInsTableOpts, return &rNdTable; } +static void lcl_RemoveBreaksTable(SwTableNode & rNode, SwTableFormat *const pTableFormat) +{ + // delete old layout frames, new ones need to be created... + rNode.DelFrames(nullptr); + + // remove PageBreaks/PageDesc/ColBreak + SwFrameFormat & rFormat(*rNode.GetTable().GetFrameFormat()); + + if (const SvxFormatBreakItem* pItem = rFormat.GetItemIfSet(RES_BREAK, false)) + { + if (pTableFormat) + { + pTableFormat->SetFormatAttr(*pItem); + } + rFormat.ResetFormatAttr(RES_BREAK); + } + + SwFormatPageDesc const*const pPageDescItem(rFormat.GetItemIfSet(RES_PAGEDESC, false)); + if (pPageDescItem && pPageDescItem->GetPageDesc()) + { + if (pTableFormat) + { + pTableFormat->SetFormatAttr(*pPageDescItem); + } + rFormat.ResetFormatAttr(RES_PAGEDESC); + } +} + static void lcl_RemoveBreaks(SwContentNode & rNode, SwTableFormat *const pTableFormat) { // delete old layout frames, new ones need to be created... @@ -1386,7 +1414,13 @@ SwTableNode* SwNodes::TextToTable( const SwNodes::TableRanges_t & rTableNodes, for( nLines = 0; aNodeIndex <= rTableNodes.rbegin()->rbegin()->aEnd; ++aNodeIndex,++nLines ) { SwNode& rNode = aNodeIndex.GetNode(); - if( rNode.IsContentNode() ) + assert(!rNode.IsSectionNode()); // not possible in writerfilter import + if (rNode.IsTableNode()) + { + lcl_RemoveBreaksTable(static_cast<SwTableNode&>(rNode), + (0 == nLines) ? pTableFormat : nullptr); + } + else if (rNode.IsContentNode()) { lcl_RemoveBreaks(static_cast<SwContentNode&>(rNode), (0 == nLines) ? pTableFormat : nullptr);