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 "oox/ppt/pptimport.hxx"
21 : #include "oox/drawingml/chart/chartconverter.hxx"
22 : #include "oox/dump/pptxdumper.hxx"
23 : #include "oox/drawingml/table/tablestylelistfragmenthandler.hxx"
24 : #include "oox/helper/graphichelper.hxx"
25 : #include "oox/ole/vbaproject.hxx"
26 :
27 : using ::rtl::OUString;
28 : using namespace ::com::sun::star;
29 : using namespace ::com::sun::star::uno;
30 : using namespace ::com::sun::star::xml::sax;
31 : using namespace oox::core;
32 :
33 : using ::com::sun::star::beans::PropertyValue;
34 : using ::com::sun::star::lang::XComponent;
35 :
36 : namespace oox { namespace ppt {
37 :
38 14 : OUString SAL_CALL PowerPointImport_getImplementationName() throw()
39 : {
40 14 : return CREATE_OUSTRING( "com.sun.star.comp.oox.ppt.PowerPointImport" );
41 : }
42 :
43 2 : uno::Sequence< OUString > SAL_CALL PowerPointImport_getSupportedServiceNames() throw()
44 : {
45 2 : Sequence< OUString > aSeq( 2 );
46 2 : aSeq[ 0 ] = CREATE_OUSTRING( "com.sun.star.document.ImportFilter" );
47 2 : aSeq[ 1 ] = CREATE_OUSTRING( "com.sun.star.document.ExportFilter" );
48 2 : return aSeq;
49 : }
50 :
51 4 : uno::Reference< uno::XInterface > SAL_CALL PowerPointImport_createInstance( const Reference< XComponentContext >& rxContext ) throw( Exception )
52 : {
53 4 : return static_cast< ::cppu::OWeakObject* >( new PowerPointImport( rxContext ) );
54 : }
55 :
56 : #if OSL_DEBUG_LEVEL > 0
57 : XmlFilterBase* PowerPointImport::mpDebugFilterBase = NULL;
58 : #endif
59 :
60 4 : PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
61 : XmlFilterBase( rxContext ),
62 4 : mxChartConv( new ::oox::drawingml::chart::ChartConverter )
63 :
64 : {
65 : #if OSL_DEBUG_LEVEL > 0
66 : mpDebugFilterBase = this;
67 : #endif
68 4 : }
69 :
70 8 : PowerPointImport::~PowerPointImport()
71 : {
72 8 : }
73 :
74 4 : bool PowerPointImport::importDocument() throw()
75 : {
76 : /* to activate the PPTX dumper, define the environment variable
77 : OOO_PPTXDUMPER and insert the full path to the file
78 : file:///<path-to-oox-module>/source/dump/pptxdumper.ini. */
79 : OOX_DUMP_FILE( ::oox::dump::pptx::Dumper );
80 :
81 4 : OUString aFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "officeDocument" ) );
82 4 : FragmentHandlerRef xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath ) );
83 4 : maTableStyleListPath = xPresentationFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "tableStyles" ) );
84 4 : return importFragment( xPresentationFragmentHandler );
85 :
86 :
87 : }
88 :
89 0 : bool PowerPointImport::exportDocument() throw()
90 : {
91 0 : return false;
92 : }
93 :
94 48 : sal_Int32 PowerPointImport::getSchemeColor( sal_Int32 nToken ) const
95 : {
96 48 : sal_Int32 nColor = 0;
97 48 : if ( mpActualSlidePersist )
98 : {
99 48 : sal_Bool bColorMapped = sal_False;
100 48 : oox::drawingml::ClrMapPtr pClrMapPtr( mpActualSlidePersist->getClrMap() );
101 48 : if ( pClrMapPtr )
102 40 : bColorMapped = pClrMapPtr->getColorMap( nToken );
103 :
104 48 : if ( !bColorMapped ) // try masterpage mapping
105 : {
106 8 : SlidePersistPtr pMasterPersist = mpActualSlidePersist->getMasterPersist();
107 8 : if ( pMasterPersist )
108 : {
109 8 : pClrMapPtr = pMasterPersist->getClrMap();
110 8 : if ( pClrMapPtr )
111 8 : bColorMapped = pClrMapPtr->getColorMap( nToken );
112 8 : }
113 : }
114 48 : oox::drawingml::ClrSchemePtr pClrSchemePtr( mpActualSlidePersist->getClrScheme() );
115 48 : if ( pClrSchemePtr )
116 0 : pClrSchemePtr->getColor( nToken, nColor );
117 : else
118 : {
119 48 : ::oox::drawingml::ThemePtr pTheme = mpActualSlidePersist->getTheme();
120 48 : if( pTheme )
121 : {
122 48 : pTheme->getClrScheme().getColor( nToken, nColor );
123 : }
124 : else
125 : {
126 : OSL_TRACE("OOX: PowerPointImport::mpThemePtr is NULL");
127 48 : }
128 48 : }
129 : }
130 48 : return nColor;
131 : }
132 :
133 407 : const ::oox::drawingml::Theme* PowerPointImport::getCurrentTheme() const
134 : {
135 407 : return mpActualSlidePersist ? mpActualSlidePersist->getTheme().get() : 0;
136 : }
137 :
138 4 : sal_Bool SAL_CALL PowerPointImport::filter( const Sequence< PropertyValue >& rDescriptor ) throw( RuntimeException )
139 : {
140 4 : if( XmlFilterBase::filter( rDescriptor ) )
141 4 : return true;
142 :
143 0 : if( isExportFilter() ) {
144 0 : Reference< XExporter > xExporter( getServiceFactory()->createInstance( CREATE_OUSTRING( "com.sun.star.comp.Impress.oox.PowerPointExport" ) ), UNO_QUERY );
145 :
146 0 : if( xExporter.is() ) {
147 0 : Reference< XComponent > xDocument( getModel(), UNO_QUERY );
148 0 : Reference< XFilter > xFilter( xExporter, UNO_QUERY );
149 :
150 0 : if( xFilter.is() ) {
151 0 : xExporter->setSourceDocument( xDocument );
152 0 : if( xFilter->filter( rDescriptor ) )
153 0 : return true;
154 0 : }
155 0 : }
156 : }
157 :
158 0 : return false;
159 : }
160 :
161 0 : ::oox::vml::Drawing* PowerPointImport::getVmlDrawing()
162 : {
163 0 : return mpActualSlidePersist ? mpActualSlidePersist->getDrawing() : 0;
164 : }
165 :
166 0 : const oox::drawingml::table::TableStyleListPtr PowerPointImport::getTableStyles()
167 : {
168 0 : if ( !mpTableStyleList && !maTableStyleListPath.isEmpty() )
169 : {
170 0 : mpTableStyleList = oox::drawingml::table::TableStyleListPtr( new oox::drawingml::table::TableStyleList() );
171 : importFragment( new oox::drawingml::table::TableStyleListFragmentHandler(
172 0 : *this, maTableStyleListPath, *mpTableStyleList ) );
173 : }
174 0 : return mpTableStyleList;
175 : }
176 :
177 0 : ::oox::drawingml::chart::ChartConverter* PowerPointImport::getChartConverter()
178 : {
179 0 : return mxChartConv.get();
180 : }
181 :
182 : namespace {
183 :
184 8 : class PptGraphicHelper : public GraphicHelper
185 : {
186 : public:
187 : explicit PptGraphicHelper( const PowerPointImport& rFilter );
188 : virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const;
189 : private:
190 : const PowerPointImport& mrFilter;
191 : };
192 :
193 4 : PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) :
194 4 : GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
195 8 : mrFilter( rFilter )
196 : {
197 4 : }
198 :
199 48 : sal_Int32 PptGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
200 : {
201 48 : return mrFilter.getSchemeColor( nToken );
202 : }
203 :
204 : } // namespace
205 :
206 4 : GraphicHelper* PowerPointImport::implCreateGraphicHelper() const
207 : {
208 4 : return new PptGraphicHelper( *this );
209 : }
210 :
211 0 : ::oox::ole::VbaProject* PowerPointImport::implCreateVbaProject() const
212 : {
213 0 : return new ::oox::ole::VbaProject( getComponentContext(), getModel(), CREATE_OUSTRING( "Impress" ) );
214 : }
215 :
216 0 : OUString PowerPointImport::implGetImplementationName() const
217 : {
218 0 : return PowerPointImport_getImplementationName();
219 : }
220 :
221 51 : }}
222 :
223 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|