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

Miklos Vajna vmiklos at collabora.co.uk
Thu Oct 1 02:22:22 PDT 2015


 sw/qa/extras/ooxmlexport/data/tdf92521.odt   |binary
 sw/qa/extras/ooxmlexport/ooxmlexport4.cxx    |    7 ++++
 sw/source/filter/ww8/attributeoutputbase.hxx |    2 -
 sw/source/filter/ww8/docxattributeoutput.cxx |   31 +++++++++++++----
 sw/source/filter/ww8/docxattributeoutput.hxx |    2 -
 sw/source/filter/ww8/docxexport.cxx          |    3 +
 sw/source/filter/ww8/rtfattributeoutput.cxx  |   47 ++++++++++++++-------------
 sw/source/filter/ww8/rtfattributeoutput.hxx  |    2 -
 sw/source/filter/ww8/ww8attributeoutput.hxx  |    2 -
 9 files changed, 62 insertions(+), 34 deletions(-)

New commits:
commit f624559bbfa2cfb8cc2a081174be2ac6b0ed9dcb
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Sep 21 07:31:33 2015 +0200

    tdf#92521 DOCX export: handle section break right after a table
    
    DocxAttributeOutput::SectionBreaks() previously only handled the
    text-text and text-table node transitions; implement support for
    table-text to avoid loosing a page break on export for the bugdoc.
    
    (View this commit with whitespace ignored to filter out the noise about
    SectionBreaks() now accepting non-text nodes, too.)
    
    (cherry picked from commit c916152d8562cab868d4c522748ac30029fad179)
    
    Conflicts:
    	sw/source/filter/ww8/attributeoutputbase.hxx
    	sw/source/filter/ww8/docxattributeoutput.cxx
    	sw/source/filter/ww8/docxattributeoutput.hxx
    	sw/source/filter/ww8/rtfattributeoutput.cxx
    	sw/source/filter/ww8/rtfattributeoutput.hxx
    	sw/source/filter/ww8/ww8attributeoutput.hxx
    
    Change-Id: Ie8a1575374a207399351635bda8c0c076ce7268d
    Reviewed-on: https://gerrit.libreoffice.org/18901
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf92521.odt b/sw/qa/extras/ooxmlexport/data/tdf92521.odt
new file mode 100644
index 0000000..8148e49
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf92521.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index 5690507..ea3c6af 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -810,6 +810,13 @@ DECLARE_OOXMLEXPORT_TEST(testTdf83227, "tdf83227.docx")
     CPPUNIT_ASSERT_EQUAL(false, bool(xNameAccess->hasByName("word/media/image2.png")));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf92521, "tdf92521.odt")
+{
+    if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
+        // There should be a section break that's in the middle of the document: right after the table.
+        assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:sectPr", 1);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx b/sw/source/filter/ww8/attributeoutputbase.hxx
index 1dffa63..84a1d70 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -156,7 +156,7 @@ public:
     virtual void EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner ) = 0;
 
     /// Called in order to output section breaks.
-    virtual void SectionBreaks(const SwTxtNode& rNode) = 0;
+    virtual void SectionBreaks(const SwNode& rNode) = 0;
 
     /// Called before we start outputting the attributes.
     virtual void StartParagraphProperties() = 0;
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 4cba427..ade163e 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -750,7 +750,7 @@ void DocxAttributeOutput::EmptyParagraph()
     m_pSerializer->singleElementNS( XML_w, XML_p, FSEND );
 }
 
