include/xmloff/txtparae.hxx                                   |    7 
 sd/qa/unit/data/odp/tdf161023.fodp                            |   35 -
 sd/qa/unit/import-tests2.cxx                                  |   52 --
 sw/qa/core/text/data/number-portion-format.odt                |binary
 sw/qa/extras/htmlexport/xhtmlexport.cxx                       |    4 
 sw/qa/extras/odfexport/data/table_in_frame_to_page.fodt       |   66 ---
 sw/qa/extras/odfexport/data/tdf160253_ordinary_numbering.fodt |   43 --
 sw/qa/extras/odfexport/data/tdf160253_outline_numbering.fodt  |   37 -
 sw/qa/extras/odfexport/odfexport2.cxx                         |   84 ----
 sw/qa/extras/odfimport/data/empty_line_in_text_box.fodt       |   31 -
 sw/qa/extras/odfimport/odfimport.cxx                          |   53 --
 sw/source/core/text/txtfld.cxx                                |   22 +
 sw/source/filter/ww8/ww8par.cxx                               |   19 
 sw/source/filter/ww8/ww8par.hxx                               |    2 
 sw/source/filter/ww8/ww8par2.cxx                              |    4 
 sw/source/filter/ww8/ww8par5.cxx                              |    2 
 sw/source/filter/ww8/ww8par6.cxx                              |    4 
 sw/source/filter/xml/xmlfmte.cxx                              |    2 
 xmloff/source/text/txtparae.cxx                               |  208 +++++++---
 xmloff/source/text/txtparai.cxx                               |   13 
 20 files changed, 213 insertions(+), 475 deletions(-)

New commits:
commit efedfae6a340bac4ad49843c178ae1b45a92352c
Author:     Thorsten Behrens <thorsten.behr...@allotropia.de>
AuthorDate: Thu Jun 20 23:38:43 2024 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Thu Jun 20 23:39:51 2024 +0200

    Revert attempted clipboard fixes on branch
    
    This is a squashed revert, consisting of:
    
    * Revert "tdf#161054: drop support of last empty span as paragraph mark 
format"
    * Revert "tdf#161023: Empty spans may only define paragraph marks in text 
documents"
    * Revert "This block seems obsolete now, try to drop it"
    * Revert "Make sure to export autostyles from inside frames anchored to 
page"
    * Revert "tdf#160253: fix list identifier export decision code"

diff --git a/include/xmloff/txtparae.hxx b/include/xmloff/txtparae.hxx
index ec07d1af8112..436c2d2b629e 100644
--- a/include/xmloff/txtparae.hxx
+++ b/include/xmloff/txtparae.hxx
@@ -114,8 +114,6 @@ class XMLOFF_DLLPUBLIC XMLTextParagraphExport : public 
XMLStyleExport
 
     struct DocumentListNodes;
     std::unique_ptr<DocumentListNodes> mpDocumentListNodes;
-    std::vector<sal_Int32> maDocumentNodeOrder;
-    bool bInDocumentNodeOrderCollection = false;
 
     o3tl::sorted_vector<css::uno::Reference<css::text::XTextFrame>> 
maFrameRecurseGuard;
     o3tl::sorted_vector<css::uno::Reference<css::drawing::XShape>> 
maShapeRecurseGuard;
@@ -474,7 +472,9 @@ public:
         exportText( rText, rBaseSection, true, bIsProgress, 
true/*bExportParagraph*/ );
     }
 
-    void collectTextAutoStylesAndNodeExportOrder(bool bIsProgress);
+    // It the model implements the xAutoStylesSupplier interface, the automatic
+    // styles can exported without iterating over the text portions
+    void collectTextAutoStylesOptimized( bool bIsProgress );
 
     // This method exports all automatic styles that have been collected.
     void exportTextAutoStyles();
@@ -540,7 +540,6 @@ public:
     void PopTextListsHelper();
 
 private:
-    void RecordNodeIndex(const css::uno::Reference<css::text::XTextContent>& 
xTextContent);
     bool ShouldSkipListId(const css::uno::Reference<css::text::XTextContent>& 
xTextContent);
     bool ExportListId() const;
 
diff --git a/sd/qa/unit/data/odp/tdf161023.fodp 
b/sd/qa/unit/data/odp/tdf161023.fodp
deleted file mode 100644
index bf3a894cec4b..000000000000
--- a/sd/qa/unit/data/odp/tdf161023.fodp
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible: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:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
office:version="1.3" 
office:mimetype="application/vnd.oasis.opendocument.presentation">
- <office:font-face-decls>
-  <style:font-face style:name="Liberation Sans" 
svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="roman" 
style:font-pitch="variable"/>
- </office:font-face-decls>
- <office:styles>
-  <style:style style:name="standard" style:family="graphic">
-   <style:text-properties style:font-name="Liberation Sans" 
fo:font-size="18pt"/>
-  </style:style>
- </office:styles>
- <office:automatic-styles>
-  <style:style style:name="T1" style:family="text">
-   <style:text-properties fo:font-size="10pt"/>
-  </style:style>
- </office:automatic-styles>
- <office:master-styles>
-  <draw:layer-set>
-   <draw:layer draw:name="layout"/>
-  </draw:layer-set>
- </office:master-styles>
- <office:body>
-  <office:presentation>
-   <draw:page draw:name="page1">
-    <draw:frame draw:layer="layout" svg:width="4cm" svg:x="4cm" svg:y="4cm">
-     <draw:text-box>
-      <text:p><text:span text:style-name="T1">a</text:span></text:p>
-      <text:p><text:span text:style-name="T1"/></text:p>
-      <text:p><text:span text:style-name="T1">c</text:span></text:p>
-     </draw:text-box>
-    </draw:frame>
-   </draw:page>
-  </office:presentation>
- </office:body>
-</office:document>
\ No newline at end of file
diff --git a/sd/qa/unit/import-tests2.cxx b/sd/qa/unit/import-tests2.cxx
index a69a30ef991a..ac730a24d6bf 100644
--- a/sd/qa/unit/import-tests2.cxx
+++ b/sd/qa/unit/import-tests2.cxx
@@ -1982,58 +1982,6 @@ CPPUNIT_TEST_FIXTURE(SdImportTest2, testMasterSlides)
     CPPUNIT_ASSERT_EQUAL(sal_Int32(7), xMasterPages->getCount());
 }
 
