summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-07-14 11:07:45 +0200
committerAndras Timar <andras.timar@collabora.com>2022-07-18 15:38:24 +0200
commit70d201c857fe86834f618f8c66df6f19b76c2556 (patch)
treec753c40fda429e262930105e1097b765b0be00cf
parentfe072bf9e52ab4c0bd7b692940092ca296edfe59 (diff)
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 <quikee@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137162 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--sw/qa/extras/uiwriter/data/HiddenSection.odtbin0 -> 8378 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter2.cxx50
-rw-r--r--sw/source/core/doc/docfld.cxx28
-rw-r--r--sw/source/core/docnode/ndsect.cxx1
4 files changed, 77 insertions, 2 deletions
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
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/HiddenSection.odt
Binary files 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();