Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sal/config.h>
21 :
22 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 : #include <com/sun/star/uno/XComponentContext.hpp>
24 : #include <osl/diagnose.h>
25 : #include "oox/ppt/pptimport.hxx"
26 : #include "oox/drawingml/chart/chartconverter.hxx"
27 : #include "oox/dump/pptxdumper.hxx"
28 : #include "drawingml/table/tablestylelistfragmenthandler.hxx"
29 : #include "oox/helper/graphichelper.hxx"
30 : #include "oox/ole/vbaproject.hxx"
31 :
32 : #include <services.hxx>
33 :
34 : using namespace ::com::sun::star;
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::xml::sax;
37 : using namespace oox::core;
38 :
39 : using ::com::sun::star::beans::PropertyValue;
40 : using ::com::sun::star::lang::XComponent;
41 :
42 : namespace oox { namespace ppt {
43 :
44 91 : OUString SAL_CALL PowerPointImport_getImplementationName()
45 : {
46 91 : return OUString( "com.sun.star.comp.oox.ppt.PowerPointImport" );
47 : }
48 :
49 5 : uno::Sequence< OUString > SAL_CALL PowerPointImport_getSupportedServiceNames()
50 : {
51 5 : Sequence< OUString > aSeq( 2 );
52 5 : aSeq[ 0 ] = "com.sun.star.document.ImportFilter";
53 5 : aSeq[ 1 ] = "com.sun.star.document.ExportFilter";
54 5 : return aSeq;
55 : }
56 :
57 111 : uno::Reference< uno::XInterface > SAL_CALL PowerPointImport_createInstance( const Reference< XComponentContext >& rxContext ) throw( Exception )
58 : {
59 111 : return static_cast< ::cppu::OWeakObject* >( new PowerPointImport( rxContext ) );
60 : }
61 :
62 : #if OSL_DEBUG_LEVEL > 0
63 : XmlFilterBase* PowerPointImport::mpDebugFilterBase = NULL;
64 : #endif
65 :
66 111 : PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
67 : XmlFilterBase( rxContext ),
68 111 : mxChartConv( new ::oox::drawingml::chart::ChartConverter )
69 :
70 : {
71 : #if OSL_DEBUG_LEVEL > 0
72 : mpDebugFilterBase = this;
73 : #endif
74 111 : }
75 :
76 222 : PowerPointImport::~PowerPointImport()
77 : {
78 222 : }
79 :
80 83 : bool PowerPointImport::importDocument()
81 : {
82 : /* to activate the PPTX dumper, define the environment variable
83 : OOO_PPTXDUMPER and insert the full path to the file
84 : file:///<path-to-oox-module>/source/dump/pptxdumper.ini. */
85 : OOX_DUMP_FILE( ::oox::dump::pptx::Dumper );
86 :
87 83 : importDocumentProperties();
88 :
89 83 : OUString aFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "officeDocument" );
90 166 : FragmentHandlerRef xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath ) );
91 83 : maTableStyleListPath = xPresentationFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( "tableStyles" );
92 166 : return importFragment( xPresentationFragmentHandler );
93 :
94 : }
95 :
96 26 : bool PowerPointImport::exportDocument() throw()
97 : {
98 26 : return false;
99 : }
100 :
101 4275 : sal_Int32 PowerPointImport::getSchemeColor( sal_Int32 nToken ) const
102 : {
103 4275 : sal_Int32 nColor = 0;
104 4275 : if ( mpActualSlidePersist )
105 : {
106 4275 : bool bColorMapped = false;
107 4275 : oox::drawingml::ClrMapPtr pClrMapPtr( mpActualSlidePersist->getClrMap() );
108 4275 : if ( pClrMapPtr )
109 2038 : bColorMapped = pClrMapPtr->getColorMap( nToken );
110 :
111 4275 : if ( !bColorMapped ) // try masterpage mapping
112 : {
113 2237 : SlidePersistPtr pMasterPersist = mpActualSlidePersist->getMasterPersist();
114 2237 : if ( pMasterPersist )
115 : {
116 2237 : pClrMapPtr = pMasterPersist->getClrMap();
117 2237 : if ( pClrMapPtr )
118 2237 : bColorMapped = pClrMapPtr->getColorMap( nToken );
119 2237 : }
120 : }
121 8550 : oox::drawingml::ClrSchemePtr pClrSchemePtr( mpActualSlidePersist->getClrScheme() );
122 4275 : if ( pClrSchemePtr )
123 0 : pClrSchemePtr->getColor( nToken, nColor );
124 : else
125 : {
126 4275 : ::oox::drawingml::ThemePtr pTheme = mpActualSlidePersist->getTheme();
127 4275 : if( pTheme )
128 : {
129 4265 : pTheme->getClrScheme().getColor( nToken, nColor );
130 : }
131 : else
132 : {
133 : OSL_TRACE("OOX: PowerPointImport::mpThemePtr is NULL");
134 4275 : }
135 4275 : }
136 : }
137 4275 : return nColor;
138 : }
139 :
140 16696 : const ::oox::drawingml::Theme* PowerPointImport::getCurrentTheme() const
141 : {
142 16696 : return mpActualSlidePersist ? mpActualSlidePersist->getTheme().get() : 0;
143 : }
144 :
145 110 : sal_Bool SAL_CALL PowerPointImport::filter( const Sequence< PropertyValue >& rDescriptor ) throw( RuntimeException, std::exception )
146 : {
147 110 : if( XmlFilterBase::filter( rDescriptor ) )
148 83 : return true;
149 :
150 27 : if( isExportFilter() ) {
151 26 : Reference< XExporter > xExporter( Reference<css::lang::XMultiServiceFactory>(getComponentContext()->getServiceManager(), UNO_QUERY_THROW)->createInstance( "com.sun.star.comp.Impress.oox.PowerPointExport" ), UNO_QUERY );;
152 :
153 26 : if( xExporter.is() ) {
154 26 : Reference< XComponent > xDocument( getModel(), UNO_QUERY );
155 26 : Reference< XFilter > xFilter( xExporter, UNO_QUERY );
156 :
157 26 : if( xFilter.is() ) {
158 26 : xExporter->setSourceDocument( xDocument );
159 26 : if( xFilter->filter( rDescriptor ) )
160 26 : return true;
161 0 : }
162 0 : }
163 : }
164 :
165 1 : return false;
166 : }
167 :
168 4 : ::oox::vml::Drawing* PowerPointImport::getVmlDrawing()
169 : {
170 4 : return mpActualSlidePersist ? mpActualSlidePersist->getDrawing() : 0;
171 : }
172 :
173 22 : const oox::drawingml::table::TableStyleListPtr PowerPointImport::getTableStyles()
174 : {
175 22 : if ( !mpTableStyleList && !maTableStyleListPath.isEmpty() )
176 : {
177 7 : mpTableStyleList = oox::drawingml::table::TableStyleListPtr( new oox::drawingml::table::TableStyleList() );
178 : importFragment( new oox::drawingml::table::TableStyleListFragmentHandler(
179 7 : *this, maTableStyleListPath, *mpTableStyleList ) );
180 : }
181 22 : return mpTableStyleList;
182 : }
183 :
184 18 : ::oox::drawingml::chart::ChartConverter* PowerPointImport::getChartConverter()
185 : {
186 18 : return mxChartConv.get();
187 : }
188 :
189 : namespace {
190 :
191 166 : class PptGraphicHelper : public GraphicHelper
192 : {
193 : public:
194 : explicit PptGraphicHelper( const PowerPointImport& rFilter );
195 : virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const SAL_OVERRIDE;
196 : virtual sal_Int32 getDefaultChartAreaFillStyle() const SAL_OVERRIDE;
197 : private:
198 : const PowerPointImport& mrFilter;
199 : };
200 :
201 83 : PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) :
202 83 : GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
203 166 : mrFilter( rFilter )
204 : {
205 83 : }
206 :
207 4275 : sal_Int32 PptGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
208 : {
209 4275 : return mrFilter.getSchemeColor( nToken );
210 : }
211 :
212 9 : sal_Int32 PptGraphicHelper::getDefaultChartAreaFillStyle() const
213 : {
214 9 : return XML_noFill;
215 : }
216 :
217 : } // namespace
218 :
219 83 : GraphicHelper* PowerPointImport::implCreateGraphicHelper() const
220 : {
221 83 : return new PptGraphicHelper( *this );
222 : }
223 :
224 0 : ::oox::ole::VbaProject* PowerPointImport::implCreateVbaProject() const
225 : {
226 0 : return new ::oox::ole::VbaProject( getComponentContext(), getModel(), "Impress" );
227 : }
228 :
229 1 : OUString PowerPointImport::getImplementationName() throw (css::uno::RuntimeException, std::exception)
230 : {
231 1 : return PowerPointImport_getImplementationName();
232 : }
233 :
234 246 : }}
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|