-CPPUNIT_TEST_FIXTURE(SdImportTest2, testTdf161023)
-{
-    // Given a shape with three paragraphs (18pt), all directly assigned a 
smaller font (10pt)
-    createSdImpressDoc("odp/tdf161023.fodp");
-    auto shape = getShapeFromPage(0, 0);
-
-    // 1st paragraph, not empty
-    {
-        auto paragraph(getParagraphFromShape(0, shape));
-        CPPUNIT_ASSERT_EQUAL(u"a"_ustr, paragraph->getString());
-        auto run(getRunFromParagraph(0, paragraph));
-        CPPUNIT_ASSERT_EQUAL(u"a"_ustr, run->getString());
-        uno::Reference<beans::XPropertySet> xPropSet(run, 
uno::UNO_QUERY_THROW);
-        double fCharHeight = 0;
-        xPropSet->getPropertyValue("CharHeight") >>= fCharHeight;
-        CPPUNIT_ASSERT_EQUAL(10.0, fCharHeight);
-        // No more runs
-        CPPUNIT_ASSERT_THROW(getRunFromParagraph(1, paragraph), 
container::NoSuchElementException);
-    }
-
-    // Empty 2nd paragraph, consisting of a single span: this span was treated 
as "paragraph mark"
-    {
-        auto paragraph(getParagraphFromShape(1, shape));
-        CPPUNIT_ASSERT_EQUAL(u""_ustr, paragraph->getString());
-        auto run(getRunFromParagraph(0, paragraph));
-        CPPUNIT_ASSERT_EQUAL(u""_ustr, run->getString());
-        uno::Reference<beans::XPropertySet> xPropSet(run, 
uno::UNO_QUERY_THROW);
-        double fCharHeight = 0;
-        xPropSet->getPropertyValue("CharHeight") >>= fCharHeight;
-        // Without the fix, this would fail with
-        // - Expected: 10
-        // - Actual  : 18
-        CPPUNIT_ASSERT_EQUAL(10.0, fCharHeight);
-        // No more runs
-        CPPUNIT_ASSERT_THROW(getRunFromParagraph(1, paragraph), 
container::NoSuchElementException);
-    }
-
-    // 3rd paragraph, not empty
-    {
-        auto paragraph(getParagraphFromShape(2, shape));
-        CPPUNIT_ASSERT_EQUAL(u"c"_ustr, paragraph->getString());
-        auto run(getRunFromParagraph(0, paragraph));
-        CPPUNIT_ASSERT_EQUAL(u"c"_ustr, run->getString());
-        uno::Reference<beans::XPropertySet> xPropSet(run, 
uno::UNO_QUERY_THROW);
-        double fCharHeight = 0;
-        xPropSet->getPropertyValue("CharHeight") >>= fCharHeight;
-        CPPUNIT_ASSERT_EQUAL(10.0, fCharHeight);
-        // No more runs
-        CPPUNIT_ASSERT_THROW(getRunFromParagraph(1, paragraph), 
container::NoSuchElementException);
-    }
-}
-
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/core/text/data/number-portion-format.odt 
b/sw/qa/core/text/data/number-portion-format.odt
index 70b67ee3547e..19b23ae84420 100644
Binary files a/sw/qa/core/text/data/number-portion-format.odt and 
b/sw/qa/core/text/data/number-portion-format.odt differ
diff --git a/sw/qa/extras/htmlexport/xhtmlexport.cxx 
b/sw/qa/extras/htmlexport/xhtmlexport.cxx
index b1c00a6f81e5..86026dbd70bd 100644
--- a/sw/qa/extras/htmlexport/xhtmlexport.cxx
+++ b/sw/qa/extras/htmlexport/xhtmlexport.cxx
@@ -176,9 +176,9 @@ CPPUNIT_TEST_FIXTURE(XHtmlExportTest, testTdf66305)
     sal_uInt64 nLength = pStream->TellEnd();
     OString aStream(read_uInt8s_ToOString(*pStream, nLength));
     CPPUNIT_ASSERT(
-        aStream.indexOf("<p class=\"paragraph-P5\"><a 
href=\"#__RefHeading__82004_486970805\" "
+        aStream.indexOf("<p class=\"paragraph-P6\"><a 
href=\"#__RefHeading__82004_486970805\" "
                         
"class=\"text-Internet_20_link\">Introduction</a></p><p "
-                        "class=\"paragraph-P6\"> </p>")
+                        "class=\"paragraph-P7\"> </p>")
         != -1);
 }
 