-void DocxAttributeOutput::SectionBreaks(const SwTxtNode& rNode)
+void DocxAttributeOutput::SectionBreaks(const SwNode& rNode)
 {
     // output page/section breaks
     // Writer can have them at the beginning of a paragraph, or at the end, but
@@ -758,16 +758,31 @@ void DocxAttributeOutput::SectionBreaks(const SwTxtNode& rNode)
     // paragraph in a section.  To get it right, we have to switch to the next
     // paragraph, and detect the section breaks there.
     SwNodeIndex aNextIndex( rNode, 1 );
-    if ( aNextIndex.GetNode().IsTxtNode() )
+
+    if (rNode.IsTxtNode())
     {
-        const SwTxtNode* pTxtNode = static_cast< SwTxtNode* >( &aNextIndex.GetNode() );
-        m_rExport.OutputSectionBreaks( pTxtNode->GetpSwAttrSet(), *pTxtNode, m_tableReference->m_bTableCellOpen, pTxtNode->GetTxt().isEmpty() );
+        if (aNextIndex.GetNode().IsTxtNode())
+        {
+            const SwTxtNode* pTxtNode = static_cast<SwTxtNode*>(&aNextIndex.GetNode());
+            m_rExport.OutputSectionBreaks(pTxtNode->GetpSwAttrSet(), *pTxtNode, m_tableReference->m_bTableCellOpen, pTxtNode->GetTxt().isEmpty());
+        }
+        else if (aNextIndex.GetNode().IsTableNode())
+        {
+            const SwTableNode* pTableNode = static_cast<SwTableNode*>(&aNextIndex.GetNode());
+            const SwFrmFmt *pFmt = pTableNode->GetTable().GetFrmFmt();
+            m_rExport.OutputSectionBreaks(&(pFmt->GetAttrSet()), *pTableNode);
+        }
     }
-    else if ( aNextIndex.GetNode().IsTableNode() )
+    else if (rNode.IsEndNode())
     {
-        const SwTableNode* pTableNode = static_cast< SwTableNode* >( &aNextIndex.GetNode() );
-        const SwFrmFmt *pFmt = pTableNode->GetTable().GetFrmFmt();
-        m_rExport.OutputSectionBreaks( &(pFmt->GetAttrSet()), *pTableNode );
+        // End of something: make sure that it's the end of a table.
+        assert(rNode.StartOfSectionNode()->IsTableNode());
+        if (aNextIndex.GetNode().IsTxtNode())
+        {
+            // Handle section break between a table and a text node following it.
+            const SwTxtNode* pTxtNode = aNextIndex.GetNode().GetTxtNode();
+            m_rExport.OutputSectionBreaks(pTxtNode->GetpSwAttrSet(), *pTxtNode, m_tableReference->m_bTableCellOpen, pTxtNode->GetTxt().isEmpty());
+        }
     }
 }
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index f8ae626..4206b88 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -155,7 +155,7 @@ public:
     virtual void EmptyParagraph() SAL_OVERRIDE;
 
     /// Called in order to output section breaks.
-    virtual void SectionBreaks(const SwTxtNode& rNode) SAL_OVERRIDE;
+    virtual void SectionBreaks(const SwNode& rNode) SAL_OVERRIDE;
 
     /// Called before we start outputting the attributes.
     virtual void StartParagraphProperties() SAL_OVERRIDE;
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 5b4c381..0e1d1d1 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -501,6 +501,9 @@ void DocxExport::OutputEndNode( const SwEndNode& rEndNode )
             m_pSections->AppendSection( pAktPageDesc, pParentFmt, nRstLnNum );
         }
     }
+    else if (TXT_MAINTEXT == nTxtTyp && rEndNode.StartOfSectionNode()->IsTableNode())
+        // End node of a table: see if a section break should be written after the table.
+        AttrOutput().SectionBreaks(rEndNode);
 }
 
 void DocxExport::OutputTableNode( const SwTableNode& )
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index d9550c0..e001956 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -324,33 +324,36 @@ void RtfAttributeOutput::EmptyParagraph()
     m_rExport.Strm().WriteCharPtr(SAL_NEWLINE_STRING).WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PAR).WriteChar(' ');
 }
 
