1*70f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*70f497fbSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*70f497fbSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*70f497fbSAndrew Rist * distributed with this work for additional information
6*70f497fbSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*70f497fbSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*70f497fbSAndrew Rist * "License"); you may not use this file except in compliance
9*70f497fbSAndrew Rist * with the License. You may obtain a copy of the License at
10*70f497fbSAndrew Rist *
11*70f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*70f497fbSAndrew Rist *
13*70f497fbSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*70f497fbSAndrew Rist * software distributed under the License is distributed on an
15*70f497fbSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*70f497fbSAndrew Rist * KIND, either express or implied. See the License for the
17*70f497fbSAndrew Rist * specific language governing permissions and limitations
18*70f497fbSAndrew Rist * under the License.
19*70f497fbSAndrew Rist *
20*70f497fbSAndrew Rist *************************************************************/
21*70f497fbSAndrew Rist
22*70f497fbSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // must be first
28cdf0e10cSrcweir #include <canvas/debug.hxx>
29cdf0e10cSrcweir #include <vcl/cvtgrf.hxx>
30cdf0e10cSrcweir #include <tools/urlobj.hxx>
31cdf0e10cSrcweir #include <tools/stream.hxx>
32cdf0e10cSrcweir #include <svtools/grfmgr.hxx>
33cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
34cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
35cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
36cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
37cdf0e10cSrcweir #include <cppcanvas/basegfxfactory.hxx>
38cdf0e10cSrcweir #include <cppcanvas/polypolygon.hxx>
39cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp>
40cdf0e10cSrcweir #include <com/sun/star/drawing/ColorMode.hpp>
41cdf0e10cSrcweir #include <com/sun/star/text/GraphicCrop.hpp>
42cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
43cdf0e10cSrcweir #include <com/sun/star/drawing/PointSequenceSequence.hpp>
44cdf0e10cSrcweir #include <com/sun/star/drawing/PointSequence.hpp>
45cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
46cdf0e10cSrcweir #include <com/sun/star/drawing/XLayerSupplier.hpp>
47cdf0e10cSrcweir #include <com/sun/star/drawing/XLayerManager.hpp>
48cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
49cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
50cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
51cdf0e10cSrcweir
52cdf0e10cSrcweir #include "drawshapesubsetting.hxx"
53cdf0e10cSrcweir #include "drawshape.hxx"
54cdf0e10cSrcweir #include "backgroundshape.hxx"
55cdf0e10cSrcweir #include "mediashape.hxx"
56cdf0e10cSrcweir #include "appletshape.hxx"
57cdf0e10cSrcweir #include "shapeimporter.hxx"
58cdf0e10cSrcweir #include "slideshowexceptions.hxx"
59cdf0e10cSrcweir #include "gdimtftools.hxx"
60cdf0e10cSrcweir #include "tools.hxx"
61cdf0e10cSrcweir #include "slideshowcontext.hxx"
62cdf0e10cSrcweir
63cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
64cdf0e10cSrcweir #include <boost/scoped_ptr.hpp>
65cdf0e10cSrcweir
66cdf0e10cSrcweir using namespace com::sun::star;
67cdf0e10cSrcweir
68cdf0e10cSrcweir namespace slideshow {
69cdf0e10cSrcweir namespace internal {
70cdf0e10cSrcweir
71cdf0e10cSrcweir namespace {
72cdf0e10cSrcweir
importShapeGraphic(GraphicObject & o_rGraphic,uno::Reference<beans::XPropertySet> const & xPropSet)73cdf0e10cSrcweir bool importShapeGraphic(
74cdf0e10cSrcweir GraphicObject & o_rGraphic,
75cdf0e10cSrcweir uno::Reference<beans::XPropertySet> const& xPropSet )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir rtl::OUString aURL;
78cdf0e10cSrcweir if( !getPropertyValue( aURL, xPropSet, OUSTR("GraphicURL")) ||
79cdf0e10cSrcweir aURL.getLength() == 0 )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir // no or empty property - cannot import shape graphic
82cdf0e10cSrcweir return false;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir rtl::OUString const aVndUrl(
86cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.GraphicObject:" ) );
87cdf0e10cSrcweir sal_Int32 nIndex( aURL.indexOf( aVndUrl ) );
88cdf0e10cSrcweir
89cdf0e10cSrcweir if(nIndex != -1)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir // skip past the end of the "vnd..." prefix
92cdf0e10cSrcweir nIndex += aVndUrl.getLength();
93cdf0e10cSrcweir
94cdf0e10cSrcweir if(nIndex >= aURL.getLength())
95cdf0e10cSrcweir {
96cdf0e10cSrcweir OSL_ENSURE( false, "ShapeImporter::importShape(): "
97cdf0e10cSrcweir "embedded graphic has no graphic ID" );
98cdf0e10cSrcweir return false;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
101cdf0e10cSrcweir // unique ID string found in URL, extract
102cdf0e10cSrcweir // to separate string
103cdf0e10cSrcweir rtl::OUString const aUniqueId(
104cdf0e10cSrcweir aURL.copy( nIndex, aURL.getLength() - nIndex ) );
105cdf0e10cSrcweir
106cdf0e10cSrcweir // TODO(T2): Creating a GraphicObject is not
107cdf0e10cSrcweir // thread safe (internally calls VCL, and has
108cdf0e10cSrcweir // unguarded internal singleton mpGlobalMgr)
109cdf0e10cSrcweir
110cdf0e10cSrcweir // fetch already loaded graphic from graphic manager.
111cdf0e10cSrcweir ByteString const aOldString( static_cast<String>(aUniqueId),
112cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 );
113cdf0e10cSrcweir o_rGraphic = GraphicObject( aOldString );
114cdf0e10cSrcweir
115cdf0e10cSrcweir
116cdf0e10cSrcweir if( GRAPHIC_DEFAULT == o_rGraphic.GetType()
117cdf0e10cSrcweir || GRAPHIC_NONE == o_rGraphic.GetType() )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir // even the GrfMgr does not seem to know this graphic
120cdf0e10cSrcweir return false;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir }
123cdf0e10cSrcweir else
124cdf0e10cSrcweir {
125cdf0e10cSrcweir // no special string found, graphic must be
126cdf0e10cSrcweir // external. Load via GraphicIm porter
127cdf0e10cSrcweir INetURLObject aTmp( aURL );
128cdf0e10cSrcweir boost::scoped_ptr<SvStream> pGraphicStream(
129cdf0e10cSrcweir utl::UcbStreamHelper::CreateStream(
130cdf0e10cSrcweir aTmp.GetMainURL( INetURLObject::NO_DECODE ),
131cdf0e10cSrcweir STREAM_READ ) );
132cdf0e10cSrcweir if( !pGraphicStream )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir OSL_ENSURE( false, "ShapeImporter::importShape(): "
135cdf0e10cSrcweir "cannot create input stream for graphic" );
136cdf0e10cSrcweir return false;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir Graphic aTmpGraphic;
140cdf0e10cSrcweir if( GraphicConverter::Import(
141cdf0e10cSrcweir *pGraphicStream, aTmpGraphic ) != ERRCODE_NONE )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir OSL_ENSURE( false, "ShapeImporter::importShape(): "
144cdf0e10cSrcweir "Failed to import shape graphic from given URL" );
145cdf0e10cSrcweir return false;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir o_rGraphic = GraphicObject( aTmpGraphic );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir return true;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
153cdf0e10cSrcweir /** This shape implementation just acts as a dummy for the layermanager.
154cdf0e10cSrcweir Its sole role is for hit test detection of group shapes.
155cdf0e10cSrcweir */
156cdf0e10cSrcweir class ShapeOfGroup : public Shape
157cdf0e10cSrcweir {
158cdf0e10cSrcweir public:
159cdf0e10cSrcweir ShapeOfGroup( ShapeSharedPtr const& pGroupShape,
160cdf0e10cSrcweir uno::Reference<drawing::XShape> const& xShape,
161cdf0e10cSrcweir uno::Reference<beans::XPropertySet> const& xPropSet,
162cdf0e10cSrcweir double nPrio );
163cdf0e10cSrcweir
164cdf0e10cSrcweir // Shape:
165cdf0e10cSrcweir virtual uno::Reference<drawing::XShape> getXShape() const;
166cdf0e10cSrcweir virtual void addViewLayer( ViewLayerSharedPtr const& pNewLayer,
167cdf0e10cSrcweir bool bRedrawLayer );
168cdf0e10cSrcweir virtual bool removeViewLayer( ViewLayerSharedPtr const& pNewLayer );
169cdf0e10cSrcweir virtual bool clearAllViewLayers();
170cdf0e10cSrcweir virtual bool update() const;
171cdf0e10cSrcweir virtual bool render() const;
172cdf0e10cSrcweir virtual bool isContentChanged() const;
173cdf0e10cSrcweir virtual basegfx::B2DRectangle getBounds() const;
174cdf0e10cSrcweir virtual basegfx::B2DRectangle getDomBounds() const;
175cdf0e10cSrcweir virtual basegfx::B2DRectangle getUpdateArea() const;
176cdf0e10cSrcweir virtual bool isVisible() const;
177cdf0e10cSrcweir virtual double getPriority() const;
178cdf0e10cSrcweir virtual bool isBackgroundDetached() const;
179cdf0e10cSrcweir
180cdf0e10cSrcweir private:
181cdf0e10cSrcweir ShapeSharedPtr const mpGroupShape;
182cdf0e10cSrcweir uno::Reference<drawing::XShape> const mxShape;
183cdf0e10cSrcweir double const mnPrio;
184cdf0e10cSrcweir basegfx::B2DPoint maPosOffset;
185cdf0e10cSrcweir double mnWidth;
186cdf0e10cSrcweir double mnHeight;
187cdf0e10cSrcweir };
188cdf0e10cSrcweir
ShapeOfGroup(ShapeSharedPtr const & pGroupShape,uno::Reference<drawing::XShape> const & xShape,uno::Reference<beans::XPropertySet> const & xPropSet,double nPrio)189cdf0e10cSrcweir ShapeOfGroup::ShapeOfGroup( ShapeSharedPtr const& pGroupShape,
190cdf0e10cSrcweir uno::Reference<drawing::XShape> const& xShape,
191cdf0e10cSrcweir uno::Reference<beans::XPropertySet> const& xPropSet,
192cdf0e10cSrcweir double nPrio ) :
193cdf0e10cSrcweir mpGroupShape(pGroupShape),
194cdf0e10cSrcweir mxShape(xShape),
195cdf0e10cSrcweir mnPrio(nPrio)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir // read bound rect
198cdf0e10cSrcweir uno::Any const aTmpRect_( xPropSet->getPropertyValue( OUSTR("BoundRect") ));
199cdf0e10cSrcweir awt::Rectangle const aTmpRect( aTmpRect_.get<awt::Rectangle>() );
200cdf0e10cSrcweir basegfx::B2DRectangle const groupPosSize( pGroupShape->getBounds() );
201cdf0e10cSrcweir maPosOffset = basegfx::B2DPoint( aTmpRect.X - groupPosSize.getMinX(),
202cdf0e10cSrcweir aTmpRect.Y - groupPosSize.getMinY() );
203cdf0e10cSrcweir mnWidth = aTmpRect.Width;
204cdf0e10cSrcweir mnHeight = aTmpRect.Height;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
getXShape() const207cdf0e10cSrcweir uno::Reference<drawing::XShape> ShapeOfGroup::getXShape() const
208cdf0e10cSrcweir {
209cdf0e10cSrcweir return mxShape;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
addViewLayer(ViewLayerSharedPtr const &,bool)212cdf0e10cSrcweir void ShapeOfGroup::addViewLayer( ViewLayerSharedPtr const& /*pNewLayer*/,
213cdf0e10cSrcweir bool /*bRedrawLayer*/ )
214cdf0e10cSrcweir {
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
removeViewLayer(ViewLayerSharedPtr const &)217cdf0e10cSrcweir bool ShapeOfGroup::removeViewLayer( ViewLayerSharedPtr const& /*pNewLayer*/ )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir return true;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
clearAllViewLayers()222cdf0e10cSrcweir bool ShapeOfGroup::clearAllViewLayers()
223cdf0e10cSrcweir {
224cdf0e10cSrcweir return true;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
update() const227cdf0e10cSrcweir bool ShapeOfGroup::update() const
228cdf0e10cSrcweir {
229cdf0e10cSrcweir return true;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
render() const232cdf0e10cSrcweir bool ShapeOfGroup::render() const
233cdf0e10cSrcweir {
234cdf0e10cSrcweir return true;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir
isContentChanged() const237cdf0e10cSrcweir bool ShapeOfGroup::isContentChanged() const
238cdf0e10cSrcweir {
239cdf0e10cSrcweir return false;
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
getBounds() const242cdf0e10cSrcweir basegfx::B2DRectangle ShapeOfGroup::getBounds() const
243cdf0e10cSrcweir {
244cdf0e10cSrcweir basegfx::B2DRectangle const groupPosSize( mpGroupShape->getBounds() );
245cdf0e10cSrcweir double const posX = (groupPosSize.getMinX() + maPosOffset.getX());
246cdf0e10cSrcweir double const posY = (groupPosSize.getMinY() + maPosOffset.getY());
247cdf0e10cSrcweir return basegfx::B2DRectangle( posX, posY, posX + mnWidth, posY + mnHeight );
248cdf0e10cSrcweir }
249cdf0e10cSrcweir
getDomBounds() const250cdf0e10cSrcweir basegfx::B2DRectangle ShapeOfGroup::getDomBounds() const
251cdf0e10cSrcweir {
252cdf0e10cSrcweir return getBounds();
253cdf0e10cSrcweir }
254cdf0e10cSrcweir
getUpdateArea() const255cdf0e10cSrcweir basegfx::B2DRectangle ShapeOfGroup::getUpdateArea() const
256cdf0e10cSrcweir {
257cdf0e10cSrcweir return getBounds();
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
isVisible() const260cdf0e10cSrcweir bool ShapeOfGroup::isVisible() const
261cdf0e10cSrcweir {
262cdf0e10cSrcweir return mpGroupShape->isVisible();
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
getPriority() const265cdf0e10cSrcweir double ShapeOfGroup::getPriority() const
266cdf0e10cSrcweir {
267cdf0e10cSrcweir return mnPrio;
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
isBackgroundDetached() const270cdf0e10cSrcweir bool ShapeOfGroup::isBackgroundDetached() const
271cdf0e10cSrcweir {
272cdf0e10cSrcweir return false;
273cdf0e10cSrcweir }
274cdf0e10cSrcweir
275cdf0e10cSrcweir } // anon namespace
276cdf0e10cSrcweir
createShape(uno::Reference<drawing::XShape> const & xCurrShape,uno::Reference<beans::XPropertySet> const & xPropSet,rtl::OUString const & shapeType) const277cdf0e10cSrcweir ShapeSharedPtr ShapeImporter::createShape(
278cdf0e10cSrcweir uno::Reference<drawing::XShape> const& xCurrShape,
279cdf0e10cSrcweir uno::Reference<beans::XPropertySet> const& xPropSet,
280cdf0e10cSrcweir rtl::OUString const& shapeType ) const
281cdf0e10cSrcweir {
282cdf0e10cSrcweir if( shapeType.equalsAsciiL(
283cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.MediaShape") ) ||
284cdf0e10cSrcweir shapeType.equalsAsciiL(
285cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.MediaShape") ) )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir // Media shape (video etc.). This is a special object
288cdf0e10cSrcweir return createMediaShape(xCurrShape,
289cdf0e10cSrcweir mnAscendingPrio,
290cdf0e10cSrcweir mrContext);
291cdf0e10cSrcweir }
292cdf0e10cSrcweir else if( shapeType.equalsAsciiL(
293cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.PluginShape") ))
294cdf0e10cSrcweir {
295cdf0e10cSrcweir // PropertyValues to copy from XShape to plugin
296cdf0e10cSrcweir static const char* aPropertyValues[] =
297cdf0e10cSrcweir {
298cdf0e10cSrcweir "PluginURL",
299cdf0e10cSrcweir "PluginMimeType",
300cdf0e10cSrcweir "PluginCommands"
301cdf0e10cSrcweir };
302cdf0e10cSrcweir
303cdf0e10cSrcweir // (Netscape)Plugin shape. This is a special object
304cdf0e10cSrcweir return createAppletShape( xCurrShape,
305cdf0e10cSrcweir mnAscendingPrio,
306cdf0e10cSrcweir ::rtl::OUString(
307cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
308cdf0e10cSrcweir "com.sun.star.comp.sfx2.PluginObject" )),
309cdf0e10cSrcweir aPropertyValues,
310cdf0e10cSrcweir sizeof(aPropertyValues)/sizeof(*aPropertyValues),
311cdf0e10cSrcweir mrContext );
312cdf0e10cSrcweir }
313cdf0e10cSrcweir else if( shapeType.equalsAsciiL(
314cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.AppletShape") ))
315cdf0e10cSrcweir {
316cdf0e10cSrcweir // PropertyValues to copy from XShape to applet
317cdf0e10cSrcweir static const char* aPropertyValues[] =
318cdf0e10cSrcweir {
319cdf0e10cSrcweir "AppletCodeBase",
320cdf0e10cSrcweir "AppletName",
321cdf0e10cSrcweir "AppletCode",
322cdf0e10cSrcweir "AppletCommands",
323cdf0e10cSrcweir "AppletIsScript"
324cdf0e10cSrcweir };
325cdf0e10cSrcweir
326cdf0e10cSrcweir // (Java)Applet shape. This is a special object
327cdf0e10cSrcweir return createAppletShape( xCurrShape,
328cdf0e10cSrcweir mnAscendingPrio,
329cdf0e10cSrcweir ::rtl::OUString(
330cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
331cdf0e10cSrcweir "com.sun.star.comp.sfx2.AppletObject" )),
332cdf0e10cSrcweir aPropertyValues,
333cdf0e10cSrcweir sizeof(aPropertyValues)/sizeof(*aPropertyValues),
334cdf0e10cSrcweir mrContext );
335cdf0e10cSrcweir }
336cdf0e10cSrcweir else if( shapeType.equalsAsciiL(
337cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.OLE2Shape") ) ||
338cdf0e10cSrcweir shapeType.equalsAsciiL(
339cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.OLE2Shape") ) )
340cdf0e10cSrcweir {
341cdf0e10cSrcweir // #i46224# Mark OLE shapes as foreign content - scan them for
342cdf0e10cSrcweir // unsupported actions, and fallback to bitmap, if necessary
343cdf0e10cSrcweir return DrawShape::create( xCurrShape,
344cdf0e10cSrcweir mxPage,
345cdf0e10cSrcweir mnAscendingPrio,
346cdf0e10cSrcweir true,
347cdf0e10cSrcweir mrContext );
348cdf0e10cSrcweir }
349cdf0e10cSrcweir else if( shapeType.equalsAsciiL(
350cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM(
351cdf0e10cSrcweir "com.sun.star.drawing.GraphicObjectShape") ) ||
352cdf0e10cSrcweir shapeType.equalsAsciiL(
353cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM(
354cdf0e10cSrcweir "com.sun.star.presentation.GraphicObjectShape") ) )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir GraphicObject aGraphicObject;
357cdf0e10cSrcweir
358cdf0e10cSrcweir // to get hold of GIF animations, inspect Graphic
359cdf0e10cSrcweir // objects more thoroughly (the plain-jane shape
360cdf0e10cSrcweir // metafile of course would only contain the first
361cdf0e10cSrcweir // animation frame)
362cdf0e10cSrcweir if( !importShapeGraphic( aGraphicObject, xPropSet ) )
363cdf0e10cSrcweir return ShapeSharedPtr(); // error loading graphic -
364cdf0e10cSrcweir // #142147# no placeholders in
365cdf0e10cSrcweir // slideshow
366cdf0e10cSrcweir
367cdf0e10cSrcweir if( !aGraphicObject.IsAnimated() )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir // no animation - simply utilize plain draw shape import
370cdf0e10cSrcweir
371cdf0e10cSrcweir // import shape as bitmap - either its a bitmap
372cdf0e10cSrcweir // anyway, or its a metafile, which currently the
373cdf0e10cSrcweir // metafile renderer might not display correctly.
374cdf0e10cSrcweir return DrawShape::create( xCurrShape,
375cdf0e10cSrcweir mxPage,
376cdf0e10cSrcweir mnAscendingPrio,
377cdf0e10cSrcweir true,
378cdf0e10cSrcweir mrContext );
379cdf0e10cSrcweir }
380cdf0e10cSrcweir
381cdf0e10cSrcweir
382cdf0e10cSrcweir // now extract relevant shape attributes via API
383cdf0e10cSrcweir // ---------------------------------------------
384cdf0e10cSrcweir
385cdf0e10cSrcweir drawing::ColorMode eColorMode( drawing::ColorMode_STANDARD );
386cdf0e10cSrcweir sal_Int16 nLuminance(0);
387cdf0e10cSrcweir sal_Int16 nContrast(0);
388cdf0e10cSrcweir sal_Int16 nRed(0);
389cdf0e10cSrcweir sal_Int16 nGreen(0);
390cdf0e10cSrcweir sal_Int16 nBlue(0);
391cdf0e10cSrcweir double nGamma(1.0);
392cdf0e10cSrcweir sal_Int16 nTransparency(0);
393cdf0e10cSrcweir sal_Int32 nRotation(0);
394cdf0e10cSrcweir
395cdf0e10cSrcweir getPropertyValue( eColorMode, xPropSet, OUSTR("GraphicColorMode") );
396cdf0e10cSrcweir getPropertyValue( nLuminance, xPropSet, OUSTR("AdjustLuminance") );
397cdf0e10cSrcweir getPropertyValue( nContrast, xPropSet, OUSTR("AdjustContrast") );
398cdf0e10cSrcweir getPropertyValue( nRed, xPropSet, OUSTR("AdjustRed") );
399cdf0e10cSrcweir getPropertyValue( nGreen, xPropSet, OUSTR("AdjustGreen") );
400cdf0e10cSrcweir getPropertyValue( nBlue, xPropSet, OUSTR("AdjustBlue") );
401cdf0e10cSrcweir getPropertyValue( nGamma, xPropSet, OUSTR("Gamma") );
402cdf0e10cSrcweir getPropertyValue( nTransparency, xPropSet, OUSTR("Transparency") );
403cdf0e10cSrcweir getPropertyValue( nRotation, xPropSet, OUSTR("RotateAngle") );
404cdf0e10cSrcweir
405cdf0e10cSrcweir GraphicAttr aGraphAttrs;
406cdf0e10cSrcweir aGraphAttrs.SetDrawMode( (GraphicDrawMode)eColorMode );
407cdf0e10cSrcweir aGraphAttrs.SetLuminance( nLuminance );
408cdf0e10cSrcweir aGraphAttrs.SetContrast( nContrast );
409cdf0e10cSrcweir aGraphAttrs.SetChannelR( nRed );
410cdf0e10cSrcweir aGraphAttrs.SetChannelG( nGreen );
411cdf0e10cSrcweir aGraphAttrs.SetChannelB( nBlue );
412cdf0e10cSrcweir aGraphAttrs.SetGamma( nGamma );
413cdf0e10cSrcweir aGraphAttrs.SetTransparency( static_cast<sal_uInt8>(nTransparency) );
414cdf0e10cSrcweir aGraphAttrs.SetRotation( static_cast<sal_uInt16>(nRotation*10) );
415cdf0e10cSrcweir
416cdf0e10cSrcweir text::GraphicCrop aGraphCrop;
417cdf0e10cSrcweir if( getPropertyValue( aGraphCrop, xPropSet, OUSTR("GraphicCrop") ))
418cdf0e10cSrcweir {
419cdf0e10cSrcweir aGraphAttrs.SetCrop( aGraphCrop.Left,
420cdf0e10cSrcweir aGraphCrop.Top,
421cdf0e10cSrcweir aGraphCrop.Right,
422cdf0e10cSrcweir aGraphCrop.Bottom );
423cdf0e10cSrcweir }
424cdf0e10cSrcweir
425cdf0e10cSrcweir // fetch readily transformed and color-modified
426cdf0e10cSrcweir // graphic
427cdf0e10cSrcweir // ---------------------------------------------
428cdf0e10cSrcweir
429cdf0e10cSrcweir Graphic aGraphic(
430cdf0e10cSrcweir aGraphicObject.GetTransformedGraphic(
431cdf0e10cSrcweir aGraphicObject.GetPrefSize(),
432cdf0e10cSrcweir aGraphicObject.GetPrefMapMode(),
433cdf0e10cSrcweir aGraphAttrs ) );
434cdf0e10cSrcweir
435cdf0e10cSrcweir return DrawShape::create( xCurrShape,
436cdf0e10cSrcweir mxPage,
437cdf0e10cSrcweir mnAscendingPrio,
438cdf0e10cSrcweir aGraphic,
439cdf0e10cSrcweir mrContext );
440cdf0e10cSrcweir }
441cdf0e10cSrcweir else
442cdf0e10cSrcweir {
443cdf0e10cSrcweir return DrawShape::create( xCurrShape,
444cdf0e10cSrcweir mxPage,
445cdf0e10cSrcweir mnAscendingPrio,
446cdf0e10cSrcweir false,
447cdf0e10cSrcweir mrContext );
448cdf0e10cSrcweir }
449cdf0e10cSrcweir }
450cdf0e10cSrcweir
isSkip(uno::Reference<beans::XPropertySet> const & xPropSet,rtl::OUString const & shapeType,uno::Reference<drawing::XLayer> const & xLayer)451cdf0e10cSrcweir bool ShapeImporter::isSkip(
452cdf0e10cSrcweir uno::Reference<beans::XPropertySet> const& xPropSet,
453cdf0e10cSrcweir rtl::OUString const& shapeType,
454cdf0e10cSrcweir uno::Reference< drawing::XLayer> const& xLayer )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir // skip empty presentation objects:
457cdf0e10cSrcweir bool bEmpty = false;
458cdf0e10cSrcweir if( getPropertyValue( bEmpty,
459cdf0e10cSrcweir xPropSet,
460cdf0e10cSrcweir OUSTR("IsEmptyPresentationObject")) &&
461cdf0e10cSrcweir bEmpty )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir return true;
464cdf0e10cSrcweir }
465cdf0e10cSrcweir
466cdf0e10cSrcweir //skip shapes which corresponds to annotations
467cdf0e10cSrcweir if(xLayer.is())
468cdf0e10cSrcweir {
469cdf0e10cSrcweir rtl::OUString layerName;
470cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xPropLayerSet(
471cdf0e10cSrcweir xLayer, uno::UNO_QUERY );
472cdf0e10cSrcweir const uno::Any& a(xPropLayerSet->getPropertyValue(rtl::OUString::createFromAscii("Name")) );
473cdf0e10cSrcweir bool const bRet = (a >>= layerName);
474cdf0e10cSrcweir if(bRet)
475cdf0e10cSrcweir {
476cdf0e10cSrcweir if( layerName.equals(rtl::OUString::createFromAscii("DrawnInSlideshow")))
477cdf0e10cSrcweir {
478cdf0e10cSrcweir //Transform shapes into PolyPolygons
479cdf0e10cSrcweir importPolygons(xPropSet);
480cdf0e10cSrcweir
481cdf0e10cSrcweir return true;
482cdf0e10cSrcweir }
483cdf0e10cSrcweir }
484cdf0e10cSrcweir }
485cdf0e10cSrcweir
486cdf0e10cSrcweir // don't export presentation placeholders on masterpage
487cdf0e10cSrcweir // they can be non empty when user edits the default texts
488cdf0e10cSrcweir if(mbConvertingMasterPage)
489cdf0e10cSrcweir {
490cdf0e10cSrcweir if(shapeType.equalsAsciiL(
491cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation."
492cdf0e10cSrcweir "TitleTextShape") ) ||
493cdf0e10cSrcweir shapeType.equalsAsciiL(
494cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation."
495cdf0e10cSrcweir "OutlinerShape") ))
496cdf0e10cSrcweir {
497cdf0e10cSrcweir return true;
498cdf0e10cSrcweir }
499cdf0e10cSrcweir }
500cdf0e10cSrcweir return false;
501cdf0e10cSrcweir }
502cdf0e10cSrcweir
503cdf0e10cSrcweir
importPolygons(uno::Reference<beans::XPropertySet> const & xPropSet)504cdf0e10cSrcweir void ShapeImporter::importPolygons(uno::Reference<beans::XPropertySet> const& xPropSet) {
505cdf0e10cSrcweir
506cdf0e10cSrcweir drawing::PointSequenceSequence aRetval;
507cdf0e10cSrcweir sal_Int32 nLineColor=0;
508cdf0e10cSrcweir double fLineWidth;
509cdf0e10cSrcweir getPropertyValue( aRetval, xPropSet, OUSTR("PolyPolygon") );
510cdf0e10cSrcweir getPropertyValue( nLineColor, xPropSet, OUSTR("LineColor") );
511cdf0e10cSrcweir getPropertyValue( fLineWidth, xPropSet, OUSTR("LineWidth") );
512cdf0e10cSrcweir
513cdf0e10cSrcweir drawing::PointSequence* pOuterSequence = aRetval.getArray();
514cdf0e10cSrcweir awt::Point* pInnerSequence = pOuterSequence->getArray();
515cdf0e10cSrcweir
516cdf0e10cSrcweir ::basegfx::B2DPolygon aPoly;
517cdf0e10cSrcweir basegfx::B2DPoint aPoint;
518cdf0e10cSrcweir for( sal_Int32 nCurrPoly=0; nCurrPoly<pOuterSequence->getLength(); ++nCurrPoly, ++pInnerSequence )
519cdf0e10cSrcweir {
520cdf0e10cSrcweir aPoint.setX((*pInnerSequence).X);
521cdf0e10cSrcweir aPoint.setY((*pInnerSequence).Y);
522cdf0e10cSrcweir aPoly.append( aPoint );
523cdf0e10cSrcweir }
524cdf0e10cSrcweir UnoViewVector::const_iterator aIter=(mrContext.mrViewContainer).begin();
525cdf0e10cSrcweir UnoViewVector::const_iterator aEnd=(mrContext.mrViewContainer).end();
526cdf0e10cSrcweir while(aIter != aEnd)
527cdf0e10cSrcweir {
528cdf0e10cSrcweir ::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
529cdf0e10cSrcweir ::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( (*aIter)->getCanvas(),
530cdf0e10cSrcweir aPoly ) );
531cdf0e10cSrcweir if( pPolyPoly )
532cdf0e10cSrcweir {
533cdf0e10cSrcweir pPolyPoly->setRGBALineColor( unoColor2RGBColor( nLineColor ).getIntegerColor() );
534cdf0e10cSrcweir pPolyPoly->setStrokeWidth(fLineWidth);
535cdf0e10cSrcweir pPolyPoly->draw();
536cdf0e10cSrcweir maPolygons.push_back(pPolyPoly);
537cdf0e10cSrcweir }
538cdf0e10cSrcweir aIter++;
539cdf0e10cSrcweir }
540cdf0e10cSrcweir }
541cdf0e10cSrcweir
importBackgroundShape()542cdf0e10cSrcweir ShapeSharedPtr ShapeImporter::importBackgroundShape() // throw (ShapeLoadFailedException)
543cdf0e10cSrcweir {
544cdf0e10cSrcweir if( maShapesStack.empty() )
545cdf0e10cSrcweir throw ShapeLoadFailedException();
546cdf0e10cSrcweir
547cdf0e10cSrcweir XShapesEntry& rTop = maShapesStack.top();
548cdf0e10cSrcweir ShapeSharedPtr pBgShape(
549cdf0e10cSrcweir createBackgroundShape(mxPage,
550cdf0e10cSrcweir uno::Reference<drawing::XDrawPage>(
551cdf0e10cSrcweir rTop.mxShapes,
552cdf0e10cSrcweir uno::UNO_QUERY_THROW),
553cdf0e10cSrcweir mrContext) );
554cdf0e10cSrcweir mnAscendingPrio += 1.0;
555cdf0e10cSrcweir
556cdf0e10cSrcweir return pBgShape;
557cdf0e10cSrcweir }
558cdf0e10cSrcweir
importShape()559cdf0e10cSrcweir ShapeSharedPtr ShapeImporter::importShape() // throw (ShapeLoadFailedException)
560cdf0e10cSrcweir {
561cdf0e10cSrcweir ShapeSharedPtr pRet;
562cdf0e10cSrcweir bool bIsGroupShape = false;
563cdf0e10cSrcweir
564cdf0e10cSrcweir while( !maShapesStack.empty() && !pRet )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir XShapesEntry& rTop = maShapesStack.top();
567cdf0e10cSrcweir if( rTop.mnPos < rTop.mnCount )
568cdf0e10cSrcweir {
569cdf0e10cSrcweir uno::Reference<drawing::XShape> const xCurrShape(
570cdf0e10cSrcweir rTop.mxShapes->getByIndex( rTop.mnPos ), uno::UNO_QUERY );
571cdf0e10cSrcweir ++rTop.mnPos;
572cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xPropSet(
573cdf0e10cSrcweir xCurrShape, uno::UNO_QUERY );
574cdf0e10cSrcweir if( !xPropSet.is() )
575cdf0e10cSrcweir {
576cdf0e10cSrcweir // we definitely need the properties of
577cdf0e10cSrcweir // the shape here. This will also fail,
578cdf0e10cSrcweir // if getByIndex did not return a valid
579cdf0e10cSrcweir // shape
580cdf0e10cSrcweir throw ShapeLoadFailedException();
581cdf0e10cSrcweir }
582cdf0e10cSrcweir
583cdf0e10cSrcweir //Retrieve the layer for the current shape
584cdf0e10cSrcweir uno::Reference< drawing::XLayer > xDrawnInSlideshow;
585cdf0e10cSrcweir
586cdf0e10cSrcweir uno::Reference< drawing::XLayerSupplier > xLayerSupplier(mxPagesSupplier, uno::UNO_QUERY);
587cdf0e10cSrcweir if(xLayerSupplier.is())
588cdf0e10cSrcweir {
589cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess = xLayerSupplier->getLayerManager();
590cdf0e10cSrcweir
591cdf0e10cSrcweir uno::Reference< drawing::XLayerManager > xLayerManager(xNameAccess, uno::UNO_QUERY);
592cdf0e10cSrcweir
593cdf0e10cSrcweir xDrawnInSlideshow = xLayerManager->getLayerForShape(xCurrShape);
594cdf0e10cSrcweir }
595cdf0e10cSrcweir
596cdf0e10cSrcweir rtl::OUString const shapeType( xCurrShape->getShapeType());
597cdf0e10cSrcweir
598cdf0e10cSrcweir // is this shape presentation-invisible?
599cdf0e10cSrcweir if( !isSkip(xPropSet, shapeType, xDrawnInSlideshow) )
600cdf0e10cSrcweir {
601cdf0e10cSrcweir bIsGroupShape = shapeType.equalsAsciiL(
602cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM(
603cdf0e10cSrcweir "com.sun.star.drawing.GroupShape") );
604cdf0e10cSrcweir
605cdf0e10cSrcweir if( rTop.mpGroupShape ) // in group particle mode?
606cdf0e10cSrcweir {
607cdf0e10cSrcweir pRet.reset( new ShapeOfGroup(
608cdf0e10cSrcweir rTop.mpGroupShape /* container shape */,
609cdf0e10cSrcweir xCurrShape, xPropSet,
610cdf0e10cSrcweir mnAscendingPrio ) );
611cdf0e10cSrcweir }
612cdf0e10cSrcweir else
613cdf0e10cSrcweir {
614cdf0e10cSrcweir pRet = createShape( xCurrShape, xPropSet, shapeType );
615cdf0e10cSrcweir }
616cdf0e10cSrcweir mnAscendingPrio += 1.0;
617cdf0e10cSrcweir }
618cdf0e10cSrcweir }
619cdf0e10cSrcweir if( rTop.mnPos >= rTop.mnCount )
620cdf0e10cSrcweir {
621cdf0e10cSrcweir // group or top-level shapes finished:
622cdf0e10cSrcweir maShapesStack.pop();
623cdf0e10cSrcweir }
624cdf0e10cSrcweir if( bIsGroupShape && pRet )
625cdf0e10cSrcweir {
626cdf0e10cSrcweir // push new group on the stack: group traversal
627cdf0e10cSrcweir maShapesStack.push( XShapesEntry( pRet ) );
628cdf0e10cSrcweir }
629cdf0e10cSrcweir }
630cdf0e10cSrcweir
631cdf0e10cSrcweir return pRet;
632cdf0e10cSrcweir }
633cdf0e10cSrcweir
isImportDone() const634cdf0e10cSrcweir bool ShapeImporter::isImportDone() const
635cdf0e10cSrcweir {
636cdf0e10cSrcweir return maShapesStack.empty();
637cdf0e10cSrcweir }
638cdf0e10cSrcweir
getPolygons()639cdf0e10cSrcweir PolyPolygonVector ShapeImporter::getPolygons()
640cdf0e10cSrcweir {
641cdf0e10cSrcweir return maPolygons;
642cdf0e10cSrcweir }
643cdf0e10cSrcweir
ShapeImporter(uno::Reference<drawing::XDrawPage> const & xPage,uno::Reference<drawing::XDrawPage> const & xActualPage,uno::Reference<drawing::XDrawPagesSupplier> const & xPagesSupplier,const SlideShowContext & rContext,sal_Int32 nOrdNumStart,bool bConvertingMasterPage)644cdf0e10cSrcweir ShapeImporter::ShapeImporter( uno::Reference<drawing::XDrawPage> const& xPage,
645cdf0e10cSrcweir uno::Reference<drawing::XDrawPage> const& xActualPage,
646cdf0e10cSrcweir uno::Reference<drawing::XDrawPagesSupplier> const& xPagesSupplier,
647cdf0e10cSrcweir const SlideShowContext& rContext,
648cdf0e10cSrcweir sal_Int32 nOrdNumStart,
649cdf0e10cSrcweir bool bConvertingMasterPage ) :
650cdf0e10cSrcweir mxPage( xActualPage ),
651cdf0e10cSrcweir mxPagesSupplier( xPagesSupplier ),
652cdf0e10cSrcweir mrContext( rContext ),
653cdf0e10cSrcweir maPolygons(),
654cdf0e10cSrcweir maShapesStack(),
655cdf0e10cSrcweir mnAscendingPrio( nOrdNumStart ),
656cdf0e10cSrcweir mbConvertingMasterPage( bConvertingMasterPage )
657cdf0e10cSrcweir {
658cdf0e10cSrcweir uno::Reference<drawing::XShapes> const xShapes(
659cdf0e10cSrcweir xPage, uno::UNO_QUERY_THROW );
660cdf0e10cSrcweir maShapesStack.push( XShapesEntry(xShapes) );
661cdf0e10cSrcweir }
662cdf0e10cSrcweir
663cdf0e10cSrcweir } // namespace internal
664cdf0e10cSrcweir } // namespace presentation
665cdf0e10cSrcweir
666