From 65043a50adf8d56e1f965ec48b9609ca836ccced Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 18 Dec 2024 10:36:48 +0100 Subject: Related: tdf#164359 editeng RTF export: track unused follow styles recursively Similar to commit a7a81b6fbe37af938ce461e790fac517be032317 (tdf#164359 editeng RTF export: track unused parent styles recursively, 2024-12-18), the follows of a style has to be tracked recursively as well, to avoid a crash. The Impress UI doesn't seem to have a way to specify the parent/next name of a style, but you can definitely create such a follow chain from test code and probably this is also possible via macros. Fix this similar to the parent case, except here handle when a style sets itself as a follow: that's what the default Outline N styles do in Impress. Change-Id: If3847add02061fdb9ba1e3fbf7c1fc42e3866209 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178786 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- editeng/source/editeng/impedit4.cxx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'editeng/source') diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 6c83f2a4e5e2..de167e657690 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -479,15 +479,25 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel, bool bCl aParent = pParent->GetParent(); } - const OUString& rFollow = pParaStyle->GetFollow(); - if (!rFollow.isEmpty()) + // Collect follows of the style recursively. + OUString aFollow = pParaStyle->GetFollow(); + while (!aFollow.isEmpty()) { auto pFollow = static_cast( - GetStyleSheetPool()->Find(rFollow, pParaStyle->GetFamily())); - if (pFollow) + GetStyleSheetPool()->Find(aFollow, pParaStyle->GetFamily())); + if (!pFollow) { - aUsedParagraphStyles.insert(pFollow); + break; + } + + auto it = aUsedParagraphStyles.insert(pFollow); + // A style is fine to have itself as a follow. + if (!it.second) + { + // No insertion happened, so this is visited already. + break; } + aFollow = pFollow->GetFollow(); } } } -- cgit