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 | |
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
-rw-r--r-- | filter/Configuration_filter.mk | 2 | ||||
-rw-r--r-- | filter/source/config/fragments/filters/MS_Word_2007_XML_VBA.xcu | 18 | ||||
-rw-r--r-- | filter/source/config/fragments/types/writer_MS_Word_2007_XML.xcu | 2 | ||||
-rw-r--r-- | filter/source/config/fragments/types/writer_MS_Word_2007_XML_VBA.xcu | 17 | ||||
-rw-r--r-- | oox/source/core/filterdetect.cxx | 6 | ||||
-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 |
10 files changed, 93 insertions, 9 deletions
diff --git a/filter/Configuration_filter.mk b/filter/Configuration_filter.mk index 49e09aeb9c3b..9c25d1543e9f 100644 --- a/filter/Configuration_filter.mk +++ b/filter/Configuration_filter.mk @@ -342,6 +342,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_writer_types.xcu writer8 \ writer_MS_Word_2007_XML \ writer_MS_Word_2007_XML_Template \ + writer_MS_Word_2007_XML_VBA \ writer_OOXML \ writer_OOXML_Template \ writer_layout_dump_xml \ @@ -388,6 +389,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_writer_filters writer8_template \ MS_Word_2007_XML \ MS_Word_2007_XML_Template \ + MS_Word_2007_XML_VBA \ OOXML_Text \ OOXML_Text_Template \ writer_layout_dump \ diff --git a/filter/source/config/fragments/filters/MS_Word_2007_XML_VBA.xcu b/filter/source/config/fragments/filters/MS_Word_2007_XML_VBA.xcu new file mode 100644 index 000000000000..6f4774d42b83 --- /dev/null +++ b/filter/source/config/fragments/filters/MS_Word_2007_XML_VBA.xcu @@ -0,0 +1,18 @@ +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. +--> + <node oor:name="MS Word 2007 XML VBA" oor:op="replace"> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER ENCRYPTION PASSWORDTOMODIFY SUPPORTSSIGNING</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.WriterFilter</value></prop> + <prop oor:name="UserData"><value>OXML</value></prop> + <prop oor:name="UIName"><value xml:lang="en-US">Microsoft Word 2007-2013 XML VBA</value></prop> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>writer_MS_Word_2007_VBA</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop> + </node> diff --git a/filter/source/config/fragments/types/writer_MS_Word_2007_XML.xcu b/filter/source/config/fragments/types/writer_MS_Word_2007_XML.xcu index 9e21ef50de5a..d6c62ddf439d 100644 --- a/filter/source/config/fragments/types/writer_MS_Word_2007_XML.xcu +++ b/filter/source/config/fragments/types/writer_MS_Word_2007_XML.xcu @@ -18,7 +18,7 @@ <node oor:name="writer_MS_Word_2007" oor:op="replace" > <prop oor:name="DetectService"><value>com.sun.star.comp.oox.FormatDetector</value></prop> <prop oor:name="URLPattern"/> - <prop oor:name="Extensions"><value>docx docm</value></prop> + <prop oor:name="Extensions"><value>docx</value></prop> <prop oor:name="MediaType"><value>application/msword</value></prop> <prop oor:name="Preferred"><value>true</value></prop> <prop oor:name="PreferredFilter"><value>MS Word 2007 XML</value></prop> diff --git a/filter/source/config/fragments/types/writer_MS_Word_2007_XML_VBA.xcu b/filter/source/config/fragments/types/writer_MS_Word_2007_XML_VBA.xcu new file mode 100644 index 000000000000..5ee986fc8d83 --- /dev/null +++ b/filter/source/config/fragments/types/writer_MS_Word_2007_XML_VBA.xcu @@ -0,0 +1,17 @@ +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. +--> + <node oor:name="writer_MS_Word_2007_VBA" oor:op="replace" > + <prop oor:name="DetectService"><value>com.sun.star.comp.oox.FormatDetector</value></prop> + <prop oor:name="URLPattern"/> + <prop oor:name="Extensions"><value>docm</value></prop> + <prop oor:name="MediaType"><value>application/msword</value></prop> + <prop oor:name="Preferred"><value>true</value></prop> + <prop oor:name="PreferredFilter"><value>MS Word 2007 XML VBA</value></prop> + <prop oor:name="UIName"><value xml:lang="en-US">Microsoft Word 2007-2013 XML VBA</value></prop> + <prop oor:name="ClipboardFormat"><value>MSWordDoc</value></prop> + </node> diff --git a/oox/source/core/filterdetect.cxx b/oox/source/core/filterdetect.cxx index f7a8f8125df5..1eff38b21723 100644 --- a/oox/source/core/filterdetect.cxx +++ b/oox/source/core/filterdetect.cxx @@ -171,10 +171,12 @@ void FilterDetectDocHandler::parseRelationship( const AttributeList& rAttribs ) OUString FilterDetectDocHandler::getFilterNameFromContentType( const OUString& rContentType ) { - if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" || - rContentType == "application/vnd.ms-word.document.macroEnabled.main+xml" ) + if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" ) return OUString( "writer_MS_Word_2007" ); + if( rContentType == "application/vnd.ms-word.document.macroEnabled.main+xml" ) + return OUString( "writer_MS_Word_2007_VBA" ); + if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml" || rContentType == "application/vnd.ms-word.template.macroEnabledTemplate.main+xml" ) return OUString( "writer_MS_Word_2007_Template" ); 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 } |