diff --git a/sw/qa/extras/odfexport/data/table_in_frame_to_page.fodt 
b/sw/qa/extras/odfexport/data/table_in_frame_to_page.fodt
deleted file mode 100644
index 998f7a08e590..000000000000
--- a/sw/qa/extras/odfexport/data/table_in_frame_to_page.fodt
+++ /dev/null
@@ -1,66 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible: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:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
- <office:automatic-styles>
-  <style:style style:name="P1" style:family="paragraph">
-   <style:text-properties fo:font-style="italic"/>
-  </style:style>
-  <style:style style:name="P2" style:family="paragraph">
-   <style:text-properties fo:font-weight="bold"/>
-  </style:style>
-  <style:style style:name="Table1" style:family="table">
-   <style:table-properties style:width="8cm" table:align="margins"/>
-  </style:style>
-  <style:style style:name="Table1.A" style:family="table-column">
-   <style:table-column-properties style:column-width="4cm" 
style:rel-column-width="32767*"/>
-  </style:style>
-  <style:style style:name="Table1.B" style:family="table-column">
-   <style:table-column-properties style:column-width="4cm" 
style:rel-column-width="32768*"/>
-  </style:style>
-  <style:style style:name="Table1.A1" style:family="table-cell">
-   <style:table-cell-properties fo:padding="1mm" fo:border-left="0.5pt solid 
#000000" fo:border-right="none" fo:border-top="0.5pt solid #000000" 
fo:border-bottom="0.5pt solid #000000"/>
-  </style:style>
-  <style:style style:name="Table1.B1" style:family="table-cell">
-   <style:table-cell-properties fo:padding="1mm" fo:border="0.5pt solid 
#000000"/>
-  </style:style>
-  <style:style style:name="Table1.A2" style:family="table-cell">
-   <style:table-cell-properties fo:padding="1mm" fo:border-left="0.5pt solid 
#000000" fo:border-right="none" fo:border-top="none" fo:border-bottom="0.5pt 
solid #000000"/>
-  </style:style>
-  <style:style style:name="Table1.B2" style:family="table-cell">
-   <style:table-cell-properties fo:padding="1mm" fo:border-left="0.5pt solid 
#000000" fo:border-right="0.5pt solid #000000" fo:border-top="none" 
fo:border-bottom="0.5pt solid #000000"/>
-  </style:style>
-  <style:style style:name="fr1" style:family="graphic" 
style:parent-style-name="Frame">
-   <style:graphic-properties style:wrap="parallel" 
style:number-wrapped-paragraphs="no-limit" style:vertical-pos="from-top" 
style:vertical-rel="page" style:horizontal-pos="from-left" 
style:horizontal-rel="page" draw:wrap-influence-on-position="once-concurrent"/>
-  </style:style>
- </office:automatic-styles>
- <office:body>
-  <office:text>
-   <draw:frame draw:style-name="fr1" draw:name="Frame1" 
text:anchor-type="page" text:anchor-page-number="1" svg:x="5cm" svg:y="1cm" 
svg:width="8cm" draw:z-index="0">
-    <draw:text-box fo:min-height="5cm">
-     <table:table table:name="Table1" table:style-name="Table1">
-      <table:table-column table:style-name="Table1.A"/>
-      <table:table-column table:style-name="Table1.B"/>
-      <table:table-row>
-       <table:table-cell table:style-name="Table1.A1" 
office:value-type="string">
-        <text:p text:style-name="P1"/>
-       </table:table-cell>
-       <table:table-cell table:style-name="Table1.B1" 
office:value-type="string">
-        <text:p/>
-       </table:table-cell>
-      </table:table-row>
-      <table:table-row>
-       <table:table-cell table:style-name="Table1.A2" 
office:value-type="string">
-        <text:p/>
-       </table:table-cell>
-       <table:table-cell table:style-name="Table1.B2" 
office:value-type="string">
-        <text:p/>
-       </table:table-cell>
-      </table:table-row>
-     </table:table>
-     <text:p text:style-name="P2"/>
-    </draw:text-box>
-   </draw:frame>
-   <text:p/>
-  </office:text>
- </office:body>
-</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/odfexport/data/tdf160253_ordinary_numbering.fodt 
b/sw/qa/extras/odfexport/data/tdf160253_ordinary_numbering.fodt
deleted file mode 100644
index ca5c1128d1c0..000000000000
--- a/sw/qa/extras/odfexport/data/tdf160253_ordinary_numbering.fodt
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
- <office:automatic-styles>
-  <text:list-style style:name="L1">
-   <text:list-level-style-number text:level="1" style:num-suffix="." 
style:num-format="1">
-    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
-     <style:list-level-label-alignment text:label-followed-by="space"/>
-    </style:list-level-properties>
-   </text:list-level-style-number>
-  </text:list-style>
-  <text:list-style style:name="L2">
-   <text:list-level-style-bullet text:level="1" text:bullet-char="•">
-    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
-     <style:list-level-label-alignment text:label-followed-by="space" 
fo:text-indent="-0.5cm" fo:margin-left="1cm"/>
-    </style:list-level-properties>
-   </text:list-level-style-bullet>
-  </text:list-style>
- </office:automatic-styles>
- <office:body>
-  <office:text>
-   <text:list xml:id="list1" text:style-name="L1">
-    <text:list-item>
-     <text:p>a</text:p>
-    </text:list-item>
-    <text:list-item>
-     <text:p>b</text:p>
-    </text:list-item>
-   </text:list>
-   <text:p>c<text:note text:id="ftn1" 
text:note-class="endnote"><text:note-citation>i</text:note-citation><text:note-body>
-      <text:list text:style-name="L2">
-       <text:list-item>
-        <text:p>xyz</text:p>
-       </text:list-item>
-      </text:list></text:note-body></text:note></text:p>
-   <text:list text:continue-list="list1" text:style-name="L1">
-    <text:list-item>
-     <text:p>d</text:p>
-    </text:list-item>
-   </text:list>
-  </office:text>
- </office:body>
-</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/odfexport/data/tdf160253_outline_numbering.fodt 
b/sw/qa/extras/odfexport/data/tdf160253_outline_numbering.fodt
deleted file mode 100644
index 2eddd6dd4593..000000000000
--- a/sw/qa/extras/odfexport/data/tdf160253_outline_numbering.fodt
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
- <office:styles>
-  <style:style style:name="Heading" style:family="paragraph" 
style:default-outline-level="1" style:list-style-name="Numbering_20_1" 
style:class="text"/>
-  <style:style style:name="Heading_20_1" style:display-name="Heading 1" 
style:family="paragraph" style:parent-style-name="Heading" 
style:next-style-name="Text_20_body" style:default-outline-level="1" 
style:list-style-name="Outline" style:class="text">
-   <style:text-properties fo:font-weight="bold"/>
-  </style:style>
-  <text:outline-style style:name="Outline">
-   <text:outline-level-style text:level="1" style:num-format="1">
-    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
-     <style:list-level-label-alignment text:label-followed-by="space"/>
-    </style:list-level-properties>
-   </text:outline-level-style>
-  </text:outline-style>
-  <text:list-style style:name="Numbering_20_1" style:display-name="Numbering 
1">
-   <text:list-level-style-number text:level="1" style:num-format="1"/>
-  </text:list-style>
- </office:styles>
- <office:master-styles>
-  <style:master-page style:name="Standard"/>
-  <style:master-page style:name="Endnote"/>
- </office:master-styles>
- <office:automatic-styles>
-  <text:list-style style:name="L1">
-   <text:list-level-style-bullet text:level="1" text:bullet-char="•"/>
-  </text:list-style>
- </office:automatic-styles>
- <office:body>
-  <office:text>
-   <text:h text:style-name="Heading_20_1" text:outline-level="1">foo</text:h>
-   <text:p>xyz<text:note text:id="ftn1" 
text:note-class="endnote"><text:note-citation>i</text:note-citation><text:note-body>
-    <text:list 
text:style-name="L1"><text:list-item><text:p>abc</text:p></text:list-item></text:list></text:note-body></text:note></text:p>
-   <text:h text:style-name="Heading_20_1" text:outline-level="1">bar</text:h>
-  </office:text>
- </office:body>
-</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/odfexport/odfexport2.cxx 
b/sw/qa/extras/odfexport/odfexport2.cxx
index 51c77cba4e78..1a06a8eaf268 100644
--- a/sw/qa/extras/odfexport/odfexport2.cxx
+++ b/sw/qa/extras/odfexport/odfexport2.cxx
@@ -111,14 +111,10 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf106733)
     CPPUNIT_ASSERT_EQUAL(1, getPages());
     xmlDocUniquePtr pXmlDoc = parseExport("content.xml");
 
-    OUString autostyle = getXPath(pXmlDoc, 
"//office:body/office:text/text:p[2]/text:span"_ostr,
-                                  "style-name"_ostr);
-    OString autostyle_span_xpath = "//style:style[@style:name='" + 
autostyle.toUtf8() + "']";
-
     // keep fo:hyphenate="false" in direct formatting
     assertXPath(
         pXmlDoc,
-        autostyle_span_xpath + "/style:text-properties",
+        "//style:style[@style:name='T3']/style:text-properties"_ostr,
         "hyphenate"_ostr, "false");
 
     // keep fo:hyphenate="false" in character style
@@ -1154,13 +1150,9 @@ CPPUNIT_TEST_FIXTURE(Test, 
testParagraphMarkerMarkupRoundtrip)
     loadAndReload("ParagraphMarkerMarkup.fodt");
     // Test that the markup stays at save-and-reload
     xmlDocUniquePtr pXmlDoc = parseExport("content.xml");
-    OUString autostyle
-        = getXPath(pXmlDoc, "//office:body/office:text/text:p"_ostr, 
"marker-style-name"_ostr);
-    OString style_text_properties
-        = 
"/office:document-content/office:automatic-styles/style:style[@style:name='"
-          + autostyle.toUtf8() + "']/style:text-properties";
-    assertXPath(pXmlDoc, style_text_properties, "font-size"_ostr, "9pt");
-    assertXPath(pXmlDoc, style_text_properties, "color"_ostr, "#ff0000");
+    assertXPath(pXmlDoc, 
"/office:document-content/office:body/office:text/text:p"_ostr, 
"marker-style-name"_ostr, "T2");
+    assertXPath(pXmlDoc, 
"/office:document-content/office:automatic-styles/style:style[@style:name='T2']/style:text-properties"_ostr,
 "font-size"_ostr, "9pt");
