diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-06-01 09:46:16 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-06-01 14:08:06 +0200 |
commit | 720d271788432883e0c968e9dd51bd80ed4b7050 (patch) | |
tree | 019da63284d1643499ad959385e31215140c216b /sw | |
parent | 8d322275b0a4d482296b891a550e538e33986324 (diff) |
sw: add separate DOCM filter
This way at export time we can preserve the correct content-type, which
isn't the same for DOCX and DOCM.
Reviewed-on: https://gerrit.libreoffice.org/38298
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
(cherry picked from commit 697173f6fdfae581022cfdb5ec5171c5a3be58f0)
Conflicts:
sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
sw/source/filter/ww8/docxexportfilter.cxx
Change-Id: I08fa734c72fab7400bd327a07a760839556dbf6f
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/hello.docm | bin | 0 -> 12709 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 33 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 12 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.hxx | 5 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexportfilter.cxx | 7 |
5 files changed, 51 insertions, 6 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/hello.docm b/sw/qa/extras/ooxmlexport/data/hello.docm Binary files differnew file mode 100644 index 000000000000..a00aa58e7ba5 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/hello.docm diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 32e418d09a3a..d8f4dd3cef67 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -37,12 +37,45 @@ protected: } }; +class DocmTest : public SwModelTestBase +{ +public: + DocmTest() + : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "MS Word 2007 XML VBA") + { + } +}; + DECLARE_OOXMLEXPORT_TEST(testTdf92045, "tdf92045.docx") { // This was true, <w:effect w:val="none"/> resulted in setting the blinking font effect. CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(getRun(getParagraph(1), 1), "CharFlash")); } +DECLARE_OOXMLEXPORT_TEST(testDocm, "hello.docm") +{ + // Make sure that we check the name of the export filter. + // This was application/vnd.ms-word.document.macroEnabled.main+xml when the + // name of the import filter was checked. + if (xmlDocPtr pXmlDoc = parseExport("[Content_Types].xml")) + assertXPath(pXmlDoc, + "/ContentType:Types/ContentType:Override[@PartName='/word/document.xml']", + "ContentType", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"); +} + +DECLARE_SW_ROUNDTRIP_TEST(testDocmSave, "hello.docm", nullptr, DocmTest) +{ + // This was + // application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml, + // we used the wrong content type for .docm files. + if (xmlDocPtr pXmlDoc = parseExport("[Content_Types].xml")) + assertXPath(pXmlDoc, + "/ContentType:Types/ContentType:Override[@PartName='/word/document.xml']", + "ContentType", + "application/vnd.ms-word.document.macroEnabled.main+xml"); +} + DECLARE_OOXMLEXPORT_TEST(testTdf95031, "tdf95031.docx") { // This was 494, in-numbering paragraph's automating spacing was handled as visible spacing, while it should not. diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index c36139ca31ac..50048c8adcaa 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1437,7 +1437,7 @@ void DocxExport::SetFS( ::sax_fastparser::FSHelperPtr const & pFS ) mpFS = pFS; } -DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam ) +DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam, bool bDocm ) : MSWordExportBase( pDocument, pCurrentPam, pOriginalPam ), m_pFilter( pFilter ), m_pAttrOutput( nullptr ), @@ -1447,7 +1447,8 @@ DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCur m_nOLEObjects( 0 ), m_nHeadersFootersInSection(0), m_pVMLExport( nullptr ), - m_pSdrExport( nullptr ) + m_pSdrExport( nullptr ), + m_bDocm(bDocm) { // Write the document properies WriteProperties( ); @@ -1456,9 +1457,12 @@ DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCur m_pFilter->addRelation( "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "word/document.xml" ); + // DOCM needs a different media type for the document.xml stream. + OUString aMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"; + if (m_bDocm) + aMediaType = "application/vnd.ms-word.document.macroEnabled.main+xml"; // the actual document - m_pDocumentFS = m_pFilter->openFragmentStreamWithSerializer( "word/document.xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" ); + m_pDocumentFS = m_pFilter->openFragmentStreamWithSerializer( "word/document.xml", aMediaType ); SetFS(m_pDocumentFS); diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx index 1b0b03b345d8..65c9f9283730 100644 --- a/sw/source/filter/ww8/docxexport.hxx +++ b/sw/source/filter/ww8/docxexport.hxx @@ -100,6 +100,9 @@ class DocxExport : public MSWordExportBase /// Exporter of drawings. DocxSdrExport* m_pSdrExport; + /// If the result will be a .docm file or not. + bool m_bDocm; + DocxSettingsData m_aSettings; public: @@ -254,7 +257,7 @@ public: /// Pass the pDocument, pCurrentPam and pOriginalPam to the base class. DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, - SwPaM *pCurrentPam, SwPaM *pOriginalPam ); + SwPaM *pCurrentPam, SwPaM *pOriginalPam, bool bDocm ); /// Destructor. virtual ~DocxExport() override; diff --git a/sw/source/filter/ww8/docxexportfilter.cxx b/sw/source/filter/ww8/docxexportfilter.cxx index 2917da1e374a..0eb4a9a44d62 100644 --- a/sw/source/filter/ww8/docxexportfilter.cxx +++ b/sw/source/filter/ww8/docxexportfilter.cxx @@ -29,6 +29,7 @@ #include <IDocumentLayoutAccess.hxx> #include <cppuhelper/implementationentry.hxx> +#include <unotools/mediadescriptor.hxx> using namespace ::comphelper; using namespace ::com::sun::star; @@ -75,10 +76,14 @@ bool DocxExportFilter::exportDocument() SwPaM *pCurPam = new SwPaM( *aPam.End(), *aPam.Start() ); + OUString aFilterName; + getMediaDescriptor()[utl::MediaDescriptor::PROP_FILTERNAME()] >>= aFilterName; + bool bDocm = aFilterName.endsWith("VBA"); + // export the document // (in a separate block so that it's destructed before the commit) { - DocxExport aExport( this, pDoc, pCurPam, &aPam ); + DocxExport aExport( this, pDoc, pCurPam, &aPam, bDocm ); aExport.ExportDocument( true ); // FIXME support exporting selection only } |