sw/inc/EnhancedPDFExportHelper.hxx               |    2 
 sw/source/core/text/EnhancedPDFExportHelper.cxx  |   96 ++++++++++------
 vcl/qa/cppunit/pdfexport/data/nestedsection.fodt |  132 ++++++++++++++++++++++
 vcl/qa/cppunit/pdfexport/pdfexport.cxx           |  137 +++++++++++++++++++++++
 4 files changed, 332 insertions(+), 35 deletions(-)

New commits:
commit 033e37b49b5712df19dbfd2c307a102bce620de1
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Aug 31 19:50:55 2023 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Sep 26 21:13:18 2023 +0200

    sw: PDF/UA export: produce nested Sect SEs for nested sections
    
    Change-Id: I5b142acf00629ffd00562e2c8791587b7a7761df
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156357
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit d5f68529a79c615f989fcfeef248d887a6e10f5a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157229
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/inc/EnhancedPDFExportHelper.hxx 
b/sw/inc/EnhancedPDFExportHelper.hxx
index 53fbbbe4bab1..1ab0f8868af4 100644
--- a/sw/inc/EnhancedPDFExportHelper.hxx
+++ b/sw/inc/EnhancedPDFExportHelper.hxx
@@ -146,6 +146,7 @@ class SwTaggedPDFHelper
     const Frame_Info* mpFrameInfo;
     const Por_Info* mpPorInfo;
 
+    void OpenTagImpl(void const* pKey);
     sal_Int32 BeginTagImpl(void const* pKey,vcl::PDFWriter::StructElement 
aTagRole, const OUString& rTagName);
     void BeginTag( vcl::PDFWriter::StructElement aTagRole, const OUString& 
rTagName );
     void EndTag();
diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx 
b/sw/source/core/text/EnhancedPDFExportHelper.cxx
index 315c2e1b7429..3cd5176cb786 100644
--- a/sw/source/core/text/EnhancedPDFExportHelper.cxx
+++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx
@@ -452,13 +452,7 @@ bool SwTaggedPDFHelper::CheckReopenTag()
 
     if (pReopenKey)
     {
-        sal_Int32 const id = 
mpPDFExtOutDevData->EnsureStructureElement(pReopenKey);
-        mpPDFExtOutDevData->BeginStructureElement(id);
-        ++m_nEndStructureElement;
-
-#if OSL_DEBUG_LEVEL > 1
-        aStructStack.push_back( 99 );
-#endif
+        OpenTagImpl(pReopenKey);
 
         bRet = true;
     }
@@ -479,6 +473,17 @@ void SwTaggedPDFHelper::CheckRestoreTag() const
     }
 }
 
