[Libreoffice-commits] core.git: Branch 'libreoffice-4-3' - 3 commits - sw/qa sw/source writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Aug 19 08:57:56 PDT 2014


 sw/qa/extras/ooxmlexport/data/first-header-footer.docx  |binary
 sw/qa/extras/ooxmlexport/data/footer-body-distance.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx                |   38 ++++++++++-
 sw/qa/extras/ww8import/data/fdo81102.doc                |binary
 sw/qa/extras/ww8import/ww8import.cxx                    |   16 ++++
 sw/source/filter/ww8/ww8par.cxx                         |    5 -
 writerfilter/source/dmapper/DomainMapper_Impl.cxx       |    4 -
 writerfilter/source/dmapper/PropertyMap.cxx             |   53 +++-------------
 8 files changed, 69 insertions(+), 47 deletions(-)

New commits:
commit 4a1c82de77f28a107198b8d8da3cf840d541360a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Jul 14 12:34:23 2014 +0200

    DOCX import: fix FooterBodyDistance for first pages
    
    The root cause was that code in
    SectionPropertyMap::PrepareHeaderFooterProperties() saved member
    variables on the stack, modified them, then restored them at the end of
    the method, but forgot to restore m_nBottomMargin there.
    
    The result of this was that First Page's FooterBodyDistance got set to
    zero, which is not the same as Default Style's FooterBodyDistance (150),
    so on export sw::util::IsPlausableSingleWordSection() returned false,
    which turned the page break into a section break.
    
    Change-Id: I1afa2603de1313ae1e2aaefd4b7c771fce27e21e
    (cherry picked from commit 8cf681c5049970573020d8b808c990441b9cf828)
    Signed-off-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/footer-body-distance.docx b/sw/qa/extras/ooxmlexport/data/footer-body-distance.docx
new file mode 100644
index 0000000..0244d76
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/footer-body-distance.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 30a6d2f..fdcab8a 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -3651,6 +3651,13 @@ DECLARE_OOXMLEXPORT_TEST(testFirstHeaderFooter, "first-header-footer.docx")
     CPPUNIT_ASSERT_EQUAL(OUString("Even page footer 2"),  parseDump("/root/page[6]/footer/txt/text()"));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testFooterBodyDistance, "footer-body-distance.docx")
+{
+    if (xmlDocPtr pXmlDoc = parseExport())
+        // Page break was exported as section break, this was 0
+        assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:br", 1);
+}
+
 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 647c915..0b47cad 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -868,6 +868,7 @@ void SectionPropertyMap::PrepareHeaderFooterProperties( bool bFirstPage )
     // Restore original top margin, so we don't end up with a smaller margin in case we have to produce two page styles from one Word section.
     m_nTopMargin = nTopMargin;
     m_nHeaderTop = nHeaderTop;
+    m_nBottomMargin = nBottomMargin;
     m_nHeaderBottom = nHeaderBottom;
 }
 
commit 2e7a33658983b6863d3847daca0265e43fbe18ba
Author: Luke Deller <luke at deller.id.au>
Date:   Wed Jul 9 22:39:41 2014 +1000

    fdo#81102: fix .doc import of blank even page header
    
    Honour the "different odd & even pages" header/footer setting from the
    doc file even if there is no content for an even page header or footer.
    
    Conflicts:
    	sw/qa/extras/ww8import/ww8import.cxx
    Reviewed on:
    	https://gerrit.libreoffice.org/10191
    
    (cherry picked from commit b5bb15013617c6b9f1cdd089acae0bfb7104fa3a)
    Signed-off-by: Luboš Luňák <l.lunak at collabora.com>
    
    Conflicts:
    	sw/qa/extras/ww8import/ww8import.cxx
    
    Change-Id: I963f7f7189e399b1d859db0788fbfd291e868c54

diff --git a/sw/qa/extras/ww8import/data/fdo81102.doc b/sw/qa/extras/ww8import/data/fdo81102.doc
new file mode 100755
index 0000000..e8a5507
Binary files /dev/null and b/sw/qa/extras/ww8import/data/fdo81102.doc differ
diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx
index 81b0043..2fca67c 100644
--- a/sw/qa/extras/ww8import/ww8import.cxx
+++ b/sw/qa/extras/ww8import/ww8import.cxx
@@ -496,6 +496,22 @@ DECLARE_WW8IMPORT_TEST(testBnc787942, "bnc787942.doc")
     parseDump("/root/page[1]/body/txt[4]/anchored");
 }
 
