[Libreoffice-commits] core.git: sw/qa sw/source

Tushar Bende tushar.bende at synerzip.com
Wed May 21 02:20:07 PDT 2014


 sw/qa/extras/ooxmlexport/data/fdo78469.docx  |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx     |   10 ++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx |   10 +++++++---
 sw/source/filter/ww8/docxattributeoutput.hxx |    3 +++
 sw/source/filter/ww8/docxsdrexport.cxx       |   18 ++++++++++++++++++
 sw/source/filter/ww8/docxsdrexport.hxx       |    3 +++
 6 files changed, 41 insertions(+), 3 deletions(-)

New commits:
commit 1fc9923b194da3ba346f0f0583c130b4284642ba
Author: Tushar Bende <tushar.bende at synerzip.com>
Date:   Fri May 16 15:06:41 2014 +0530

    fdo#78469 FileCorrupt:During export LO was adding wrong tags inside <w:sdtPr>
    
    Description :
    Docx file corrupt after roundtrip.
    Root cause: For some documents During export LO was not checking for the content of sdt and Even if sdt contains Drawing object
    LO was writing text data related tags <w:text/> & <w:dataBinding> in <w:sdtPr>,This was the reason for corruption.
    
    To Fix this checking is there is any Drawing Object in run if yes skip writing <w:dataBinding> tag in <w:sdtPr>
    And if sdt content is Text and Drawing both do not write <Text> or <Picture> as these tags will again result in corruption.
    
    Presently, while writing the sdtContent tag LO does not check for the content type due to which LO ends up adding the dataBinding along with the
    Drawing/AlternateContent which is incorrect according ecma ECMA-376, Second Edition, Part 1 : 17.5.2.6. This cause in file corruption.
    
    Added a check to restrict the aforementioned.
    
    Reviewed on:
    	https://gerrit.libreoffice.org/9371
    
    Change-Id: Id31437db0309b0a2159389a4a9a1f5e13c1ac3a5

diff --git a/sw/qa/extras/ooxmlexport/data/fdo78469.docx b/sw/qa/extras/ooxmlexport/data/fdo78469.docx
new file mode 100644
index 0000000..7ae4d71
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/fdo78469.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index f69396f..22b144e 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -3408,6 +3408,16 @@ DECLARE_OOXMLEXPORT_TEST(testfdo78599,"fdo78599.docx")
     assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink/w:r[6]/w:fldChar", "fldCharType", "end" );
 }
 