+void SwTaggedPDFHelper::OpenTagImpl(void const*const pKey)
+{
+    sal_Int32 const id = mpPDFExtOutDevData->EnsureStructureElement(pKey);
+    mpPDFExtOutDevData->BeginStructureElement(id);
+    ++m_nEndStructureElement;
+
+#if OSL_DEBUG_LEVEL > 1
+    aStructStack.push_back( 99 );
+#endif
+}
+
 sal_Int32 SwTaggedPDFHelper::BeginTagImpl(void const*const pKey,
     vcl::PDFWriter::StructElement const eType, const OUString& rString)
 {
@@ -1228,7 +1233,30 @@ void SwTaggedPDFHelper::BeginBlockStructureElements()
             {
                 const SwSection* pSection =
                         static_cast<const 
SwSectionFrame*>(pFrame)->GetSection();
-                if ( SectionType::ToxContent == pSection->GetType() )
+
+                // open all parent sections, so that the SEs of sections
+                // are nested in the same way as their SwSectionNodes
+                std::vector<SwSection const*> parents;
+                for (SwSection const* pParent = pSection->GetParent();
+                     pParent != nullptr; pParent = pParent->GetParent())
+                {
+                    parents.push_back(pParent);
+                }
+                for (auto it = parents.rbegin(); it != parents.rend(); ++it)
+                {
+                    // key is the SwSection - see lcl_GetKeyFromFrame()
+                    OpenTagImpl(*it);
+                }
+
+                FrameTagSet& 
rFrameTagSet(mpPDFExtOutDevData->GetSwPDFState()->m_FrameTagSet);
+                if (rFrameTagSet.find(pSection) != rFrameTagSet.end())
+                {
+                    // special case: section may have *multiple* master frames,
+                    // when it is interrupted by nested section - reopen!
+                    OpenTagImpl(pSection);
+                    break;
+                }
+                else if (SectionType::ToxContent == pSection->GetType())
                 {
                     const SwTOXBase* pTOXBase = pSection->GetTOXBase();
                     if ( pTOXBase )
diff --git a/vcl/qa/cppunit/pdfexport/data/nestedsection.fodt 
b/vcl/qa/cppunit/pdfexport/data/nestedsection.fodt
new file mode 100644
index 000000000000..ab743058f5e7
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/nestedsection.fodt
@@ -0,0 +1,132 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:c
 alcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:
 meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ 
<office:meta><meta:creation-date>2023-08-31T13:12:47.478843606</meta:creation-date><dc:date>2023-08-31T19:59:09.088439334</dc:date><meta:editing-duration>PT5M46S</meta:editing-duration><meta:editing-cycles>6</meta:editing-cycles><meta:generator>LibreOfficeDev/24.2.0.0.alpha0$Linux_X86_64
 
LibreOffice_project/f72e62cf27db17505de57abe93127f8b8d40eb29</meta:generator><meta:print-date>2023-08-31T19:31:58.495592060</meta:print-date><meta:printed-by>PDF
 files</meta:printed-by><dc:title>title</dc:title><meta:document-statistic 
meta:table-count="0" meta:image-count="0" meta:object-count="0" 
meta:page-count="3" meta:paragraph-count="6" meta:word-count="6" 
meta:character-count="6" meta:non-whitespace-character-count="6"/></office:meta>
+ <office:font-face-decls>
+  <style:font-face style:name="Liberation Serif" svg:font-family="'Liberation 
Serif'" style:font-family-generic="roman" style:font-pitch="variable"/>
+  <style:font-face style:name="Lohit Devanagari1" svg:font-family="'Lohit 
Devanagari'" style:font-family-generic="system" style:font-pitch="variable"/>
+  <style:font-face style:name="Noto Sans CJK SC" svg:font-family="'Noto Sans 
CJK SC'" style:font-family-generic="system" style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:styles>
+  <style:default-style style:family="graphic">
+   <style:graphic-properties svg:stroke-color="#3465a4" 
draw:fill-color="#729fcf" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" 
draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" 
draw:start-line-spacing-vertical="0.283cm" 
draw:end-line-spacing-horizontal="0.283cm" 
draw:end-line-spacing-vertical="0.283cm" style:writing-mode="lr-tb" 
style:flow-with-text="false"/>
+   <style:paragraph-properties style:text-autospace="ideograph-alpha" 
style:line-break="strict" loext:tab-stop-distance="0cm" 
style:writing-mode="lr-tb" style:font-independent-line-spacing="false">
+    <style:tab-stops/>
+   </style:paragraph-properties>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" 
fo:language="de" fo:country="DE" style:letter-kerning="true" 
style:font-name-asian="Noto Sans CJK SC" style:font-size-asian="10.5pt" 
style:language-asian="zh" style:country-asian="CN" 
style:font-name-complex="Lohit Devanagari1" style:font-size-complex="12pt" 
style:language-complex="hi" style:country-complex="IN"/>
+  </style:default-style>
+  <style:default-style style:family="paragraph">
+   <style:paragraph-properties fo:orphans="2" fo:widows="2" 
fo:hyphenation-ladder-count="no-limit" style:text-autospace="ideograph-alpha" 
style:punctuation-wrap="hanging" style:line-break="strict" 
style:tab-stop-distance="1.251cm" style:writing-mode="page"/>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" 
fo:language="de" fo:country="DE" style:letter-kerning="true" 
style:font-name-asian="Noto Sans CJK SC" style:font-size-asian="10.5pt" 
style:language-asian="zh" style:country-asian="CN" 
style:font-name-complex="Lohit Devanagari1" style:font-size-complex="12pt" 
style:language-complex="hi" style:country-complex="IN" fo:hyphenate="false" 
fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2" 
loext:hyphenation-no-caps="false" loext:hyphenation-no-last-word="false" 
loext:hyphenation-word-char-count="5" loext:hyphenation-zone="no-limit"/>
+  </style:default-style>
+  <style:default-style style:family="table">
+   <style:table-properties table:border-model="collapsing"/>
+  </style:default-style>
+  <style:default-style style:family="table-row">
+   <style:table-row-properties fo:keep-together="auto"/>
+  </style:default-style>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text"/>
+  <text:outline-style style:name="Outline">
+   <text:outline-level-style text:level="1" loext:num-list-format="%1%" 
style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="2" loext:num-list-format="%2%" 
style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="3" loext:num-list-format="%3%" 
style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="4" loext:num-list-format="%4%" 
style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="5" loext:num-list-format="%5%" 
style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="6" loext:num-list-format="%6%" 
style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="7" loext:num-list-format="%7%" 
style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="8" loext:num-list-format="%8%" 
style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="9" loext:num-list-format="%9%" 
style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="10" loext:num-list-format="%10%" 
style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+  </text:outline-style>
+  <text:notes-configuration text:note-class="footnote" style:num-format="1" 
text:start-value="0" text:footnotes-position="page" 
text:start-numbering-at="document"/>
+  <text:notes-configuration text:note-class="endnote" style:num-format="i" 
text:start-value="0"/>
+  <text:linenumbering-configuration text:number-lines="false" 
text:offset="0.499cm" style:num-format="1" text:number-position="left" 
text:increment="5"/>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P2" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:text-properties/>
+  </style:style>
+  <style:style style:name="P3" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:paragraph-properties fo:break-before="page"/>
+   <style:text-properties/>
+  </style:style>
+  <style:style style:name="Sect1" style:family="section">
+   <style:section-properties style:editable="false">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+   </style:section-properties>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" 
fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" 
fo:margin-right="2cm" style:writing-mode="lr-tb" 
style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" 
style:layout-grid-base-height="0.706cm" style:layout-grid-ruby-height="0.353cm" 
style:layout-grid-mode="none" style:layout-grid-ruby-below="false" 
style:layout-grid-print="false" style:layout-grid-display="false" 
style:footnote-max-height="0cm" loext:margin-gutter="0cm">
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="solid" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style/>
+  </style:page-layout>
+  <style:style style:name="dp1" style:family="drawing-page">
+   <style:drawing-page-properties draw:background-size="full"/>
+  </style:style>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1" 
draw:style-name="dp1"/>
+  </office:master-styles>
+ <office:body>
+  <office:text text:use-soft-page-breaks="true">
+   <text:sequence-decls>
+    <text:sequence-decl text:display-outline-level="0" 
text:name="Illustration"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Table"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Figure"/>
+   </text:sequence-decls>
+   <text:section text:style-name="Sect1" text:name="Section1">
+    <text:p text:style-name="P2">1</text:p>
+    <text:p text:style-name="P3">2</text:p>
+    <text:section text:style-name="Sect1" text:name="Section2">
+     <text:p text:style-name="P2">3</text:p>
+    </text:section>
+    <text:p text:style-name="P2">4</text:p>
+    <text:p text:style-name="P3">5</text:p>
+   </text:section>
+   <text:p text:style-name="P2">6</text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 903bda81154b..47bd983dea84 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -3465,6 +3465,143 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf149140)
     CPPUNIT_ASSERT_EQUAL(int(6), nTH);
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testNestedSection)
+{
+    aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+
+    // Enable PDF/UA
+    uno::Sequence<beans::PropertyValue> aFilterData(
+        comphelper::InitPropertySequence({ { "PDFUACompliance", uno::Any(true) 
} }));
+    aMediaDescriptor["FilterData"] <<= aFilterData;
+    saveAsPDF(u"nestedsection.fodt");
+
+    vcl::filter::PDFDocument aDocument;
+    SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
+    CPPUNIT_ASSERT(aDocument.Read(aStream));
+
+    // the assert needs 2 follows to reproduce => 3 pages
+    std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aPages.size());
+
+    auto nDoc(0);
+    for (const auto& rDocElement : aDocument.GetElements())
+    {
+        auto pObject1 = 
dynamic_cast<vcl::filter::PDFObjectElement*>(rDocElement.get());
+        if (!pObject1)
+            continue;
+        auto pType1 = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject1->Lookup("Type"));
+        if (pType1 && pType1->GetValue() == "StructElem")
+        {
+            auto pS1 = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject1->Lookup("S"));
+            if (pS1 && pS1->GetValue() == "Document")
+            {
+                auto pKids1 = 
dynamic_cast<vcl::filter::PDFArrayElement*>(pObject1->Lookup("K"));
+                CPPUNIT_ASSERT(pKids1);
+                // assume there are no MCID ref at this level
+                auto pKids1v = pKids1->GetElements();
+                auto pRefKid10 = 
dynamic_cast<vcl::filter::PDFReferenceElement*>(pKids1v[0]);
+                CPPUNIT_ASSERT(pRefKid10);
+                auto pObject10 = pRefKid10->LookupObject();
+                CPPUNIT_ASSERT(pObject10);
+                auto pType10
+                    = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject10->Lookup("Type"));
+                CPPUNIT_ASSERT_EQUAL(OString("StructElem"), 
pType10->GetValue());
+                auto pS10 = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject10->Lookup("S"));
+                CPPUNIT_ASSERT_EQUAL(OString("Sect"), pS10->GetValue());
+
+                auto pKids10 = 
dynamic_cast<vcl::filter::PDFArrayElement*>(pObject10->Lookup("K"));
+                CPPUNIT_ASSERT(pKids10);
+                // assume there are no MCID ref at this level
+                auto pKids10v = pKids10->GetElements();
+
+                auto pRefKid100 = 
dynamic_cast<vcl::filter::PDFReferenceElement*>(pKids10v[0]);
+                CPPUNIT_ASSERT(pRefKid100);
+                auto pObject100 = pRefKid100->LookupObject();
+                CPPUNIT_ASSERT(pObject100);
+                auto pType100
+                    = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject100->Lookup("Type"));
+                CPPUNIT_ASSERT_EQUAL(OString("StructElem"), 
pType100->GetValue());
+                auto pS100 = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject100->Lookup("S"));
+                CPPUNIT_ASSERT_EQUAL(OString("Standard"), pS100->GetValue());
+
+                auto pRefKid101 = 
dynamic_cast<vcl::filter::PDFReferenceElement*>(pKids10v[1]);
+                CPPUNIT_ASSERT(pRefKid101);
+                auto pObject101 = pRefKid101->LookupObject();
+                CPPUNIT_ASSERT(pObject101);
+                auto pType101
+                    = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject101->Lookup("Type"));
+                CPPUNIT_ASSERT_EQUAL(OString("StructElem"), 
pType101->GetValue());
+                auto pS101 = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject101->Lookup("S"));
+                CPPUNIT_ASSERT_EQUAL(OString("Standard"), pS101->GetValue());
+
+                auto pRefKid102 = 
dynamic_cast<vcl::filter::PDFReferenceElement*>(pKids10v[2]);
+                CPPUNIT_ASSERT(pRefKid102);
+                auto pObject102 = pRefKid102->LookupObject();
+                CPPUNIT_ASSERT(pObject102);
+                auto pType102
+                    = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject102->Lookup("Type"));
+                CPPUNIT_ASSERT_EQUAL(OString("StructElem"), 
pType102->GetValue());
+                auto pS102 = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject102->Lookup("S"));
+                CPPUNIT_ASSERT_EQUAL(OString("Sect"), pS102->GetValue());
+
+                auto pKids102
+                    = 
dynamic_cast<vcl::filter::PDFArrayElement*>(pObject102->Lookup("K"));
+                CPPUNIT_ASSERT(pKids102);
+                // assume there are no MCID ref at this level
+                auto pKids102v = pKids102->GetElements();
+
+                auto pRefKid1020 = 
dynamic_cast<vcl::filter::PDFReferenceElement*>(pKids102v[0]);
+                CPPUNIT_ASSERT(pRefKid1020);
+                auto pObject1020 = pRefKid1020->LookupObject();
+                CPPUNIT_ASSERT(pObject1020);
+                auto pType1020
+                    = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject1020->Lookup("Type"));
+                CPPUNIT_ASSERT_EQUAL(OString("StructElem"), 
pType1020->GetValue());
+                auto pS1020 = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject1020->Lookup("S"));
+                CPPUNIT_ASSERT_EQUAL(OString("Standard"), pS1020->GetValue());
+
+                CPPUNIT_ASSERT_EQUAL(size_t(1), pKids102v.size());
+
+                auto pRefKid103 = 
dynamic_cast<vcl::filter::PDFReferenceElement*>(pKids10v[3]);
+                CPPUNIT_ASSERT(pRefKid103);
+                auto pObject103 = pRefKid103->LookupObject();
+                CPPUNIT_ASSERT(pObject103);
+                auto pType103
+                    = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject103->Lookup("Type"));
+                CPPUNIT_ASSERT_EQUAL(OString("StructElem"), 
pType103->GetValue());
+                auto pS103 = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject103->Lookup("S"));
+                CPPUNIT_ASSERT_EQUAL(OString("Standard"), pS103->GetValue());
+
+                auto pRefKid104 = 
dynamic_cast<vcl::filter::PDFReferenceElement*>(pKids10v[4]);
+                CPPUNIT_ASSERT(pRefKid104);
+                auto pObject104 = pRefKid104->LookupObject();
+                CPPUNIT_ASSERT(pObject104);
+                auto pType104
+                    = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject104->Lookup("Type"));
+                CPPUNIT_ASSERT_EQUAL(OString("StructElem"), 
pType104->GetValue());
+                auto pS104 = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject104->Lookup("S"));
+                CPPUNIT_ASSERT_EQUAL(OString("Standard"), pS104->GetValue());
+
+                CPPUNIT_ASSERT_EQUAL(size_t(5), pKids10v.size());
+
+                auto pRefKid11 = 
dynamic_cast<vcl::filter::PDFReferenceElement*>(pKids1v[1]);
+                CPPUNIT_ASSERT(pRefKid11);
+                auto pObject11 = pRefKid11->LookupObject();
+                CPPUNIT_ASSERT(pObject11);
+                auto pType11
+                    = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject11->Lookup("Type"));
+                CPPUNIT_ASSERT_EQUAL(OString("StructElem"), 
pType11->GetValue());
+                auto pS11 = 
dynamic_cast<vcl::filter::PDFNameElement*>(pObject11->Lookup("S"));
+                CPPUNIT_ASSERT_EQUAL(OString("Standard"), pS11->GetValue());
+
+                CPPUNIT_ASSERT_EQUAL(size_t(2), pKids1v.size());
+                ++nDoc;
+            }
+        }
+    }
+    CPPUNIT_ASSERT_EQUAL(static_cast<decltype(nDoc)>(1), nDoc);
+}
+
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf135638)
 {
     aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
commit 8c94442fab9588dd0793a1792979f50a600c4c65
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Aug 31 19:01:47 2023 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Sep 26 21:13:12 2023 +0200

    tdf#156306 sw: PDF export: refactor, split out BeginTagImpl()
    
    Change-Id: Ifcb8db6d9a5caaf50c0ca2794266fb501b59dee0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156356
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 7aca867aa1e1e675c0a9d27d76bd069bc6d5f512)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157228
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/inc/EnhancedPDFExportHelper.hxx 
b/sw/inc/EnhancedPDFExportHelper.hxx
index 8ae8d812b71a..53fbbbe4bab1 100644
--- a/sw/inc/EnhancedPDFExportHelper.hxx
+++ b/sw/inc/EnhancedPDFExportHelper.hxx
@@ -146,6 +146,7 @@ class SwTaggedPDFHelper
     const Frame_Info* mpFrameInfo;
     const Por_Info* mpPorInfo;
 
