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

Vinaya Mandke vinaya.mandke at synerzip.com
Thu Mar 20 04:35:05 PDT 2014


 sw/qa/extras/ooxmlexport/data/fdo76101.docx   |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx      |   10 ++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx  |   11 ++++++++---
 sw/source/filter/ww8/docxtablestyleexport.cxx |    9 +++++++--
 sw/source/filter/ww8/docxtablestyleexport.hxx |    2 +-
 sw/source/filter/ww8/wrtw8sty.cxx             |   10 ++++++++++
 6 files changed, 36 insertions(+), 6 deletions(-)

New commits:
commit 7057d1c9097b7c7aa4d232a9f67199bbf406d3f6
Author: Vinaya Mandke <vinaya.mandke at synerzip.com>
Date:   Wed Mar 19 11:54:08 2014 +0530

    fdo#76101 [DOCX] Export: Limit no of styles in styles.xml
    
    MS Office has an internal limitation of 4091 styles in styles.xml
    and cannot load a .docx with more. However the documentation seems to allow
    that. So if there are more styles, don't export those.
    
    MS Office follows the same principle and repairs the corrupt document by
    removing extra styles.
    
    Change-Id: I20c8775ee9d697a6613be96eb01283844c1d78f5
    Reviewed-on: https://gerrit.libreoffice.org/8653
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/qa/extras/ooxmlexport/data/fdo76101.docx b/sw/qa/extras/ooxmlexport/data/fdo76101.docx
new file mode 100644
index 0000000..d2264f3
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/fdo76101.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 2212755..11c1ab0 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -2920,6 +2920,16 @@ DECLARE_OOXMLEXPORT_TEST(test76317, "test76317.docx")
     assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/a:graphic[1]/a:graphicData[1]/wps:wsp[1]/wps:spPr[1]/a:prstGeom[1]", "prst", "hexagon");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testFdo76101, "fdo76101.docx")
+{
+    xmlDocPtr pXmlDoc = parseExport("word/styles.xml");
+
+    if (!pXmlDoc)
+       return;
+    xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, "/w:styles/w:style");
+    CPPUNIT_ASSERT(4091 >= xmlXPathNodeSetGetLength(pXmlNodes));
+}
+
 DECLARE_OOXMLEXPORT_TEST(test76317_2K10, "test76317_2K10.docx")
 {
     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 4792dc1..e0dc997 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3314,9 +3314,14 @@ void DocxAttributeOutput::DocDefaults( )
     m_pSerializer->endElementNS(XML_w, XML_docDefaults);
 }
 
-void DocxAttributeOutput::EndStyles( sal_uInt16 /*nNumberOfStyles*/ )
-{
-    m_pTableStyleExport->TableStyles();
+void DocxAttributeOutput::EndStyles( sal_uInt16 nNumberOfStyles )
+{
+    // HACK
+    // Ms Office seems to have an internal limitation of 4091 styles
+    // and refuses to load .docx with more, even though the spec seems to allow that;
+    // so simply if there are more styles, don't export those
+    sal_uInt16 nCountStylesToWrite =  (4091 == nNumberOfStyles) ? 0 : (4091 - nNumberOfStyles);
+    m_pTableStyleExport->TableStyles(nCountStylesToWrite);
     m_pSerializer->endElementNS( XML_w, XML_styles );
 }
 
diff --git a/sw/source/filter/ww8/docxtablestyleexport.cxx b/sw/source/filter/ww8/docxtablestyleexport.cxx
index 034123f..c080ba0 100644
--- a/sw/source/filter/ww8/docxtablestyleexport.cxx
+++ b/sw/source/filter/ww8/docxtablestyleexport.cxx
@@ -67,7 +67,7 @@ struct DocxTableStyleExport::Impl
     void tableStyleRColor(uno::Sequence<beans::PropertyValue>& rColor);
 };
 
-void DocxTableStyleExport::TableStyles()
+void DocxTableStyleExport::TableStyles(sal_uInt16 nCountStylesToWrite)
 {
     // Do we have table styles from InteropGrabBag available?
     uno::Reference<beans::XPropertySet> xPropertySet(m_pImpl->m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW);
@@ -84,8 +84,13 @@ void DocxTableStyleExport::TableStyles()
     }
     if (!aTableStyles.getLength())
         return;
+    // HACK
+    // Ms Office seems to have an internal limitation of 4091 styles
+    // and refuses to load .docx with more, even though the spec seems to allow that;
+    // so simply if there are more styles, don't export those
+    nCountStylesToWrite = (nCountStylesToWrite > aTableStyles.getLength()) ?  aTableStyles.getLength(): nCountStylesToWrite;
 
-    for (sal_Int32 i = 0; i < aTableStyles.getLength(); ++i)
+    for (sal_Int32 i = 0; i < nCountStylesToWrite; ++i)
     {
         uno::Sequence<beans::PropertyValue> aTableStyle;
         aTableStyles[i].Value >>= aTableStyle;
diff --git a/sw/source/filter/ww8/docxtablestyleexport.hxx b/sw/source/filter/ww8/docxtablestyleexport.hxx
index cd8d9d7..f506ae3 100644
--- a/sw/source/filter/ww8/docxtablestyleexport.hxx
+++ b/sw/source/filter/ww8/docxtablestyleexport.hxx
@@ -21,7 +21,7 @@ class DocxTableStyleExport
     struct Impl;
     boost::shared_ptr<Impl> m_pImpl;
 public:
-    void TableStyles();
+    void TableStyles(sal_uInt16 nCountStylesToWrite);
     void SetSerializer(sax_fastparser::FSHelperPtr pSerializer);
     DocxTableStyleExport(SwDoc* pDoc, sax_fastparser::FSHelperPtr pSerializer);
     ~DocxTableStyleExport();
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index 57266c7..c1acb3b 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -692,6 +692,8 @@ void WW8AttributeOutput::EndStyles( sal_uInt16 nNumberOfStyles )
     SwWW8Writer::WriteShort( *m_rWW8Export.pTableStrm, m_nStyAnzPos, nNumberOfStyles );
 }
 
+#define MSWORD_MAX_STYLES_LIMIT 4091;
+
 void MSWordStyles::OutputStylesTable()
 {
     m_rExport.bStyDef = true;
@@ -699,6 +701,14 @@ void MSWordStyles::OutputStylesTable()
     m_rExport.AttrOutput().StartStyles();
 
     sal_uInt16 n;
+    // HACK
+    // Ms Office seems to have an internal limitation of 4091 styles
+    // and refuses to load .docx with more, even though the spec seems to allow that;
+    // so simply if there are more styles, don't export those
+    // Implementing check for all exports DOCX, DOC, RTF
+    sal_uInt16 nLimit = MSWORD_MAX_STYLES_LIMIT;
+    nUsedSlots = (nLimit > nUsedSlots)? nUsedSlots : nLimit;
+
     for ( n = 0; n < nUsedSlots; n++ )
     {
         if (m_aNumRules.find(n) != m_aNumRules.end())


More information about the Libreoffice-commits mailing list