[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sw/qa writerfilter/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Thu Jan 16 19:35:59 UTC 2020


 sw/qa/extras/ooxmlexport/data/cont-sect-break-header-footer.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx                       |   26 ++++++++++
 writerfilter/source/dmapper/PropertyMap.cxx                      |   25 +++++++++
 3 files changed, 50 insertions(+), 1 deletion(-)

New commits:
commit c521e69ab9b0330e9e8ad8c58d14f44d74aa2267
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jan 15 17:54:52 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Jan 16 20:35:16 2020 +0100

    DOCX import: improve support for headers/footers from cont sect break
    
    A continuous section break in a DOCX file can set new headers/footers
    which start appearing from the next page. In general, this is not
    something Writer supports, but commit
    08f13ab85b5c65b5dc8adfa15918fb3e426fcc3c (tdf#112202 writerfilter,sw:
    fix loss of headers, 2019-12-16) improved the situation significantly
    here.
    
    Build on top of that and add support for a few more cases:
    
    1) When checking for the last paragraph of the previous section, detect
    when that last paragraph is so small so in practice that's not the last
    one.
    
    2) Handle when the text node in question has no explicit break type set,
    only a SwFormatPageDesc (which implicitly causes a page break).
    
    3) When setting the page style to show the correct header/footer, don't
    set the page style on the previous paragraph directly, rather update the
    "next style" of the already set page style. (This is safe, as we never
    reuse the same Writer page style for multiple Word sections.)
    
    Conflicts:
            sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
    
    (cherry picked from commit 9a50e8f2bcde95233e4b38707c521ada90fcd6af)
    
    Change-Id: Iede196b864af5123c5637f82432ed6e0f7e7241a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86915
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/cont-sect-break-header-footer.docx b/sw/qa/extras/ooxmlexport/data/cont-sect-break-header-footer.docx
new file mode 100644
index 000000000000..61c18298d083
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/cont-sect-break-header-footer.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index b6216a699d9f..f2e3877271a0 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -362,6 +362,32 @@ DECLARE_OOXMLIMPORT_TEST(testTdf128207, "tdf128207.docx")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(12), getProperty<sal_Int32>(getShape(1), "HoriOrientPosition"));
 }
 
+DECLARE_OOXMLIMPORT_TEST(testContSectBreakHeaderFooter, "cont-sect-break-header-footer.docx")
+{
+    // Load a document with a continuous section break on page 2.
+    CPPUNIT_ASSERT_EQUAL(OUString("First page header, section 1"),
+                         parseDump("/root/page[1]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("First page footer, section 1"),
+                         parseDump("/root/page[1]/footer/txt/text()"));
+    // Make sure the header stays like this; if we naively just update the page style name of the
+    // first para on page 2, then this would be 'Header, section 2', which is incorrect.
+    CPPUNIT_ASSERT_EQUAL(OUString("First page header, section 2"),
+                         parseDump("/root/page[2]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("First page footer, section 2"),
+                         parseDump("/root/page[2]/footer/txt/text()"));
+    // This is inherited from page 2.
+    CPPUNIT_ASSERT_EQUAL(OUString("Header, section 2"),
+                         parseDump("/root/page[3]/header/txt/text()"));
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+    // - xpath should match exactly 1 node
+    // i.e. the footer had no text (inherited from page 2), while the correct behavior is to provide
+    // the own footer text.
+    CPPUNIT_ASSERT_EQUAL(OUString("Footer, section 3"),
+                         parseDump("/root/page[3]/footer/txt/text()"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index 120fb7872ed3..8fbfdb01aca8 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -1415,9 +1415,11 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
                         }
                     }
                 }
+                uno::Reference<text::XParagraphCursor> const xPCursor(xCursor,
+                                                                      uno::UNO_QUERY_THROW);
+                float fCharHeight = 0;
                 if (!isFound)
                 {   // HACK: try the last paragraph of the previous section
-                    uno::Reference<text::XParagraphCursor> const xPCursor(xCursor, uno::UNO_QUERY_THROW);
                     xPCursor->gotoPreviousParagraph(false);
                     uno::Reference<beans::XPropertySet> const xPSCursor(xCursor, uno::UNO_QUERY_THROW);
                     style::BreakType bt;
@@ -1426,6 +1428,27 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
                     {
                         xPSCursor->setPropertyValue(getPropertyName(PROP_PAGE_DESC_NAME),
                                 uno::makeAny(m_sFollowPageStyleName));
+                        isFound = true;
+                    }
+                    else
+                    {
+                        xPSCursor->getPropertyValue("CharHeight") >>= fCharHeight;
+                    }
+                }
+                if (!isFound && fCharHeight <= 1.0)
+                {
+                    // If still not found, see if the last paragraph is ~invisible, and work with
+                    // the last-in-practice paragraph.
+                    xPCursor->gotoPreviousParagraph(false);
+                    uno::Reference<beans::XPropertySet> xPropertySet(xCursor, uno::UNO_QUERY_THROW);
+                    OUString aPageDescName;
+                    if ((xPropertySet->getPropertyValue("PageDescName") >>= aPageDescName)
+                        && !aPageDescName.isEmpty())
+                    {
+                        uno::Reference<beans::XPropertySet> xPageStyle(
+                            rDM_Impl.GetPageStyles()->getByName(aPageDescName), uno::UNO_QUERY);
+                        xPageStyle->setPropertyValue("FollowStyle",
+                                                     uno::makeAny(m_sFollowPageStyleName));
                     }
                 }
             }


More information about the Libreoffice-commits mailing list