+    sal_Int32 BeginTagImpl(void const* pKey,vcl::PDFWriter::StructElement 
aTagRole, const OUString& rTagName);
     void BeginTag( vcl::PDFWriter::StructElement aTagRole, const OUString& 
rTagName );
     void EndTag();
 
diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx 
b/sw/source/core/text/EnhancedPDFExportHelper.cxx
index ad025d96a7d0..315c2e1b7429 100644
--- a/sw/source/core/text/EnhancedPDFExportHelper.cxx
+++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx
@@ -479,11 +479,27 @@ void SwTaggedPDFHelper::CheckRestoreTag() const
     }
 }
 
+sal_Int32 SwTaggedPDFHelper::BeginTagImpl(void const*const pKey,
+    vcl::PDFWriter::StructElement const eType, const OUString& rString)
+{
+    // write new tag
+    const sal_Int32 nId = mpPDFExtOutDevData->EnsureStructureElement(pKey);
+    mpPDFExtOutDevData->InitStructureElement(nId, eType, rString);
+    mpPDFExtOutDevData->BeginStructureElement(nId);
+    ++m_nEndStructureElement;
+
+#if OSL_DEBUG_LEVEL > 1
+    aStructStack.push_back( o3tl::narrowing<sal_uInt16>(eType) );
+#endif
+
+    return nId;
+}
+
 void SwTaggedPDFHelper::BeginTag( vcl::PDFWriter::StructElement eType, const 
OUString& rString )
 {
     void const* pKey(nullptr);
 
-    if (mpFrameInfo && eType != vcl::PDFWriter::LIBody && eType != 
vcl::PDFWriter::TOCI)
+    if (mpFrameInfo)
     {
         const SwFrame& rFrame = mpFrameInfo->mrFrame;
 
@@ -504,15 +520,7 @@ void SwTaggedPDFHelper::BeginTag( 
vcl::PDFWriter::StructElement eType, const OUS
         }
     }
 
-    // write new tag
-    const sal_Int32 nId = mpPDFExtOutDevData->EnsureStructureElement(pKey);
-    mpPDFExtOutDevData->InitStructureElement(nId, eType, rString);
-    mpPDFExtOutDevData->BeginStructureElement(nId);
-    ++m_nEndStructureElement;
-
-#if OSL_DEBUG_LEVEL > 1
-    aStructStack.push_back( o3tl::narrowing<sal_uInt16>(eType) );
-#endif
+    sal_Int32 const nId = BeginTagImpl(pKey, eType, rString);
 
     // Store the id of the current structure element if
     // - it is a list structure element
@@ -539,19 +547,6 @@ void SwTaggedPDFHelper::BeginTag( 
vcl::PDFWriter::StructElement eType, const OUS
             rNumListBodyIdMap[ pNodeNum ] = nId;
         }
     }
