From b4380022a664b86bcd29aa5a8ffe27f83afe763f Mon Sep 17 00:00:00 2001 From: Miguel Gomez Date: Mon, 16 Sep 2013 15:02:34 +0200 Subject: fdo#64491: Export theme file when saving Export the theme dom tree that has been parsed when loading the file. This is necessary in order to properly reopen docx files that contain SmartArt diagrams. Change-Id: If8712352e7c70373afb542b450a69bd634632092 Reviewed-on: https://gerrit.libreoffice.org/6005 Reviewed-by: Miklos Vajna Tested-by: Miklos Vajna --- sw/source/filter/ww8/docxexport.cxx | 44 +++++++++++++++++++++++++++++++++++++ sw/source/filter/ww8/docxexport.hxx | 3 +++ 2 files changed, 47 insertions(+) (limited to 'sw') diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index ff451807c0a4..3abb5467a97b 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #include #include @@ -46,6 +49,7 @@ #include #include +#include #include #include #include @@ -345,6 +349,8 @@ void DocxExport::ExportDocument_Impl() WriteSettings(); + WriteTheme(); + delete pStyles, pStyles = NULL; delete m_pSections, m_pSections = NULL; } @@ -738,6 +744,44 @@ void DocxExport::WriteSettings() pFS->endElementNS( XML_w, XML_settings ); } +void DocxExport::WriteTheme() +{ + uno::Reference< beans::XPropertySet > xPropSet( pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW ); + + uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + OUString pName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG; + if ( !xPropSetInfo->hasPropertyByName( pName ) ) + return; + + uno::Reference themeDom; + uno::Sequence< beans::PropertyValue > propList; + xPropSet->getPropertyValue( pName ) >>= propList; + for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) + { + OUString propName = propList[nProp].Name; + if ( propName == "OOXTheme" ) + { + propList[nProp].Value >>= themeDom; + break; + } + } + + // no theme dom to write + if ( !themeDom.is() ) + return; + + m_pFilter->addRelation( m_pDocumentFS->getOutputStream(), + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", + "theme/theme1.xml" ); + + uno::Reference< xml::sax::XSAXSerializable > serializer( themeDom, uno::UNO_QUERY ); + uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() ); + writer->setOutputStream( GetFilter().openFragmentStream( "word/theme/theme1.xml", + "application/vnd.openxmlformats-officedocument.theme+xml" ) ); + serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ), + uno::Sequence< beans::StringPair >() ); +} + VMLExport& DocxExport::VMLExporter() { return *m_pVMLExport; diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx index c7a2b2888c3e..6080cbc49637 100644 --- a/sw/source/filter/ww8/docxexport.hxx +++ b/sw/source/filter/ww8/docxexport.hxx @@ -204,6 +204,9 @@ private: /// Write word/settings.xml void WriteSettings(); + /// Write word/theme/theme1.xml + void WriteTheme(); + /// All xml namespaces to be used at the top of any text .xml file (main doc, headers, footers,...) sax_fastparser::XFastAttributeListRef MainXmlNamespaces( sax_fastparser::FSHelperPtr serializer ); -- cgit