summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorVinaya Mandke <vinaya.mandke@synerzip.com>2014-03-19 11:54:08 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-03-20 11:34:36 +0000
commit7057d1c9097b7c7aa4d232a9f67199bbf406d3f6 (patch)
treefc72fd4342dd69091378fc90f9e8706d363d7e7c /sw
parent370c29237804bd0bd96ae34ab630681044857780 (diff)
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@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/data/fdo76101.docxbin0 -> 88435 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx10
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx11
-rw-r--r--sw/source/filter/ww8/docxtablestyleexport.cxx9
-rw-r--r--sw/source/filter/ww8/docxtablestyleexport.hxx2
-rw-r--r--sw/source/filter/ww8/wrtw8sty.cxx10
6 files changed, 36 insertions, 6 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/fdo76101.docx b/sw/qa/extras/ooxmlexport/data/fdo76101.docx
new file mode 100644
index 000000000000..d2264f3f8883
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/fdo76101.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 22127556de78..11c1ab076e8a 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 4792dc145d4c..e0dc99754967 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 034123f53c68..c080ba0660b7 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 cd8d9d79defe..f506ae3254ca 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 57266c7d78b7..c1acb3be80ff 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())