-void RtfAttributeOutput::SectionBreaks(const SwTxtNode& rNode)
+void RtfAttributeOutput::SectionBreaks(const SwNode& rNode)
 {
-    OSL_ENSURE(m_aStyles.getLength() == 0, "m_aStyles is not empty");
+    if (rNode.IsTxtNode())
+    {
+        OSL_ENSURE(m_aStyles.getLength() == 0, "m_aStyles is not empty");
 
-    // output page/section breaks
-    SwNodeIndex aNextIndex(rNode, 1);
-    m_rExport.Strm().WriteCharPtr(m_aSectionBreaks.makeStringAndClear().getStr());
-    m_bBufferSectionBreaks = true;
+        // output page/section breaks
+        SwNodeIndex aNextIndex(rNode, 1);
+        m_rExport.Strm().WriteCharPtr(m_aSectionBreaks.makeStringAndClear().getStr());
+        m_bBufferSectionBreaks = true;
 
-    // output section headers / footers
-    if (!m_bBufferSectionHeaders)
-        m_rExport.Strm().WriteCharPtr(m_aSectionHeaders.makeStringAndClear().getStr());
+        // output section headers / footers
+        if (!m_bBufferSectionHeaders)
+            m_rExport.Strm().WriteCharPtr(m_aSectionHeaders.makeStringAndClear().getStr());
 
-    if (aNextIndex.GetNode().IsTxtNode())
-    {
-        const SwTxtNode* pTxtNode = static_cast< SwTxtNode* >(&aNextIndex.GetNode());
-        m_rExport.OutputSectionBreaks(pTxtNode->GetpSwAttrSet(), *pTxtNode);
-        // Save the current page description for now, so later we will be able to access the previous one.
-        m_pPrevPageDesc = pTxtNode->FindPageDesc(false);
-    }
-    else if (aNextIndex.GetNode().IsTableNode())
-    {
-        const SwTableNode* pTableNode = static_cast< SwTableNode* >(&aNextIndex.GetNode());
-        const SwFrmFmt* pFmt = pTableNode->GetTable().GetFrmFmt();
-        m_rExport.OutputSectionBreaks(&(pFmt->GetAttrSet()), *pTableNode);
+        if (aNextIndex.GetNode().IsTxtNode())
+        {
+            const SwTxtNode* pTxtNode = static_cast< SwTxtNode* >(&aNextIndex.GetNode());
+            m_rExport.OutputSectionBreaks(pTxtNode->GetpSwAttrSet(), *pTxtNode);
+            // Save the current page description for now, so later we will be able to access the previous one.
+            m_pPrevPageDesc = pTxtNode->FindPageDesc(false);
+        }
+        else if (aNextIndex.GetNode().IsTableNode())
+        {
+            const SwTableNode* pTableNode = static_cast< SwTableNode* >(&aNextIndex.GetNode());
+            const SwFrmFmt* pFmt = pTableNode->GetTable().GetFrmFmt();
+            m_rExport.OutputSectionBreaks(&(pFmt->GetAttrSet()), *pTableNode);
+        }
+        m_bBufferSectionBreaks = false;
     }
-    m_bBufferSectionBreaks = false;
 }
 
 void RtfAttributeOutput::StartParagraphProperties()
diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx
index 72d07cc..812dcba 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.hxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.hxx
@@ -53,7 +53,7 @@ public:
     virtual void EmptyParagraph() SAL_OVERRIDE;
 
     /// Called in order to output section breaks.
-    virtual void SectionBreaks(const SwTxtNode& rNode) SAL_OVERRIDE;
+    virtual void SectionBreaks(const SwNode& rNode) SAL_OVERRIDE;
 
     /// Called before we start outputting the attributes.
     virtual void StartParagraphProperties() SAL_OVERRIDE;
diff --git a/sw/source/filter/ww8/ww8attributeoutput.hxx b/sw/source/filter/ww8/ww8attributeoutput.hxx
index 8e7041b..e491005 100644
--- a/sw/source/filter/ww8/ww8attributeoutput.hxx
+++ b/sw/source/filter/ww8/ww8attributeoutput.hxx
@@ -36,7 +36,7 @@ public:
     virtual void EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner ) SAL_OVERRIDE;
 
     /// Called in order to output section breaks.
-    virtual void SectionBreaks(const SwTxtNode& /*rNode*/) SAL_OVERRIDE {}
+    virtual void SectionBreaks(const SwNode& /*rNode*/) SAL_OVERRIDE {}
 
     /// Called before we start outputting the attributes.
     virtual void StartParagraphProperties() SAL_OVERRIDE {}


More information about the Libreoffice-commits mailing list