+DECLARE_OOXMLEXPORT_TEST(testfdo78469, "fdo78469.docx")
+{
+    xmlDocPtr pXmlDoc = parseExport("word/header1.xml");
+    if (!pXmlDoc)
+       return;
+    // make sure dataBinding & text tags not presernt in sdtcontent
+    assertXPath(pXmlDoc, "/w:hdr[1]/w:tbl[1]/w:tr[1]/w:tc[2]/w:p[1]/w:sdt[2]/w:sdtPr[1]/w:dataBinding[1]",0);
+    assertXPath(pXmlDoc, "/w:hdr[1]/w:tbl[1]/w:tr[1]/w:tc[2]/w:p[1]/w:sdt[2]/w:sdtPr[1]/w:text[1]",0);
+}
+
 DECLARE_OOXMLEXPORT_TEST(testfdo78300,"fdo78300.docx")
 {
     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 6608149..9e3bcd7 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -372,6 +372,9 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT
     m_pSerializer->endElementNS( XML_w, XML_p );
 
     WriteSdtBlock( m_nParagraphSdtPrToken, m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrDataBindingAttrs );
+    //sdtcontent is written so Set m_bParagraphHasDrawing to false
+    m_rExport.SdrExporter().setParagraphHasDrawing( false );
+    m_bRunTextIsOn = false;
     m_pSerializer->mergeTopMarks();
 
     // Check for end of cell, rows, tables here
@@ -411,10 +414,10 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken, ::sax_fastparse
             m_pSerializer->singleElement( nSdtPrToken,
                                           FSNS(XML_w, XML_val), OString::number( rand() ),
                                           FSEND );
-        else if( nSdtPrToken > 0 )
+        else if( (nSdtPrToken > 0) && !(m_bRunTextIsOn && m_rExport.SdrExporter().IsParagraphHasDrawing()))
             m_pSerializer->singleElement( nSdtPrToken, FSEND );
 
-        if( pSdtPrDataBindingAttrs )
+        if(( pSdtPrDataBindingAttrs ) && !m_rExport.SdrExporter().IsParagraphHasDrawing())
         {
             XFastAttributeListRef xAttrList( pSdtPrDataBindingAttrs );
             m_pSerializer->singleElementNS( XML_w, XML_dataBinding, xAttrList );
@@ -1655,7 +1658,7 @@ void DocxAttributeOutput::RunText( const OUString& rText, rtl_TextEncoding /*eCh
     {
         m_closeHyperlinkInPreviousRun = true;
     }
-
+    m_bRunTextIsOn = true;
     // one text can be split into more <w:t>blah</w:t>'s by line breaks etc.
     const sal_Unicode *pBegin = rText.getStr();
     const sal_Unicode *pEnd = pBegin + rText.getLength();
@@ -7388,6 +7391,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri
       m_pRedlineData( NULL ),
       m_nRedlineId( 0 ),
       m_bOpenedSectPr( false ),
+      m_bRunTextIsOn( false ),
       m_bWritingHeaderFooter( false ),
       m_sFieldBkm( ),
       m_nNextBookmarkId( 0 ),
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index c5dac2d..8095d2f 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -720,6 +720,9 @@ private:
     /// Flag indicating that the section properties are being written
     bool m_bOpenedSectPr;
 
+    /// Flag indicating that the Run Text is being written
+    bool m_bRunTextIsOn;
+
     /// Flag indicating that the header \ footer are being written
     bool m_bWritingHeaderFooter;
 
diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx
index e377a36..9da244f 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -145,6 +145,7 @@ struct DocxSdrExport::Impl
     OStringBuffer m_aTextFrameStyle;
     bool m_bFrameBtLr;
     bool m_bDrawingOpen;
+    bool m_bParagraphHasDrawing; ///Flag for checking drawing in a paragraph.
     bool m_bFlyFrameGraphic;
     sax_fastparser::FastAttributeList* m_pFlyFillAttrList;
     sax_fastparser::FastAttributeList* m_pFlyWrapAttrList;
@@ -166,6 +167,7 @@ struct DocxSdrExport::Impl
           m_pTextboxAttrList(0),
           m_bFrameBtLr(false),
           m_bDrawingOpen(false),
+          m_bParagraphHasDrawing(false),
           m_bFlyFrameGraphic(false),
           m_pFlyFillAttrList(0),
           m_pFlyWrapAttrList(0),
@@ -248,6 +250,21 @@ bool DocxSdrExport::IsDrawingOpen()
     return m_pImpl->m_bDrawingOpen;
 }
 
+void DocxSdrExport::setDrawingOpen(bool bDrawingOpen)
+{
+    m_pImpl->m_bDrawingOpen = bDrawingOpen;
+}
+
+bool DocxSdrExport::IsParagraphHasDrawing()
+{
+    return m_pImpl->m_bParagraphHasDrawing;
+}
+
+void DocxSdrExport::setParagraphHasDrawing(bool bParagraphHasDrawing)
+{
+    m_pImpl->m_bParagraphHasDrawing = bParagraphHasDrawing;
+}
+
 sax_fastparser::FastAttributeList*& DocxSdrExport::getFlyFillAttrList()
 {
     return m_pImpl->m_pFlyFillAttrList;
@@ -276,6 +293,7 @@ void DocxSdrExport::setFlyWrapAttrList(sax_fastparser::FastAttributeList* pAttrL
 void DocxSdrExport::startDMLAnchorInline(const SwFrmFmt* pFrmFmt, const Size& rSize)
 {
     m_pImpl->m_bDrawingOpen = true;
+    m_pImpl->m_bParagraphHasDrawing = true;
     m_pImpl->m_pSerializer->startElementNS(XML_w, XML_drawing, FSEND);
 
     const SvxLRSpaceItem pLRSpaceItem = pFrmFmt->GetLRSpace(false);
diff --git a/sw/source/filter/ww8/docxsdrexport.hxx b/sw/source/filter/ww8/docxsdrexport.hxx
index f8ba56d..ebc3c97 100644
--- a/sw/source/filter/ww8/docxsdrexport.hxx
+++ b/sw/source/filter/ww8/docxsdrexport.hxx
@@ -65,6 +65,9 @@ public:
     bool getFrameBtLr();
 
     bool IsDrawingOpen();
+    void setDrawingOpen(bool bDrawingOpen);
+    bool IsParagraphHasDrawing();
+    void setParagraphHasDrawing(bool bParagraphHasDrawing);
     sax_fastparser::FastAttributeList*& getFlyFillAttrList();
     sax_fastparser::FastAttributeList* getFlyWrapAttrList();
     void setFlyWrapAttrList(sax_fastparser::FastAttributeList* pAttrList);


More information about the Libreoffice-commits mailing list