sw/qa/extras/uiwriter/data/HiddenSection.odt |binary sw/qa/extras/uiwriter/uiwriter2.cxx | 50 +++++++++++++++++++++++++++ sw/source/core/doc/docfld.cxx | 28 ++++++++++++++- sw/source/core/docnode/ndsect.cxx | 1 4 files changed, 77 insertions(+), 2 deletions(-)
New commits: commit 70d201c857fe86834f618f8c66df6f19b76c2556 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Jul 14 11:07:45 2022 +0200 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Jul 18 15:38:24 2022 +0200 tdf#54703 fix unhiding at PDF export of cond. hidden sections The conditionally hidden sections became visible when PDF export is performed. This is due to field update where we temporary made the conditionally hidden section visible (as the frame is needed), but never put them back to hidden. Probably the expectation was that the condition will be recalculated later on, but wasn't. This change fixes this so that the changed sections will be recalculated at the end. Change-Id: Ic6d8a4a38f22ed961b2b37e05aaf3e720fc50ed4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137052 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137162 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Andras Timar <andras.ti...@collabora.com> diff --git a/sw/qa/extras/uiwriter/data/HiddenSection.odt b/sw/qa/extras/uiwriter/data/HiddenSection.odt new file mode 100644 index 000000000000..8358cbc9951a Binary files /dev/null and b/sw/qa/extras/uiwriter/data/HiddenSection.odt differ diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index f895b59ba402..6db1b70051fc 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -30,10 +30,12 @@ #include <comphelper/propertysequence.hxx> #include <comphelper/propertyvalue.hxx> #include <comphelper/configuration.hxx> +#include <unotools/mediadescriptor.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <i18nlangtag/languagetag.hxx> #include <vcl/scheduler.hxx> #include <vcl/settings.hxx> +#include <vcl/filter/PDFiumLibrary.hxx> #include <ndtxt.hxx> #include <swdtflvr.hxx> #include <wrtsh.hxx> @@ -6069,6 +6071,54 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf126735) CPPUNIT_ASSERT_EQUAL(OUString("or "), xTextRange->getString()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testConditionalHiddenSectionIssue) +{ + // tdf#54703 + // When exporting the bug document as PDF, the conditional hidden + // sections became visible in the PDF and in the document. + + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + return; + + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "HiddenSection.odt"); + + // Check section conditional hidden status - all should be hidden (IsCondHidden == true) + for (SwNodeOffset i(0); i < pDoc->GetNodes().Count(); ++i) + { + if (SwSectionNode const* const pNode = pDoc->GetNodes()[i]->GetSectionNode()) + { + CPPUNIT_ASSERT_EQUAL(true, pNode->GetSection().IsCondHidden()); + } + } + + // PDF export + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + + SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + auto pPdfDocument = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize()); + CPPUNIT_ASSERT(pPdfDocument); + auto pPdfPage = pPdfDocument->openPage(0); + CPPUNIT_ASSERT(pPdfPage); + + // No PDF object should be present in the page - sections remained hidden + CPPUNIT_ASSERT_EQUAL(0, pPdfPage->getObjectCount()); + + // Check section conditional hidden status - all should remained hidden (IsCondHidden == true) + for (SwNodeOffset i(0); i < pDoc->GetNodes().Count(); ++i) + { + if (SwSectionNode const* const pNode = pDoc->GetNodes()[i]->GetSectionNode()) + { + CPPUNIT_ASSERT_EQUAL(true, pNode->GetSection().IsCondHidden()); + } + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx index 652af8a188b9..fb1e71f3b190 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -839,6 +839,9 @@ void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int eGetMode ) // new version: walk all fields of the attribute pool m_pFieldSortList.reset(new SetGetExpFields); + // remembeer sections that were unhidden and need to be hidden again + std::vector<std::reference_wrapper<SwSection>> aUnhiddenSections; + // consider and unhide sections // with hide condition, only in mode GETFLD_ALL (<eGetMode == GETFLD_ALL>) // notes by OD: @@ -885,13 +888,27 @@ void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int eGetMode ) { pSectNd = rDoc.GetNodes()[ aTmpArr[ n ] ]->GetSectionNode(); OSL_ENSURE( pSectNd, "Where is my SectionNode" ); - pSectNd->GetSection().SetCondHidden( false ); + + auto& rSection = pSectNd->GetSection(); + // unhide and remember the conditionally hidden sections + if (rSection.IsHidden() && !rSection.GetCondition().isEmpty() && rSection.IsCondHidden()) + { + aUnhiddenSections.push_back(std::ref(rSection)); // remember to later hide again + rSection.SetCondHidden(false); + } } for (std::vector<sal_uLong>::size_type n = 0; n < nArrStt; ++n) { pSectNd = rDoc.GetNodes()[ aTmpArr[ n ] ]->GetSectionNode(); OSL_ENSURE( pSectNd, "Where is my SectionNode" ); - pSectNd->GetSection().SetCondHidden( false ); + + auto& rSection = pSectNd->GetSection(); + // unhide and remember the conditionally hidden sections + if (rSection.IsHidden() && !rSection.GetCondition().isEmpty() && rSection.IsCondHidden()) + { + aUnhiddenSections.push_back(std::ref(rSection)); // remember to later hide again + rSection.SetCondHidden(false); + } } // add all to the list so that they are sorted @@ -1032,6 +1049,13 @@ void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int eGetMode ) } m_nFieldListGetMode = eGetMode; m_nNodes = rDoc.GetNodes().Count(); + + // return the conditional hidden value back to the previous value + for (auto& rSectionWrapper : aUnhiddenSections) + { + auto& rSection = rSectionWrapper.get(); + rSection.SetCondHidden(true); + } } void SwDocUpdateField::GetBodyNode( const SwTextField& rTField, SwFieldIds nFieldWhich ) diff --git a/sw/source/core/docnode/ndsect.cxx b/sw/source/core/docnode/ndsect.cxx index 25669fcd2f76..6b3750447d8d 100644 --- a/sw/source/core/docnode/ndsect.cxx +++ b/sw/source/core/docnode/ndsect.cxx @@ -1263,6 +1263,7 @@ SwSectionNode* SwSectionNode::MakeCopy( SwDoc& rDoc, const SwNodeIndex& rIdx ) c pNewSect->SetType( GetSection().GetType() ); pNewSect->SetCondition( GetSection().GetCondition() ); + pNewSect->SetCondHidden( GetSection().IsCondHidden() ); pNewSect->SetLinkFileName( GetSection().GetLinkFileName() ); if( !pNewSect->IsHiddenFlag() && GetSection().IsHidden() ) pNewSect->SetHidden();