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 868b45039d2d168e1c51d971b0d1e0589d4d11eb Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Jul 14 11:07:45 2022 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sun Jul 17 18:41:00 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> 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 8e78a70f97c1..59f8047ca82f 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -14,9 +14,11 @@ #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> #include <comphelper/propertysequence.hxx> +#include <unotools/mediadescriptor.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <vcl/scheduler.hxx> #include <vcl/settings.hxx> +#include <vcl/filter/PDFiumLibrary.hxx> #include <ndtxt.hxx> #include <swdtflvr.hxx> #include <wrtsh.hxx> @@ -3161,6 +3163,54 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf140757) CPPUNIT_ASSERT(!pWrtShell->GetViewOptions()->IsShowChangesInMargin()); } +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 a1a7434a25b6..d0e489b7b027 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -840,6 +840,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: @@ -886,13 +889,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 @@ -1033,6 +1050,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 098f5bd49430..6c7fb8b6ecec 100644 --- a/sw/source/core/docnode/ndsect.cxx +++ b/sw/source/core/docnode/ndsect.cxx @@ -1269,6 +1269,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();