1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "oox/ppt/pptimport.hxx"
25 #include "oox/drawingml/chart/chartconverter.hxx"
26 #include "oox/dump/pptxdumper.hxx"
27 #include "oox/drawingml/table/tablestylelistfragmenthandler.hxx"
28 #include "oox/helper/graphichelper.hxx"
29 #include "oox/ole/vbaproject.hxx"
30
31 using ::rtl::OUString;
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::xml::sax;
35 using namespace oox::core;
36
37 namespace oox { namespace ppt {
38
PowerPointImport_getImplementationName()39 OUString SAL_CALL PowerPointImport_getImplementationName() throw()
40 {
41 return CREATE_OUSTRING( "com.sun.star.comp.oox.ppt.PowerPointImport" );
42 }
43
PowerPointImport_getSupportedServiceNames()44 uno::Sequence< OUString > SAL_CALL PowerPointImport_getSupportedServiceNames() throw()
45 {
46 Sequence< OUString > aSeq( 2 );
47 aSeq[ 0 ] = CREATE_OUSTRING( "com.sun.star.document.ImportFilter" );
48 aSeq[ 1 ] = CREATE_OUSTRING( "com.sun.star.document.ExportFilter" );
49 return aSeq;
50 }
51
PowerPointImport_createInstance(const Reference<XComponentContext> & rxContext)52 uno::Reference< uno::XInterface > SAL_CALL PowerPointImport_createInstance( const Reference< XComponentContext >& rxContext ) throw( Exception )
53 {
54 return static_cast< ::cppu::OWeakObject* >( new PowerPointImport( rxContext ) );
55 }
56
PowerPointImport(const Reference<XComponentContext> & rxContext)57 PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
58 XmlFilterBase( rxContext ),
59 mxChartConv( new ::oox::drawingml::chart::ChartConverter )
60 {
61 }
62
~PowerPointImport()63 PowerPointImport::~PowerPointImport()
64 {
65 }
66
importDocument()67 bool PowerPointImport::importDocument() throw()
68 {
69 /* to activate the PPTX dumper, define the environment variable
70 OOO_PPTXDUMPER and insert the full path to the file
71 file:///<path-to-oox-module>/source/dump/pptxdumper.ini. */
72 OOX_DUMP_FILE( ::oox::dump::pptx::Dumper );
73
74 OUString aFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "officeDocument" ) );
75 FragmentHandlerRef xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath ) );
76 maTableStyleListPath = xPresentationFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "tableStyles" ) );
77 return importFragment( xPresentationFragmentHandler );
78
79
80 }
81
exportDocument()82 bool PowerPointImport::exportDocument() throw()
83 {
84 return false;
85 }
86
getSchemeColor(sal_Int32 nToken) const87 sal_Int32 PowerPointImport::getSchemeColor( sal_Int32 nToken ) const
88 {
89 sal_Int32 nColor = 0;
90 if ( mpActualSlidePersist )
91 {
92 sal_Bool bColorMapped = sal_False;
93 oox::drawingml::ClrMapPtr pClrMapPtr( mpActualSlidePersist->getClrMap() );
94 if ( pClrMapPtr )
95 bColorMapped = pClrMapPtr->getColorMap( nToken );
96
97 if ( !bColorMapped ) // try masterpage mapping
98 {
99 SlidePersistPtr pMasterPersist = mpActualSlidePersist->getMasterPersist();
100 if ( pMasterPersist )
101 {
102 pClrMapPtr = pMasterPersist->getClrMap();
103 if ( pClrMapPtr )
104 bColorMapped = pClrMapPtr->getColorMap( nToken );
105 }
106 }
107 oox::drawingml::ClrSchemePtr pClrSchemePtr( mpActualSlidePersist->getClrScheme() );
108 if ( pClrSchemePtr )
109 pClrSchemePtr->getColor( nToken, nColor );
110 else
111 {
112 ::oox::drawingml::ThemePtr pTheme = mpActualSlidePersist->getTheme();
113 if( pTheme )
114 {
115 pTheme->getClrScheme().getColor( nToken, nColor );
116 }
117 else
118 {
119 OSL_TRACE("OOX: PowerPointImport::mpThemePtr is NULL");
120 }
121 }
122 }
123 return nColor;
124 }
125
getCurrentTheme() const126 const ::oox::drawingml::Theme* PowerPointImport::getCurrentTheme() const
127 {
128 return mpActualSlidePersist ? mpActualSlidePersist->getTheme().get() : 0;
129 }
130
getVmlDrawing()131 ::oox::vml::Drawing* PowerPointImport::getVmlDrawing()
132 {
133 return mpActualSlidePersist ? mpActualSlidePersist->getDrawing() : 0;
134 }
135
getTableStyles()136 const oox::drawingml::table::TableStyleListPtr PowerPointImport::getTableStyles()
137 {
138 if ( !mpTableStyleList && maTableStyleListPath.getLength() )
139 {
140 mpTableStyleList = oox::drawingml::table::TableStyleListPtr( new oox::drawingml::table::TableStyleList() );
141 importFragment( new oox::drawingml::table::TableStyleListFragmentHandler(
142 *this, maTableStyleListPath, *mpTableStyleList ) );
143 }
144 return mpTableStyleList;;
145 }
146
getChartConverter()147 ::oox::drawingml::chart::ChartConverter& PowerPointImport::getChartConverter()
148 {
149 return *mxChartConv;
150 }
151
152 namespace {
153
154 class PptGraphicHelper : public GraphicHelper
155 {
156 public:
157 explicit PptGraphicHelper( const PowerPointImport& rFilter );
158 virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const;
159 private:
160 const PowerPointImport& mrFilter;
161 };
162
PptGraphicHelper(const PowerPointImport & rFilter)163 PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) :
164 GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
165 mrFilter( rFilter )
166 {
167 }
168
getSchemeColor(sal_Int32 nToken) const169 sal_Int32 PptGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
170 {
171 return mrFilter.getSchemeColor( nToken );
172 }
173
174 } // namespace
175
implCreateGraphicHelper() const176 GraphicHelper* PowerPointImport::implCreateGraphicHelper() const
177 {
178 return new PptGraphicHelper( *this );
179 }
180
implCreateVbaProject() const181 ::oox::ole::VbaProject* PowerPointImport::implCreateVbaProject() const
182 {
183 return new ::oox::ole::VbaProject( getComponentContext(), getModel(), CREATE_OUSTRING( "Impress" ) );
184 }
185
implGetImplementationName() const186 OUString PowerPointImport::implGetImplementationName() const
187 {
188 return PowerPointImport_getImplementationName();
189 }
190
191 }}
192