+    assertXPath(pXmlDoc, 
"/office:document-content/office:automatic-styles/style:style[@style:name='T2']/style:text-properties"_ostr,
 "color"_ostr, "#ff0000");
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testCommentStyles)
@@ -1438,74 +1430,6 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf160700)
     assertXPath(pXmlDoc, 
"//office:text/text:list/text:list-item/text:p/text:bookmark"_ostr);
 }
 
-CPPUNIT_TEST_FIXTURE(Test, testTdf160253_ordinary_numbering)
-{
-    // Given a document with a list, and an out-of-the-list paragraph in the 
middle, having an
-    // endnote, which has a paragraph in another list.
-    // Before the fix, this already failed with
-    //   Error: "list2916587379" is referenced by an IDREF, but not defined.
-    loadAndReload("tdf160253_ordinary_numbering.fodt");
-
-    // Make sure that the fourth paragraph has correct number - it was "1." 
before the fix
-    CPPUNIT_ASSERT_EQUAL(u"3."_ustr,
-                         getProperty<OUString>(getParagraph(4), 
u"ListLabelString"_ustr));
-
-    // Make sure that we emit an identifier for the first list, and refer to 
it in the continuation
-    xmlDocUniquePtr pXmlDoc = parseExport("content.xml");
-    // This failed before the fix, because 'xml:id' attribute wasn't emitted
-    OUString firstListId
-        = getXPath(pXmlDoc, "//office:body/office:text/text:list[1]"_ostr, 
"id"_ostr);
-    CPPUNIT_ASSERT(!firstListId.isEmpty());
-    assertXPath(pXmlDoc, "//office:body/office:text/text:list[2]"_ostr, 
"continue-list"_ostr,
-                firstListId);
-}
-
-CPPUNIT_TEST_FIXTURE(Test, testTdf160253_outline_numbering)
-{
-    // Given a document with an outline (chapter) numbering, and a paragraph 
in the middle, having
-    // an endnote, which has a paragraph in a list.
-    // Before the fix, this already failed with
-    //   Error: "list2916587379" is referenced by an IDREF, but not defined.
-    loadAndReload("tdf160253_outline_numbering.fodt");
-
-    // Make sure that the third paragraph has correct number - it was "1" 
before the fix
-    CPPUNIT_ASSERT_EQUAL(u"2"_ustr,
-                         getProperty<OUString>(getParagraph(3), 
u"ListLabelString"_ustr));
-
-    // The difference with the ordinary numbering is that for outline 
numbering, the list element
-    // isn't really necessary. It is a TODO to fix the output, and not export 
the list.
-    // xmlDocUniquePtr pXmlDoc = parseExport("content.xml");
-    // assertXPath(pXmlDoc, "//office:body/office:text/text:list"_ostr, 0);
-}
-
-CPPUNIT_TEST_FIXTURE(Test, testTableInFrameAnchoredToPage)
-{
-    // Given a table in a frame anchored to a page:
-    // it must not assert on export because of missing format for an exported 
table
-    loadAndReload("table_in_frame_to_page.fodt");
-
-    // Check also, that autostyles defined inside that frame are stored 
correctly. If not, then
-    // these paragraphs would refer to styles in <office::styles>, not in 
<office:automatic-styles>,
-    // without the 'italic' and 'bold' attributes.
-    xmlDocUniquePtr pXmlDoc = parseExport("content.xml");
-    OUString P1 = getXPath(
-        pXmlDoc,
-        
"//office:body/office:text/draw:frame/draw:text-box/table:table/table:table-row[1]/"
-        "table:table-cell[1]/text:p"_ostr,
-        "style-name"_ostr);
-    assertXPath(pXmlDoc,
-                "//office:automatic-styles/style:style[@style:name='"_ostr + 
P1.toUtf8()
-                    + "']/style:text-properties",
-                "font-style"_ostr, u"italic"_ustr);
-    OUString P2
-        = getXPath(pXmlDoc, 
"//office:body/office:text/draw:frame/draw:text-box/text:p"_ostr,
-                   "style-name"_ostr);
-    assertXPath(pXmlDoc,
-                "//office:automatic-styles/style:style[@style:name='"_ostr + 
P2.toUtf8()
-                    + "']/style:text-properties",
-                "font-weight"_ostr, u"bold"_ustr);
-}
-
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/odfimport/data/empty_line_in_text_box.fodt 
b/sw/qa/extras/odfimport/data/empty_line_in_text_box.fodt
deleted file mode 100644
index 4ae36a9c5fac..000000000000
--- a/sw/qa/extras/odfimport/data/empty_line_in_text_box.fodt
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible: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:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
- <office:font-face-decls>
-  <style:font-face style:name="Liberation Sans" 
svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" 
style:font-pitch="variable"/>
- </office:font-face-decls>
- <office:styles>
-  <style:default-style style:family="graphic">
-   <style:text-properties style:font-name="Liberation Sans" 
fo:font-size="18pt"/>
-  </style:default-style>
- </office:styles>
- <office:automatic-styles>
-  <style:style style:name="T1" style:family="text">
-   <style:text-properties fo:font-size="10pt"/>
-  </style:style>
-  <style:style style:name="gr1" style:family="graphic">
-   <style:graphic-properties style:vertical-pos="from-top" 
style:vertical-rel="paragraph" style:horizontal-pos="from-left" 
style:horizontal-rel="paragraph"/>
-  </style:style>
- </office:automatic-styles>
- <office:body>
-  <office:text>
-   <text:p text:style-name="Standard"><draw:frame text:anchor-type="paragraph" 
draw:name="TextFrame1" draw:style-name="gr1" svg:width="4cm" svg:x="4cm" 
svg:y="4cm">
-     <draw:text-box>
-      <text:p><text:span text:style-name="T1">a</text:span></text:p>
-      <text:p><text:span text:style-name="T1"/></text:p>
-      <text:p><text:span text:style-name="T1">c</text:span></text:p>
-     </draw:text-box>
-    </draw:frame></text:p>
-  </office:text>
- </office:body>
-</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/odfimport/odfimport.cxx 
b/sw/qa/extras/odfimport/odfimport.cxx
index 0074b53f851e..70c6452e3d9f 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -1561,58 +1561,5 @@ CPPUNIT_TEST_FIXTURE(Test, testBrokenPackage_Tdf159474)
     CPPUNIT_ASSERT_EQUAL(u"Empty document"_ustr, getParagraph(1)->getString());
 }
 