-    else if ( mpFrameInfo )
-    {
-        const SwFrame& rFrame = mpFrameInfo->mrFrame;
-
-        if (vcl::PDFWriter::LIBody == eType && rFrame.IsTextFrame())
-        {
-            SwTextFrame const& rTextFrame(static_cast<const 
SwTextFrame&>(rFrame));
-            SwTextNode const*const 
pTextNd(rTextFrame.GetTextNodeForParaProps());
-            SwNodeNum const*const 
pNodeNum(pTextNd->GetNum(rTextFrame.getRootFrame()));
-            NumListBodyIdMap& 
rNumListBodyIdMap(mpPDFExtOutDevData->GetSwPDFState()->m_NumListBodyIdMap);
-            rNumListBodyIdMap[ pNodeNum ] = nId;
-        }
-    }
 
     SetAttributes( eType );
 }
@@ -1265,14 +1260,17 @@ void SwTaggedPDFHelper::BeginBlockStructureElements()
         case SwFrameType::Txt :
             {
                 SwTextFrame const& rTextFrame(*static_cast<const 
SwTextFrame*>(pFrame));
+                const SwTextNode *const 
pTextNd(rTextFrame.GetTextNodeForParaProps());
+
                 // lazy open LBody after Lbl
                 if 
(rTextFrame.GetPara()->HasNumberingPortion(SwParaPortion::OnlyNumbering))
                 {
-                    BeginTag(vcl::PDFWriter::LIBody, aListBodyString);
+                    sal_Int32 const nId = BeginTagImpl(nullptr, 
vcl::PDFWriter::LIBody, aListBodyString);
+                    SwNodeNum const*const 
pNodeNum(pTextNd->GetNum(rTextFrame.getRootFrame()));
+                    NumListBodyIdMap& 
rNumListBodyIdMap(mpPDFExtOutDevData->GetSwPDFState()->m_NumListBodyIdMap);
+                    rNumListBodyIdMap[ pNodeNum ] = nId;
                 }
 
-                const SwTextNode *const 
pTextNd(rTextFrame.GetTextNodeForParaProps());
-
                 const SwFormat* pTextFormat = pTextNd->GetFormatColl();
                 const SwFormat* pParentTextFormat = pTextFormat ? 
pTextFormat->DerivedFrom() : nullptr;
 
@@ -1386,7 +1384,7 @@ void SwTaggedPDFHelper::BeginBlockStructureElements()
                         if ( pTOXBase && TOX_INDEX != pTOXBase->GetType() )
                         {
                             // Special case: Open additional TOCI tag:
-                            BeginTag( vcl::PDFWriter::TOCI, aTOCIString );
+                            BeginTagImpl(nullptr, vcl::PDFWriter::TOCI, 
aTOCIString);
                         }
                     }
                 }

Reply via email to