+DECLARE_WW8IMPORT_TEST(testFdo81102, "fdo81102.doc")
+{
+    // get page style at beginning of document
+    uno::Reference<text::XTextDocument> textDocument(
+        mxComponent, uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> start(
+        textDocument->getText()->getStart(), uno::UNO_QUERY);
+    OUString pageStyleName = getProperty<OUString>(start, "PageStyleName");
+    uno::Reference<style::XStyle> pageStyle(
+        getStyles("PageStyles")->getByName(pageStyleName), uno::UNO_QUERY);
+
+    // check that left and right pages do not share the same header
+    bool headerIsShared = getProperty<bool>(pageStyle, "HeaderIsShared");
+    CPPUNIT_ASSERT(!headerIsShared);
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index ccdc07c..d9335411 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -4320,15 +4320,12 @@ void wwSectionManager::SetSegmentToPageDesc(const wwSection &rSection,
 
 void wwSectionManager::SetUseOn(wwSection &rSection)
 {
-    bool bEven = (rSection.maSep.grpfIhdt & (WW8_HEADER_EVEN|WW8_FOOTER_EVEN)) ?
-        true : false;
-
     bool bMirror = mrReader.pWDop->fMirrorMargins ||
         mrReader.pWDop->doptypography.f2on1;
 
     UseOnPage eUseBase = bMirror ? nsUseOnPage::PD_MIRROR : nsUseOnPage::PD_ALL;
     UseOnPage eUse = eUseBase;
-    if (!bEven)
+    if (!mrReader.pWDop->fFacingPages)
         eUse = (UseOnPage)(eUse | nsUseOnPage::PD_HEADERSHARE | nsUseOnPage::PD_FOOTERSHARE);
     if (!rSection.HasTitlePage())
         eUse = (UseOnPage)(eUse | nsUseOnPage::PD_FIRSTSHARE);
commit bcbeac44ca54f41fb80a027214b9eb2ec1eb14dd
Author: Luke Deller <luke at deller.id.au>
Date:   Sat Jul 12 21:49:50 2014 +1000

    Copy first-header-footer test from ww8 to ooxml
    
    The test document was converted from doc to docx using MS Word 2010.
    
    Several fixes were required to make this test pass:
    
    - Do not clear the "FirstIsShared" property on page styles, as the code
      instead uses the old fashioned method of translating a Word section
      with "different first page header/footer": two page styles linked
      together, the first page style and the follow page style.
      (Also remove a wrong test case which checks the FirstIsShared property)
    
    - Do not clear the "HeaderIsShared"/"FooterIsShared" properties on the
      first page style, only on the follow page style.
    
    - Actually set the "FollowStyle" property on the first page style to
      link it to the follow page style.  This didn't matter for the very
      first Word section because it was mapped to the default page styles
      "First Page" and "Standard" which are already linked, but it does
      matter for subsequent Word sections.
    
    - For some reason setting a new page style at a section break was
      excluded in the case where the following section had a title page.
      Remove this exclusion.
    
    - The exclusion mentioned in the last point was masking that bnc#751077
      was not entirely fixed.  To resolve that issue:
      When checking if the last paragraph of the section is empty, consider
      not just text content but also shapes.
    
    - Remove a workaround for bnc#780843 involving copying of headers and
      footers from the "Standard" (first section) page style in the case
      where the following section had a title page.  This workaround is no
      longer needed as the test case passes without it.
    
    Change-Id: Iacc9bba0720c11414da3e852892cff301ebbc4fe
    (cherry picked from commit b4ccde72b8e2e45e7276d5b08b182495a1b1a617)
    Signed-off-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/first-header-footer.docx b/sw/qa/extras/ooxmlexport/data/first-header-footer.docx
new file mode 100755
index 0000000..d18eea5
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/first-header-footer.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 18c4a7e..30a6d2f 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -906,8 +906,14 @@ DECLARE_OOXMLEXPORT_TEST(testPageBorderSpacingExportCase2, "page-borders-export-
 DECLARE_OOXMLEXPORT_TEST(testFdo66145, "fdo66145.docx")
 {
     // The Writer ignored the 'First Is Shared' flag
-    uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName("First Page"), uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(false, bool(getProperty<sal_Bool>(xPropertySet, "FirstIsShared")));
+    CPPUNIT_ASSERT_EQUAL(OUString("This is the FIRST page header."),
+        parseDump("/root/page[1]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(
+        OUString("This is the header for the REST OF THE FILE."),
+        parseDump("/root/page[2]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(
+        OUString("This is the header for the REST OF THE FILE."),
+        parseDump("/root/page[3]/header/txt/text()"));
 }
 
 DECLARE_OOXMLEXPORT_TEST(testGrabBag, "grabbag.docx")
@@ -3624,6 +3630,27 @@ DECLARE_OOXMLEXPORT_TEST(testfdo80898, "fdo80898.docx")
 
 #endif
 
+DECLARE_OOXMLEXPORT_TEST(testFirstHeaderFooter, "first-header-footer.docx")
+{
+    // Test import and export of a section's headerf/footerf properties.
+    // (copied from a ww8export test, with doc converted to docx using Word)
+
+    // The document has 6 pages. Note that we don't test if 4 or just 2 page
+    // styles are created, the point is that layout should be correct.
+    CPPUNIT_ASSERT_EQUAL(OUString("First page header"),  parseDump("/root/page[1]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("First page footer"),  parseDump("/root/page[1]/footer/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Even page header"),   parseDump("/root/page[2]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Even page footer"),   parseDump("/root/page[2]/footer/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Odd page header"),  parseDump("/root/page[3]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Odd page footer"),  parseDump("/root/page[3]/footer/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("First page header2"), parseDump("/root/page[4]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("First page footer 2"), parseDump("/root/page[4]/footer/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Odd page header 2"), parseDump("/root/page[5]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Odd page footer 2"), parseDump("/root/page[5]/footer/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Even page header 2"),  parseDump("/root/page[6]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Even page footer 2"),  parseDump("/root/page[6]/footer/txt/text()"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 0e18852..34ccea8 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1501,6 +1501,7 @@ void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::P
         try
         {
             bool bLeft = eType == SectionPropertyMap::PAGE_LEFT;
+            bool bFirst = eType == SectionPropertyMap::PAGE_FIRST;
             if ((!bLeft && !GetSettingsTable()->GetEvenAndOddHeaders()) || (GetSettingsTable()->GetEvenAndOddHeaders()))
             {
                 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
@@ -1512,7 +1513,7 @@ void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::P
 
                 // If the 'Different Even & Odd Pages' flag is turned on - do not ignore it
                 // Even if the 'Even' header/footer is blank - the flag should be imported (so it would look in LO like in Word)
-                if (GetSettingsTable()->GetEvenAndOddHeaders())
+                if (!bFirst && GetSettingsTable()->GetEvenAndOddHeaders())
                     xPageStyle->setPropertyValue(rPropNameSupplier.GetName(ePropShared), uno::makeAny(false));
 
                 //set the interface
@@ -1937,6 +1938,7 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape
                         rPropNameSupplier.GetName( PROP_OPAQUE ),
                         uno::makeAny( true ) );
         }
+        m_bParaChanged = true;
     }
     catch ( const uno::Exception& e )
     {
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index dab3285..647c915 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -426,6 +426,12 @@ uno::Reference< beans::XPropertySet > SectionPropertyMap::GetPageStyle(
                 m_aFirstPageStyle = uno::Reference< beans::XPropertySet > (
                         xTextFactory->createInstance("com.sun.star.style.PageStyle"),
                         uno::UNO_QUERY);
+                // Ensure that m_aFollowPageStyle has been created
+                GetPageStyle( xPageStyles, xTextFactory, false );
+                // Chain m_aFollowPageStyle to be after m_aFirstPageStyle
+                m_aFirstPageStyle->setPropertyValue("FollowStyle",
+                    uno::makeAny(m_sFollowPageStyleName));
+
                 if (xPageStyles.is())
                     xPageStyles->insertByName( m_sFirstPageStyleName, uno::makeAny(m_aFirstPageStyle) );
             }
@@ -1122,11 +1128,6 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
             if( xColumns.is() )
                 xFirstPageStyle->setPropertyValue(
                     rPropNameSupplier.GetName( PROP_TEXT_COLUMNS ), uno::makeAny( xColumns ));
-
-            // If the 'Different First Page' flag is turned on - do not ignore it
-            // If the 'Diffferent First Page' is non-checked, it must be checked - the flag should be imported (so it would look in LO like in Word)
-            xFirstPageStyle->setPropertyValue(rPropNameSupplier.GetName( PROP_FIRST_IS_SHARED ), uno::makeAny( false ));
-            xFollowPageStyle->setPropertyValue(rPropNameSupplier.GetName( PROP_FIRST_IS_SHARED ), uno::makeAny( false ));
         }
 
         ApplyBorderToPageStyles( rDM_Impl.GetPageStyles( ), rDM_Impl.GetTextFactory( ), m_nBorderParams );
@@ -1138,41 +1139,12 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
                 uno::Reference<beans::XPropertySet> xRangeProperties(lcl_GetRangeProperties(m_bIsFirstSection, rDM_Impl, m_xStartingRange));
             /* break type
             0 - No break 1 - New Column 2 - New page 3 - Even page 4 - odd page */
-                if ((m_bTitlePage && m_bIsFirstSection) || !m_bTitlePage)
-                {
-                    if (xRangeProperties.is() && rDM_Impl.IsNewDoc())
-                        xRangeProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_PAGE_DESC_NAME ),
-                                uno::makeAny( m_bTitlePage ? m_sFirstPageStyleName : m_sFollowPageStyleName ));
-                }
-                else
-                {
-                    // In this miserable situation (second or later section on a title page), make sure that the header / footer is not lost.
-                    uno::Reference< container::XNameAccess > xPageStyles(rDM_Impl.GetPageStyles(), uno::UNO_QUERY);
-                    if (xPageStyles->hasByName(m_sFollowPageStyleName))
-                    {
-                        uno::Reference<beans::XPropertySet> xCurrent(xPageStyles->getByName(rPropNameSupplier.GetName(PROP_STANDARD)), uno::UNO_QUERY);
-                        uno::Reference<beans::XPropertySet> xFollow(xPageStyles->getByName(m_sFollowPageStyleName), uno::UNO_QUERY);
-
-                        if (xFollow->getPropertyValue(rPropNameSupplier.GetName(PROP_HEADER_IS_ON)).get<sal_Bool>())
-                        {
-                            xCurrent->setPropertyValue(rPropNameSupplier.GetName(PROP_HEADER_IS_ON), uno::makeAny(sal_True));
-                            uno::Reference<text::XTextRange> xCurrentRange(xCurrent->getPropertyValue(rPropNameSupplier.GetName(PROP_HEADER_TEXT)), uno::UNO_QUERY_THROW);
-                            xCurrentRange->setString("");
-                            uno::Reference<text::XTextCopy> xCurrentTxt(xCurrentRange, uno::UNO_QUERY_THROW);
-                            uno::Reference<text::XTextCopy> xFollowTxt(xFollow->getPropertyValue(rPropNameSupplier.GetName(PROP_HEADER_TEXT)), uno::UNO_QUERY_THROW);
-                            xCurrentTxt->copyText(xFollowTxt);
-                        }
-                        if (xFollow->getPropertyValue(rPropNameSupplier.GetName(PROP_FOOTER_IS_ON)).get<sal_Bool>())
-                        {
-                            xCurrent->setPropertyValue(rPropNameSupplier.GetName(PROP_FOOTER_IS_ON), uno::makeAny(sal_True));
-                            uno::Reference<text::XTextRange> xCurrentRange(xCurrent->getPropertyValue(rPropNameSupplier.GetName(PROP_FOOTER_TEXT)), uno::UNO_QUERY_THROW);
-                            xCurrentRange->setString("");
-                            uno::Reference<text::XTextCopy> xCurrentTxt(xCurrentRange, uno::UNO_QUERY_THROW);
-                            uno::Reference<text::XTextCopy> xFollowTxt(xFollow->getPropertyValue(rPropNameSupplier.GetName(PROP_FOOTER_TEXT)), uno::UNO_QUERY_THROW);
-                            xCurrentTxt->copyText(xFollowTxt);
-                        }
-                    }
-                }
+                if (xRangeProperties.is() && rDM_Impl.IsNewDoc())
+                    xRangeProperties->setPropertyValue(
+                        rPropNameSupplier.GetName( PROP_PAGE_DESC_NAME ),
+                        uno::makeAny( m_bTitlePage ?  m_sFirstPageStyleName
+                                      : m_sFollowPageStyleName ));
+
                 // handle page breaks with odd/even page numbering
                 style::PageStyleLayout nPageStyleLayout(style::PageStyleLayout_ALL);
                 if (m_nBreakType == 3)


More information about the Libreoffice-commits mailing list