-CPPUNIT_TEST_FIXTURE(Test, testTdf161054)
-{
-    // Similar to testTdf161023 in sd/qa/unit/import-tests2.cxx
-    // Given a shape with three paragraphs (18pt), all directly assigned a 
smaller font (10pt)
-    createSwDoc("empty_line_in_text_box.fodt");
-    auto shapeText = getShape(1).queryThrow<text::XTextRange>()->getText();
-
-    // 1st paragraph, not empty
-    {
-        auto paragraph(getParagraphOfText(1, shapeText));
-        CPPUNIT_ASSERT_EQUAL(u"a"_ustr, paragraph->getString());
-        auto run(getRun(paragraph, 1));
-        CPPUNIT_ASSERT_EQUAL(u"a"_ustr, run->getString());
-        uno::Reference<beans::XPropertySet> xPropSet(run, 
uno::UNO_QUERY_THROW);
-        double fCharHeight = 0;
-        xPropSet->getPropertyValue("CharHeight") >>= fCharHeight;
-        CPPUNIT_ASSERT_EQUAL(10.0, fCharHeight);
-        // No more runs
-        CPPUNIT_ASSERT_THROW(getRun(paragraph, 2), 
container::NoSuchElementException);
-    }
-
-    // Empty 2nd paragraph, consisting of a single span: this span was treated 
as "paragraph mark"
-    {
-        auto paragraph(getParagraphOfText(2, shapeText));
-        CPPUNIT_ASSERT_EQUAL(u""_ustr, paragraph->getString());
-        auto run(getRun(paragraph, 1));
-        CPPUNIT_ASSERT_EQUAL(u""_ustr, run->getString());
-        uno::Reference<beans::XPropertySet> xPropSet(run, 
uno::UNO_QUERY_THROW);
-        double fCharHeight = 0;
-        xPropSet->getPropertyValue("CharHeight") >>= fCharHeight;
-        // Without the fix, this would fail with
-        // - Expected: 10
-        // - Actual  : 18
-        CPPUNIT_ASSERT_EQUAL(10.0, fCharHeight);
-        // No more runs
-        CPPUNIT_ASSERT_THROW(getRun(paragraph, 2), 
container::NoSuchElementException);
-    }
-
-    // 3rd paragraph, not empty
-    {
-        auto paragraph(getParagraphOfText(3, shapeText));
-        CPPUNIT_ASSERT_EQUAL(u"c"_ustr, paragraph->getString());
-        auto run(getRun(paragraph, 1));
-        CPPUNIT_ASSERT_EQUAL(u"c"_ustr, run->getString());
-        uno::Reference<beans::XPropertySet> xPropSet(run, 
uno::UNO_QUERY_THROW);
-        double fCharHeight = 0;
-        xPropSet->getPropertyValue("CharHeight") >>= fCharHeight;
-        CPPUNIT_ASSERT_EQUAL(10.0, fCharHeight);
-        // No more runs
-        CPPUNIT_ASSERT_THROW(getRun(paragraph, 2), 
container::NoSuchElementException);
-    }
-}
-
 CPPUNIT_PLUGIN_IMPLEMENT();
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx
index 2d721fd3b112..84f32e30971f 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -657,6 +657,28 @@ SwNumberPortion *SwTextFormatter::NewNumberPortion( 
SwTextFormatInfo &rInf ) con
                     // Build a new numbering font basing on the current 
paragraph font:
                     std::unique_ptr<SwFont> pNumFnt(new SwFont( 
&rInf.GetCharAttr(), pIDSA ));
 
+                    const SwTextNode& rTextNode = 
*rInf.GetTextFrame()->GetTextNodeForParaProps();
+                    if (const SwpHints* pHints = rTextNode.GetpSwpHints())
+                    {
+                        // Also look for an empty character hint that sits at 
the paragraph end:
+                        for (size_t i = 0; i < pHints->Count(); ++i)
+                        {
+                            const SwTextAttr* pHint = 
pHints->GetSortedByEnd(i);
+                            if (pHint->Which() == RES_TXTATR_AUTOFMT && 
pHint->GetEnd()
+                                && pHint->GetStart() == *pHint->GetEnd()
+                                && pHint->GetStart() == 
rTextNode.GetText().getLength())
+                            {
+                                std::shared_ptr<SfxItemSet> pSet
+                                    = pHint->GetAutoFormat().GetStyleHandle();
+                                if (pSet)
+                                {
+                                    pNumFnt->SetDiffFnt(pSet.get(), pIDSA);
+                                    break;
+                                }
+                            }
+                        }
+                    }
+
                     // #i53199#
                     if ( 
!pIDSA->get(DocumentSettingId::DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT) )
                     {
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 27d6032dd4d2..a2d959d7d3f7 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -2478,7 +2478,7 @@ void wwSectionManager::SetHdFt(wwSection const &rSection, 
int nSect,
 
 }
 
-void SwWW8ImplReader::FinalizeTextNode(SwPosition& rPos, bool bAddNew)
+void SwWW8ImplReader::AppendTextNode(SwPosition& rPos)
 {
     SwTextNode* pText = m_pPaM->GetPointNode().GetTextNode();
 
@@ -2565,8 +2565,7 @@ void SwWW8ImplReader::FinalizeTextNode(SwPosition& rPos, 
bool bAddNew)
 
     m_bFirstPara = false;
 
-    if (bAddNew)
-        m_rDoc.getIDocumentContentOperations().AppendTextNode(rPos);
+    m_rDoc.getIDocumentContentOperations().AppendTextNode(rPos);
 
     // We can flush all anchored graphics at the end of a paragraph.
     m_xAnchorStck->Flush();
@@ -3482,13 +3481,13 @@ void 
SwWW8ImplReader::simpleAddTextToParagraph(std::u16string_view aAddString)
         else
         {
             m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, 
addString.copy(0, nCharsLeft));
-            FinalizeTextNode(*m_pPaM->GetPoint());
+            AppendTextNode(*m_pPaM->GetPoint());
             m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, 
addString.copy(nCharsLeft));
         }
     }
     else
     {
-        FinalizeTextNode(*m_pPaM->GetPoint());
+        AppendTextNode(*m_pPaM->GetPoint());
         m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, 
addString);
     }
 
@@ -3559,7 +3558,7 @@ bool SwWW8ImplReader::HandlePageBreakChar()
                 && (m_bFirstPara || m_bFirstParaOfPage))
         {
             IsTemp = false;
-            FinalizeTextNode(*m_pPaM->GetPoint());
+            AppendTextNode(*m_pPaM->GetPoint());
             pTemp->SetAttr(*GetDfltAttr(RES_PARATR_NUMRULE));
         }
 
@@ -3638,7 +3637,7 @@ bool SwWW8ImplReader::ReadChar(tools::Long nPosCp, 
tools::Long nCpOfs)
                 // Always insert a txtnode for a column break, e.g. ##
                 SwContentNode *pCntNd=m_pPaM->GetPointContentNode();
                 if (pCntNd!=nullptr && pCntNd->Len()>0) // if par is empty not 
break is needed
-                    FinalizeTextNode(*m_pPaM->GetPoint());
+                    AppendTextNode(*m_pPaM->GetPoint());
                 m_rDoc.getIDocumentContentOperations().InsertPoolItem(*m_pPaM, 
SvxFormatBreakItem(SvxBreak::ColumnBefore, RES_BREAK));
             }
             break;
@@ -4107,7 +4106,7 @@ bool SwWW8ImplReader::ReadText(WW8_CP nStartCp, WW8_CP 
nTextLen, ManTypes nType)
             }
             if (bSplit)
             {
-                FinalizeTextNode(*m_pPaM->GetPoint());
+                AppendTextNode(*m_pPaM->GetPoint());
             }
         }
 
@@ -4222,7 +4221,7 @@ bool SwWW8ImplReader::ReadText(WW8_CP nStartCp, WW8_CP 
nTextLen, ManTypes nType)
                 // to insert a text node.
                 if (!bStartLine && !m_xAnchorStck->empty())
                 {
-                    FinalizeTextNode(*m_pPaM->GetPoint());
+                    AppendTextNode(*m_pPaM->GetPoint());
                 }
                 m_rDoc.getIDocumentContentOperations().InsertPoolItem(*m_pPaM,
                     SvxFormatBreakItem(SvxBreak::PageBefore, RES_BREAK));
@@ -4235,7 +4234,7 @@ bool SwWW8ImplReader::ReadText(WW8_CP nStartCp, WW8_CP 
nTextLen, ManTypes nType)
     m_xPreviousNode.reset();
 
     if (m_pPaM->GetPoint()->GetContentIndex())
-        FinalizeTextNode(*m_pPaM->GetPoint());
+        AppendTextNode(*m_pPaM->GetPoint());
 
     if (!m_bInHyperlink)
         bJoined = JoinNode(*m_pPaM);
diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index ca5b34f8e033..f98bcc2ff58e 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -1421,7 +1421,7 @@ private:
 
     bool StyleExists(unsigned int nColl) const { return (nColl < 
m_vColl.size()); }
     SwWW8StyInf *GetStyle(sal_uInt16 nColl) const;
-    void FinalizeTextNode(SwPosition& rPos, bool bAddNew = true);
+    void AppendTextNode(SwPosition& rPos);
 
     void Read_HdFt(int nSect, const SwPageDesc *pPrev,
         const wwSection &rSection);
diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx
index 07348ff888d3..602256428563 100644
--- a/sw/source/filter/ww8/ww8par2.cxx
+++ b/sw/source/filter/ww8/ww8par2.cxx
@@ -2402,7 +2402,7 @@ void WW8TabDesc::CreateSwTable()
     }
 
     if (bInsNode)
-        m_pIo->FinalizeTextNode(*pPoint);
+        m_pIo->AppendTextNode(*pPoint);
 
     m_xTmpPos = m_pIo->m_rDoc.CreateUnoCursor(*m_pIo->m_pPaM->GetPoint());
 
@@ -3497,8 +3497,6 @@ bool SwWW8ImplReader::StartTable(WW8_CP nStartCp)
 
 void SwWW8ImplReader::TabCellEnd()
 {
-    FinalizeTextNode(*m_pPaM->GetPoint(), false);
-
     if (m_nInTable && m_xTableDesc)
         m_xTableDesc->TableCellEnd();
 
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 975280376800..6750fa21ae76 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -3478,7 +3478,7 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8FieldDesc* pF, 
OUString& rStr )
     }
 
     if (m_pPaM->GetPoint()->GetContentIndex())
-        FinalizeTextNode(*m_pPaM->GetPoint());
+        AppendTextNode(*m_pPaM->GetPoint());
 
     const SwPosition* pPos = m_pPaM->GetPoint();
 
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index b8272f55ccd0..13270b28c144 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -881,7 +881,7 @@ void wwSectionManager::CreateSep(const tools::Long nTextPos)
                 if( txtNode->Len() == 0 )
                     insert = false;
         if( insert )
-            mrReader.FinalizeTextNode(*mrReader.m_pPaM->GetPoint());
+            mrReader.AppendTextNode(*mrReader.m_pPaM->GetPoint());
     }
 
     ww::WordVersion eVer = mrReader.GetFib().GetFIBVersion();
@@ -2528,7 +2528,7 @@ bool SwWW8ImplReader::StartApo(const ApoTestResults 
&rApo, const WW8_TablePos *p
                     {
                         // The two fly frames would have the same anchor 
position, leading to
                         // potentially overlapping text, prevent that.
-                        FinalizeTextNode(*pPoint);
+                        AppendTextNode(*pPoint);
                     }
                 }
             }
diff --git a/sw/source/filter/xml/xmlfmte.cxx b/sw/source/filter/xml/xmlfmte.cxx
index 0999076212c1..8e20f46e4299 100644
--- a/sw/source/filter/xml/xmlfmte.cxx
+++ b/sw/source/filter/xml/xmlfmte.cxx
@@ -250,7 +250,7 @@ void SwXMLExport::collectAutoStyles()
                 GetFormExport()->examineForms(xPage);
         }
 
-        
GetTextParagraphExport()->collectTextAutoStylesAndNodeExportOrder(m_bShowProgress);
+        GetTextParagraphExport()->collectTextAutoStylesOptimized( 
m_bShowProgress );
     }
 
     mbAutoStylesCollected = true;
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index b7101765368d..f55ee1055825 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -39,7 +39,6 @@
 #include <com/sun/star/text/XTextTablesSupplier.hpp>
 #include <com/sun/star/text/XNumberingRulesSupplier.hpp>
 #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
-#include <com/sun/star/text/XTextDocument.hpp>
 #include <com/sun/star/text/XTextTable.hpp>
 #include <com/sun/star/text/XText.hpp>
 #include <com/sun/star/text/XTextContent.hpp>
@@ -1335,14 +1334,12 @@ struct XMLTextParagraphExport::DocumentListNodes
 {
     struct NodeData
     {
-        std::ptrdiff_t order;
         sal_Int32 index; // see SwNode::GetIndex and SwNodeOffset
         sal_uInt64 style_id; // actually a pointer to NumRule
         OUString list_id;
     };
     std::vector<NodeData> docListNodes;
-    DocumentListNodes(const css::uno::Reference<css::frame::XModel>& xModel,
-                      const std::vector<sal_Int32>& aDocumentNodeOrder)
+    DocumentListNodes(const css::uno::Reference<css::frame::XModel>& xModel)
     {
         // Sequence of nodes, each of them represented by three-element 
sequence,
         // corresponding to NodeData members
@@ -1364,18 +1361,12 @@ struct XMLTextParagraphExport::DocumentListNodes
         for (const auto& node : nodes)
         {
             assert(node.getLength() == 3);
-            sal_Int32 nodeIndex = node[0].get<sal_Int32>();
-            auto nodeOrder = std::distance(
-                aDocumentNodeOrder.begin(),
-                std::find(aDocumentNodeOrder.begin(), 
aDocumentNodeOrder.end(), nodeIndex));
-            docListNodes.push_back({ .order = nodeOrder,
-                                     .index = nodeIndex,
-                                     .style_id = node[1].get<sal_uInt64>(),
-                                     .list_id = node[2].get<OUString>() });
+            docListNodes.push_back({ node[0].get<sal_Int32>(), 
node[1].get<sal_uInt64>(),
+                                     node[2].get<OUString>() });
         }
 
         std::sort(docListNodes.begin(), docListNodes.end(),
-                  [](const NodeData& lhs, const NodeData& rhs) { return 
lhs.order < rhs.order; });
+                  [](const NodeData& lhs, const NodeData& rhs) { return 
lhs.index < rhs.index; });
     }
     bool ShouldSkipListId(const Reference<XTextContent>& xTextContent) const
     {
@@ -1396,9 +1387,10 @@ struct XMLTextParagraphExport::DocumentListNodes
                 return false;
             }
 
-            auto it = std::find_if(docListNodes.begin(), docListNodes.end(),
-                                   [index](const NodeData& el) { return 
el.index == index; });
-            if (it == docListNodes.end())
+            auto it = std::lower_bound(docListNodes.begin(), 
docListNodes.end(), index,
+                                       [](const NodeData& lhs, sal_Int32 rhs)
+                                       { return lhs.index < rhs; });
+            if (it == docListNodes.end() || it->index != index)
                 return false;
 
             // We need to write the id, when there will be continuation of the 
list either with
@@ -1626,7 +1618,9 @@ const enum XMLTokenEnum lcl_XmlReferenceElements[] = {
 const enum XMLTokenEnum lcl_XmlBookmarkElements[] = {
     XML_BOOKMARK, XML_BOOKMARK_START, XML_BOOKMARK_END };
 
-void XMLTextParagraphExport::collectTextAutoStylesAndNodeExportOrder(bool 
bIsProgress)
+// This function replaces the text portion iteration during auto style
+// collection.
+void XMLTextParagraphExport::collectTextAutoStylesOptimized( bool bIsProgress )
 {
     GetExport().GetShapeExport(); // make sure the graphics styles family is 
added
 
@@ -1634,13 +1628,62 @@ void 
XMLTextParagraphExport::collectTextAutoStylesAndNodeExportOrder(bool bIsPro
         return;
 
     const bool bAutoStyles = true;
-    const bool bExportContent = true;
+    const bool bExportContent = false;
+
+    // Export AutoStyles:
+    Reference< XAutoStylesSupplier > xAutoStylesSupp( GetExport().GetModel(), 
UNO_QUERY );
+    if ( xAutoStylesSupp.is() )
+    {
+        Reference< XAutoStyles > xAutoStyleFamilies = 
xAutoStylesSupp->getAutoStyles();
+        const auto collectFamily = [this, &xAutoStyleFamilies](const OUString& 
sName,
+                                                               XmlStyleFamily 
nFamily) {
+            Any aAny = xAutoStyleFamilies->getByName( sName );
+            Reference< XAutoStyleFamily > xAutoStyles = 
*o3tl::doAccess<Reference<XAutoStyleFamily>>(aAny);
+            Reference < XEnumeration > xAutoStylesEnum( 
xAutoStyles->createEnumeration() );
+
+            while ( xAutoStylesEnum->hasMoreElements() )
+            {
+                aAny = xAutoStylesEnum->nextElement();
+                Reference< XAutoStyle > xAutoStyle = 
*o3tl::doAccess<Reference<XAutoStyle>>(aAny);
+                Reference < XPropertySet > xPSet( xAutoStyle, uno::UNO_QUERY );
+                Add( nFamily, xPSet, {}, true );
+            }
+        };
+        collectFamily("CharacterStyles", XmlStyleFamily::TEXT_TEXT);
+        collectFamily("RubyStyles", XmlStyleFamily::TEXT_RUBY);
+        collectFamily("ParagraphStyles", XmlStyleFamily::TEXT_PARAGRAPH);
+    }
 
-    if (auto xTextDocument = GetExport().GetModel().query<XTextDocument>())
+    // Export Field AutoStyles:
+    Reference< XTextFieldsSupplier > xTextFieldsSupp( GetExport().GetModel(), 
UNO_QUERY );
+    if ( xTextFieldsSupp.is() )
     {
-        bInDocumentNodeOrderCollection = true;
-        collectTextAutoStyles(xTextDocument->getText(), bIsProgress);
-        bInDocumentNodeOrderCollection = false;
+        Reference< XEnumerationAccess > xTextFields = 
xTextFieldsSupp->getTextFields();
+        Reference < XEnumeration > xTextFieldsEnum( 
xTextFields->createEnumeration() );
+
+        while ( xTextFieldsEnum->hasMoreElements() )
+        {
+            Any aAny = xTextFieldsEnum->nextElement();
+            Reference< XTextField > xTextField = 
*o3tl::doAccess<Reference<XTextField>>(aAny);
+            exportTextField( xTextField, bAutoStyles, bIsProgress,
+                !xAutoStylesSupp.is(), nullptr );
+            try
+            {
+                Reference < XPropertySet > xSet( xTextField, UNO_QUERY );
+                Reference < XText > xText;
+                Any a = xSet->getPropertyValue("TextRange");
+                a >>= xText;
+                if ( xText.is() )
+                {
+                    exportText( xText, true, bIsProgress, bExportContent );
+                    GetExport().GetTextParagraphExport()
+                        ->collectTextAutoStyles( xText );
+                }
+            }
+            catch (Exception&)
+            {
+            }
+        }
     }
 
     // Export text frames:
@@ -1687,6 +1730,85 @@ void 
XMLTextParagraphExport::collectTextAutoStylesAndNodeExportOrder(bool bIsPro
             }
         }
 
+    sal_Int32 nCount;
+    // AutoStyles for sections
+    Reference< XTextSectionsSupplier > xSectionsSupp( GetExport().GetModel(), 
UNO_QUERY );
+    if ( xSectionsSupp.is() )
+    {
+        Reference< XIndexAccess > xSections( xSectionsSupp->getTextSections(), 
UNO_QUERY );
+        if ( xSections.is() )
+        {
+            nCount = xSections->getCount();
+            for( sal_Int32 i = 0; i < nCount; ++i )
+            {
+                Any aAny = xSections->getByIndex( i );
+                Reference< XTextSection > xSection = 
*o3tl::doAccess<Reference<XTextSection>>(aAny);
+                Reference < XPropertySet > xPSet( xSection, uno::UNO_QUERY );
+                Add( XmlStyleFamily::TEXT_SECTION, xPSet );
+            }
+        }
+    }
+
+    // AutoStyles for tables (Note: suppress autostyle collection for 
paragraphs in exportTable)
+    Reference< XTextTablesSupplier > xTablesSupp( GetExport().GetModel(), 
UNO_QUERY );
+    if ( xTablesSupp.is() )
+    {
+        Reference< XIndexAccess > xTables( xTablesSupp->getTextTables(), 
UNO_QUERY );
+        if ( xTables.is() )
+        {
+            nCount = xTables->getCount();
+            for( sal_Int32 i = 0; i < nCount; ++i )
+            {
+                Any aAny = xTables->getByIndex( i );
+                Reference< XTextTable > xTable = 
*o3tl::doAccess<Reference<XTextTable>>(aAny);
+                exportTable( xTable, true, true );
+            }
+        }
+    }
+
+    Reference< XNumberingRulesSupplier > xNumberingRulesSupp( 
GetExport().GetModel(), UNO_QUERY );
+    if ( xNumberingRulesSupp.is() )
+    {
+        Reference< XIndexAccess > xNumberingRules = 
xNumberingRulesSupp->getNumberingRules();
+        nCount = xNumberingRules->getCount();
+        // Custom outline assignment lost after re-importing sxw (#i73361#)
+        for( sal_Int32 i = 0; i < nCount; ++i )
+        {
+            Reference< XIndexReplace > xNumRule( xNumberingRules->getByIndex( 
i ), UNO_QUERY );
+            if( xNumRule.is() && xNumRule->getCount() )
+            {
+                Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
+                OUString sName;
+                if( xNamed.is() )
+                    sName = xNamed->getName();
+                bool bAdd = sName.isEmpty();
+                if( !bAdd )
+                {
+                    Reference < XPropertySet > xNumPropSet( xNumRule,
+                                                            UNO_QUERY );
+                    if( xNumPropSet.is() &&
+                        xNumPropSet->getPropertySetInfo()
+                                   ->hasPropertyByName( "IsAutomatic" ) )
+                    {
+                        bAdd = 
*o3tl::doAccess<bool>(xNumPropSet->getPropertyValue( "IsAutomatic" ));
+                        // Check on outline style (#i73361#)
+                        if ( bAdd &&
+                             xNumPropSet->getPropertySetInfo()
+                                       ->hasPropertyByName( 
"NumberingIsOutline" ) )
+                        {
+                            bAdd = 
!(*o3tl::doAccess<bool>(xNumPropSet->getPropertyValue( "NumberingIsOutline" )));
+                        }
+                    }
+                    else
+                    {
+                        bAdd = true;
+                    }
+                }
+                if( bAdd )
+                    maListAutoPool.Add( xNumRule );
+            }
+        }
+    }
     mbCollected = true;
 }
 
@@ -1774,36 +1896,14 @@ bool XMLTextParagraphExport::ExportListId() const
            && GetExport().getSaneDefaultVersion() >= 
SvtSaveOptions::ODFSVER_012;
 }
 
-void XMLTextParagraphExport::RecordNodeIndex(const 
css::uno::Reference<css::text::XTextContent>& xTextContent)
-{
-    if (!bInDocumentNodeOrderCollection)
-        return;
-    if (auto xPropSet = xTextContent.query<css::beans::XPropertySet>())
-    {
-        try
-        {
-            sal_Int32 index = 0;
-            // See SwXParagraph::Impl::GetPropertyValues_Impl
-            xPropSet->getPropertyValue("ODFExport_NodeIndex") >>= index;
-            assert(std::find(maDocumentNodeOrder.begin(), 
maDocumentNodeOrder.end(), index)
-                   == maDocumentNodeOrder.end());
-            maDocumentNodeOrder.push_back(index);
-        }
-        catch (css::beans::UnknownPropertyException&)
-        {
-            // That's absolutely fine!
-        }
-    }
-}
-
 bool XMLTextParagraphExport::ShouldSkipListId(const Reference<XTextContent>& 
xTextContent)
 {
     if (!mpDocumentListNodes)
     {
         if (ExportListId())
-            mpDocumentListNodes.reset(new 
DocumentListNodes(GetExport().GetModel(), maDocumentNodeOrder));
+            mpDocumentListNodes.reset(new 
DocumentListNodes(GetExport().GetModel()));
         else
-            mpDocumentListNodes.reset(new DocumentListNodes({}, {}));
+            mpDocumentListNodes.reset(new DocumentListNodes({}));
     }
 
     return mpDocumentListNodes->ShouldSkipListId(xTextContent);
@@ -1854,7 +1954,6 @@ void XMLTextParagraphExport::exportTextContentEnumeration(
         {
             if( bAutoStyles )
             {
-                RecordNodeIndex(xTxtCntnt);
                 exportListAndSectionChange( xCurrentTextSection, xTxtCntnt,
                                             aPrevNumInfo, aNextNumInfo,
                                             bAutoStyles );
@@ -2226,6 +2325,7 @@ void XMLTextParagraphExport::exportParagraph(
 
     Reference < XEnumerationAccess > xEA( rTextContent, UNO_QUERY );
     Reference < XEnumeration > xTextEnum = xEA->createEnumeration();
+    const bool bHasPortions = xTextEnum.is();
 
     Reference < XEnumeration> xContentEnum;
     Reference < XContentEnumerationAccess > xCEA( rTextContent, UNO_QUERY );
@@ -2259,10 +2359,22 @@ void XMLTextParagraphExport::exportParagraph(
 
     bool bPrevCharIsSpace(true); // true because whitespace at start is ignored
 
+    if( bAutoStyles )
+    {
+        if( bHasContentEnum )
+            exportTextContentEnumeration(
+                                    xContentEnum, bAutoStyles, xSection,
+                                    bIsProgress );
+        if ( bHasPortions )
+        {
+            exportTextRangeEnumeration(xTextEnum, bAutoStyles, bIsProgress, 
bPrevCharIsSpace);
+        }
+    }
+    else
     {
         enum XMLTokenEnum eElem =
             0 < nOutlineLevel ? XML_H : XML_P;
-        SvXMLElementExport aElem( GetExport(), !bAutoStyles, eExtensionNS == 
TextPNS::EXTENSION ? XML_NAMESPACE_LO_EXT : XML_NAMESPACE_TEXT, eElem,
+        SvXMLElementExport aElem( GetExport(), eExtensionNS == 
TextPNS::EXTENSION ? XML_NAMESPACE_LO_EXT : XML_NAMESPACE_TEXT, eElem,
                                   true, false );
         if( bHasContentEnum )
         {
diff --git a/xmloff/source/text/txtparai.cxx b/xmloff/source/text/txtparai.cxx
index 9656ba081902..c777fa0c2929 100644
--- a/xmloff/source/text/txtparai.cxx
+++ b/xmloff/source/text/txtparai.cxx
@@ -1851,8 +1851,11 @@ void XMLParaContext::endFastElement(sal_Int32 )
 
     if (m_xHints)
     {
-        bool bEmptyHints = false;
-        if (auto xCompare = 
xTxtImport->GetText().query<text::XTextRangeCompare>())
+        bool bSetNoFormatAttr = false;
+        uno::Reference<beans::XPropertySet> xCursorProps(xAttrCursor, 
uno::UNO_QUERY);
+        int nEmptyHints = 0;
+        uno::Reference<text::XTextRangeCompare> 
xCompare(xTxtImport->GetText(), uno::UNO_QUERY);
+        if (xCompare.is())
         {
             try
             {
@@ -1860,7 +1863,7 @@ void XMLParaContext::endFastElement(sal_Int32 )
                 {
                     if (xCompare->compareRegionStarts(pHint->GetStart(), 
pHint->GetEnd()) == 0)
                     {
-                        bEmptyHints = true;
+                        ++nEmptyHints;
                     }
                 }
             }
@@ -1869,9 +1872,7 @@ void XMLParaContext::endFastElement(sal_Int32 )
                 TOOLS_WARN_EXCEPTION("xmloff.text", "");
             }
         }
-        bool bSetNoFormatAttr = false;
-        uno::Reference<beans::XPropertySet> xCursorProps(xAttrCursor, 
uno::UNO_QUERY);
-        if (bEmptyHints || m_aMarkerStyleName.hasValue())
+        if (nEmptyHints > 0 || m_aMarkerStyleName.hasValue())
         {
             // We have at least one empty hint, then make try to ask the 
cursor to not upgrade our character
             // attributes to paragraph-level formatting, which would lead to 
incorrect rendering.

Reply via email to