Update ooo320-m1
[ooovba.git] / filter / source / svg / svgexport.cxx
blob73b192deb9cc73d4c29dfcb0beaf81198254cce3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svgexport.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_filter.hxx"
34 #define ITEMID_FIELD 0
36 #include "svgwriter.hxx"
37 #include "svgfontexport.hxx"
38 #include "svgfilter.hxx"
40 #include <svx/unopage.hxx>
41 #include <svx/svdpage.hxx>
42 #include <svx/svdoutl.hxx>
43 #include <svx/outliner.hxx>
44 #include <svx/flditem.hxx>
45 #include <svx/numitem.hxx>
47 using ::rtl::OUString;
49 // -------------
50 // - SVGExport -
51 // -------------
53 // #110680#
54 SVGExport::SVGExport(
55 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
56 const Reference< XDocumentHandler >& rxHandler )
57 : SvXMLExport( xServiceFactory, OUString(), rxHandler )
59 GetDocHandler()->startDocument();
62 // -----------------------------------------------------------------------------
64 SVGExport::~SVGExport()
66 GetDocHandler()->endDocument();
69 // ------------------------
70 // - ObjectRepresentation -
71 // ------------------------
73 ObjectRepresentation::ObjectRepresentation() :
74 mpMtf( NULL )
78 // -----------------------------------------------------------------------------
80 ObjectRepresentation::ObjectRepresentation( const Reference< XInterface >& rxObject,
81 const GDIMetaFile& rMtf ) :
82 mxObject( rxObject ),
83 mpMtf( new GDIMetaFile( rMtf ) )
87 // -----------------------------------------------------------------------------
89 ObjectRepresentation::ObjectRepresentation( const ObjectRepresentation& rPresentation ) :
90 mxObject( rPresentation.mxObject ),
91 mpMtf( rPresentation.mpMtf ? new GDIMetaFile( *rPresentation.mpMtf ) : NULL )
95 // -----------------------------------------------------------------------------
97 ObjectRepresentation::~ObjectRepresentation()
99 delete mpMtf;
102 // -----------------------------------------------------------------------------
104 ObjectRepresentation& ObjectRepresentation::operator=( const ObjectRepresentation& rPresentation )
106 mxObject = rPresentation.mxObject;
107 delete mpMtf, ( mpMtf = rPresentation.mpMtf ? new GDIMetaFile( *rPresentation.mpMtf ) : NULL );
109 return *this;
112 // -----------------------------------------------------------------------------
114 bool ObjectRepresentation::operator==( const ObjectRepresentation& rPresentation ) const
116 return( ( mxObject == rPresentation.mxObject ) &&
117 ( *mpMtf == *rPresentation.mpMtf ) );
120 // -------------
121 // - SVGFilter -
122 // -------------
124 sal_Bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
125 throw (RuntimeException)
127 Reference< XMultiServiceFactory > xServiceFactory( ::comphelper::getProcessServiceFactory() ) ;
128 Reference< XOutputStream > xOStm;
129 SvStream* pOStm = NULL;
130 sal_Int32 nLength = rDescriptor.getLength();
131 sal_Int32 nPageToExport = SVG_EXPORT_ALLPAGES;
132 const PropertyValue* pValue = rDescriptor.getConstArray();
133 sal_Bool bRet = sal_False;
135 for ( sal_Int32 i = 0 ; i < nLength; ++i)
137 if( pValue[ i ].Name.equalsAscii( "OutputStream" ) )
138 pValue[ i ].Value >>= xOStm;
139 else if( pValue[ i ].Name.equalsAscii( "FileName" ) )
141 ::rtl::OUString aFileName;
143 pValue[ i ].Value >>= aFileName;
144 pOStm = ::utl::UcbStreamHelper::CreateStream( aFileName, STREAM_WRITE | STREAM_TRUNC );
146 if( pOStm )
147 xOStm = Reference< XOutputStream >( new ::utl::OOutputStreamWrapper ( *pOStm ) );
149 else if( pValue[ i ].Name.equalsAscii( "PagePos" ) )
150 pValue[ i ].Value >>= nPageToExport;
153 if( xOStm.is() && xServiceFactory.is() )
155 Reference< XMasterPagesSupplier > xMasterPagesSupplier( mxSrcDoc, UNO_QUERY );
156 Reference< XDrawPagesSupplier > xDrawPagesSupplier( mxSrcDoc, UNO_QUERY );
158 if( xMasterPagesSupplier.is() && xDrawPagesSupplier.is() )
160 Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_QUERY );
161 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY );
163 if( xMasterPages.is() && xDrawPages->getCount() &&
164 xDrawPages.is() && xDrawPages->getCount() )
166 Reference< XDocumentHandler > xDocHandler( implCreateExportDocumentHandler( xOStm ) );
168 if( xDocHandler.is() )
170 mbPresentation = Reference< XPresentationSupplier >( mxSrcDoc, UNO_QUERY ).is();
171 mpObjects = new ObjectMap;
173 // #110680#
174 // mpSVGExport = new SVGExport( xDocHandler );
175 mpSVGExport = new SVGExport( xServiceFactory, xDocHandler );
177 if( nPageToExport < 0 || nPageToExport >= xDrawPages->getCount() )
178 nPageToExport = SVG_EXPORT_ALLPAGES;
182 const sal_Int32 nDefaultPage = ( ( SVG_EXPORT_ALLPAGES == nPageToExport ) ? 0 : nPageToExport );
184 xDrawPages->getByIndex( nDefaultPage ) >>= mxDefaultPage;
186 if( mxDefaultPage.is() )
188 SvxDrawPage* pSvxDrawPage = SvxDrawPage::getImplementation( mxDefaultPage );
190 if( pSvxDrawPage )
192 mpDefaultSdrPage = pSvxDrawPage->GetSdrPage();
193 mpSdrModel = mpDefaultSdrPage->GetModel();
195 if( mpSdrModel )
197 SdrOutliner& rOutl = mpSdrModel->GetDrawOutliner(NULL);
199 maOldFieldHdl = rOutl.GetCalcFieldValueHdl();
200 rOutl.SetCalcFieldValueHdl( LINK( this, SVGFilter, CalcFieldHdl) );
204 if( implCreateObjects( xMasterPages, xDrawPages, nPageToExport ) )
206 ObjectMap::const_iterator aIter( mpObjects->begin() );
207 ::std::vector< ObjectRepresentation > aObjects( mpObjects->size() );
208 sal_uInt32 nPos = 0;
210 while( aIter != mpObjects->end() )
212 aObjects[ nPos++ ] = (*aIter).second;
213 ++aIter;
216 mpSVGFontExport = new SVGFontExport( *mpSVGExport, aObjects );
217 mpSVGWriter = new SVGActionWriter( *mpSVGExport, *mpSVGFontExport );
219 bRet = implExportDocument( xMasterPages, xDrawPages, nPageToExport );
223 catch( ... )
225 delete mpSVGDoc, mpSVGDoc = NULL;
226 DBG_ERROR( "Exception caught" );
229 if( mpSdrModel )
230 mpSdrModel->GetDrawOutliner( NULL ).SetCalcFieldValueHdl( maOldFieldHdl );
232 delete mpSVGWriter, mpSVGWriter = NULL;
233 delete mpSVGExport, mpSVGExport = NULL;
234 delete mpSVGFontExport, mpSVGFontExport = NULL;
235 delete mpObjects, mpObjects = NULL;
236 mbPresentation = sal_False;
242 delete pOStm;
244 return bRet;
247 // -----------------------------------------------------------------------------
249 Reference< XDocumentHandler > SVGFilter::implCreateExportDocumentHandler( const Reference< XOutputStream >& rxOStm )
251 Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
252 Reference< XDocumentHandler > xSaxWriter;
254 if( xMgr.is() && rxOStm.is() )
256 xSaxWriter = Reference< XDocumentHandler >( xMgr->createInstance( B2UCONST( "com.sun.star.xml.sax.Writer" ) ), UNO_QUERY );
258 if( xSaxWriter.is() )
260 Reference< XActiveDataSource > xActiveDataSource( xSaxWriter, UNO_QUERY );
262 if( xActiveDataSource.is() )
263 xActiveDataSource->setOutputStream( rxOStm );
264 else
265 xSaxWriter = NULL;
269 return xSaxWriter;
272 // -----------------------------------------------------------------------------
274 sal_Bool SVGFilter::implExportDocument( const Reference< XDrawPages >& rxMasterPages,
275 const Reference< XDrawPages >& rxDrawPages,
276 sal_Int32 nPageToExport )
278 DBG_ASSERT( rxMasterPages.is() && rxDrawPages.is(),
279 "SVGFilter::implExportDocument: invalid parameter" );
281 OUString aAttr;
282 sal_Int32 nDocWidth = 0, nDocHeight = 0;
283 sal_Int32 nVisible = -1, nVisibleMaster = -1;
284 sal_Bool bRet = sal_False;
285 const sal_Bool bSinglePage = ( rxDrawPages->getCount() == 1 ) || ( SVG_EXPORT_ALLPAGES != nPageToExport );
286 const sal_Int32 nFirstPage = ( ( SVG_EXPORT_ALLPAGES == nPageToExport ) ? 0 : nPageToExport );
287 sal_Int32 nCurPage = nFirstPage, nLastPage = ( bSinglePage ? nFirstPage : ( rxDrawPages->getCount() - 1 ) );
289 const Reference< XPropertySet > xDefaultPagePropertySet( mxDefaultPage, UNO_QUERY );
290 const Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
292 if( xDefaultPagePropertySet.is() )
294 xDefaultPagePropertySet->getPropertyValue( B2UCONST( "Width" ) ) >>= nDocWidth;
295 xDefaultPagePropertySet->getPropertyValue( B2UCONST( "Height" ) ) >>= nDocHeight;
298 if( xExtDocHandler.is() )
299 xExtDocHandler->unknown( SVG_DTD_STRING );
301 #ifdef _SVG_WRITE_EXTENTS
302 aAttr = OUString::valueOf( nDocWidth * 0.01 );
303 aAttr += B2UCONST( "mm" );
304 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "width", aAttr );
306 aAttr = OUString::valueOf( nDocHeight * 0.01 );
307 aAttr += B2UCONST( "mm" );
308 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "height", aAttr );
309 #endif
311 aAttr = B2UCONST( "0 0 " );
312 aAttr += OUString::valueOf( nDocWidth );
313 aAttr += B2UCONST( " " );
314 aAttr += OUString::valueOf( nDocHeight );
316 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "version", B2UCONST( "1.1" ) );
317 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "viewBox", aAttr );
318 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "preserveAspectRatio", B2UCONST( "xMidYMid" ) );
319 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "fill-rule", B2UCONST( "evenodd" ) );
321 if( !bSinglePage )
323 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "xmlns:ooo", B2UCONST( "http://xml.openoffice.org/svg/export" ) );
324 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "onclick", B2UCONST( "onClick(evt)" ) );
325 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "onkeypress", B2UCONST( "onKeyPress(evt)" ) );
329 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "xmlns", B2UCONST( "http://www.w3.org/2000/svg" ) );
330 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "xmlns:xlink", B2UCONST( "http://www.w3.org/1999/xlink" ) );
332 mpSVGDoc = new SvXMLElementExport( *mpSVGExport, XML_NAMESPACE_NONE, "svg", TRUE, TRUE );
334 while( ( nCurPage <= nLastPage ) && ( -1 == nVisible ) )
336 Reference< XDrawPage > xDrawPage;
338 rxDrawPages->getByIndex( nCurPage ) >>= xDrawPage;
340 if( xDrawPage.is() )
342 Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY );
344 if( xPropSet.is() )
346 sal_Bool bVisible = sal_False;
348 if( !mbPresentation || bSinglePage ||
349 ( ( xPropSet->getPropertyValue( B2UCONST( "Visible" ) ) >>= bVisible ) && bVisible ) )
351 Reference< XMasterPageTarget > xMasterTarget( xDrawPage, UNO_QUERY );
353 if( xMasterTarget.is() )
355 Reference< XDrawPage > xMasterPage( xMasterTarget->getMasterPage() );
357 nVisible = nCurPage;
359 for( sal_Int32 nMaster = 0, nMasterCount = rxMasterPages->getCount();
360 ( nMaster < nMasterCount ) && ( -1 == nVisibleMaster );
361 ++nMaster )
363 Reference< XDrawPage > xMasterTestPage;
365 rxMasterPages->getByIndex( nMaster ) >>= xMasterTestPage;
367 if( xMasterTestPage == xMasterPage )
368 nVisibleMaster = nMaster;
375 ++nCurPage;
378 #ifdef _SVG_EMBED_FONTS
379 mpSVGFontExport->EmbedFonts();
380 #endif
382 if( -1 != nVisible )
384 if( bSinglePage )
385 implExportPages( rxMasterPages, nVisibleMaster, nVisibleMaster, nVisibleMaster, sal_True );
386 else
388 implGenerateMetaData( rxMasterPages, rxDrawPages );
389 implGenerateScript( rxMasterPages, rxDrawPages );
390 implExportPages( rxMasterPages, 0, rxMasterPages->getCount() - 1, nVisibleMaster, sal_True );
393 implExportPages( rxDrawPages, nFirstPage, nLastPage, nVisible, sal_False );
395 delete mpSVGDoc, mpSVGDoc = NULL;
396 bRet = sal_True;
399 return bRet;
402 // -----------------------------------------------------------------------------
404 sal_Bool SVGFilter::implGenerateMetaData( const Reference< XDrawPages >& /* rxMasterPages */,
405 const Reference< XDrawPages >& rxDrawPages )
407 sal_Bool bRet = sal_False;
409 if( rxDrawPages->getCount() )
411 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "id", B2UCONST( "meta_slides" ) );
412 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "numberOfSlides", OUString::valueOf( rxDrawPages->getCount() ) );
415 SvXMLElementExport aExp( *mpSVGExport, XML_NAMESPACE_NONE, "ooo:slidesInfo", TRUE, TRUE );
416 const OUString aId( B2UCONST( "meta_slide" ) );
418 for( sal_Int32 i = 0, nCount = rxDrawPages->getCount(); i < nCount; ++i )
420 OUString aSlideId( aId );
421 Reference< XDrawPage > xDrawPage( rxDrawPages->getByIndex( i ), UNO_QUERY );
422 Reference< XMasterPageTarget > xMasterPageTarget( xDrawPage, UNO_QUERY );
423 Reference< XDrawPage > xMasterPage( xMasterPageTarget->getMasterPage(), UNO_QUERY );
424 sal_Bool bMasterVisible = sal_True;
425 OUString aMasterVisibility;
427 aSlideId += OUString::valueOf( i );
429 if( mbPresentation )
431 Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY );
433 if( xPropSet.is() )
434 xPropSet->getPropertyValue( B2UCONST( "Background" ) ) >>= bMasterVisible;
437 if( bMasterVisible )
438 aMasterVisibility = B2UCONST( "visible" );
439 else
440 aMasterVisibility = B2UCONST( "hidden" );
442 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "id", aSlideId );
443 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "slide", implGetValidIDFromInterface( xDrawPage ) );
444 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "master", implGetValidIDFromInterface( xMasterPage ) );
445 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "master-visibility", aMasterVisibility );
448 SvXMLElementExport aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "ooo:slideInfo", TRUE, TRUE );
454 bRet =sal_True;
457 return bRet;
460 // -----------------------------------------------------------------------------
462 sal_Bool SVGFilter::implGenerateScript( const Reference< XDrawPages >& /* rxMasterPages */,
463 const Reference< XDrawPages >& /* rxDrawPages */ )
465 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "type", B2UCONST( "text/ecmascript" ) );
468 SvXMLElementExport aExp( *mpSVGExport, XML_NAMESPACE_NONE, "script", TRUE, TRUE );
469 Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
471 if( xExtDocHandler.is() )
473 xExtDocHandler->unknown( OUString::createFromAscii( aSVGScript1 ) );
474 xExtDocHandler->unknown( OUString::createFromAscii( aSVGScript2 ) );
478 return sal_True;
481 // -----------------------------------------------------------------------------
483 sal_Bool SVGFilter::implExportPages( const Reference< XDrawPages >& rxPages,
484 sal_Int32 nFirstPage, sal_Int32 nLastPage,
485 sal_Int32 nVisiblePage, sal_Bool bMaster )
487 DBG_ASSERT( nFirstPage <= nLastPage,
488 "SVGFilter::implExportPages: nFirstPage > nLastPage" );
490 sal_Bool bRet = sal_False;
492 for( sal_Int32 i = nFirstPage; i <= nLastPage; ++i )
494 Reference< XDrawPage > xDrawPage;
496 rxPages->getByIndex( i ) >>= xDrawPage;
498 if( xDrawPage.is() )
500 Reference< XShapes > xShapes( xDrawPage, UNO_QUERY );
502 if( xShapes.is() )
504 OUString aAttr;
506 if( i == nVisiblePage )
507 aAttr = B2UCONST( "visible" );
508 else
509 aAttr = B2UCONST( "hidden" );
511 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "visibility", aAttr );
512 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "id", implGetValidIDFromInterface( xShapes ) );
515 SvXMLElementExport aExp( *mpSVGExport, XML_NAMESPACE_NONE, "g", TRUE, TRUE );
516 const Point aNullPt;
519 Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
521 if( xExtDocHandler.is() )
523 SvXMLElementExport aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "desc", TRUE, TRUE );
524 OUString aDesc;
526 if( bMaster )
527 aDesc = B2UCONST( "Master slide" );
528 else
529 aDesc = B2UCONST( "Slide" );
531 xExtDocHandler->unknown( aDesc );
535 if( bMaster )
537 const GDIMetaFile& rMtf = (*mpObjects)[ xDrawPage ].GetRepresentation();
538 mpSVGWriter->WriteMetaFile( aNullPt, rMtf.GetPrefSize(), rMtf, SVGWRITER_WRITE_FILL );
541 bRet = implExportShapes( xShapes ) || bRet;
547 return bRet;
550 // -----------------------------------------------------------------------------
552 sal_Bool SVGFilter::implExportShapes( const Reference< XShapes >& rxShapes )
554 Reference< XShape > xShape;
555 sal_Bool bRet = sal_False;
557 for( sal_Int32 i = 0, nCount = rxShapes->getCount(); i < nCount; ++i )
559 if( ( rxShapes->getByIndex( i ) >>= xShape ) && xShape.is() )
560 bRet = implExportShape( xShape ) || bRet;
562 xShape = NULL;
565 return bRet;
568 // -----------------------------------------------------------------------------
570 sal_Bool SVGFilter::implExportShape( const Reference< XShape >& rxShape )
572 Reference< XPropertySet > xShapePropSet( rxShape, UNO_QUERY );
573 sal_Bool bRet = sal_False;
575 if( xShapePropSet.is() )
577 const ::rtl::OUString aShapeType( rxShape->getShapeType() );
578 bool bHideObj = false;
580 if( mbPresentation )
582 xShapePropSet->getPropertyValue( B2UCONST( "IsEmptyPresentationObject" ) ) >>= bHideObj;
584 if( !bHideObj )
586 const Reference< XPropertySet > xDefaultPagePropertySet( mxDefaultPage, UNO_QUERY );
587 Reference< XPropertySetInfo > xPagePropSetInfo( xDefaultPagePropertySet->getPropertySetInfo() );
589 if( xPagePropSetInfo.is() )
591 static const ::rtl::OUString aHeaderString( B2UCONST( "IsHeaderVisible" ) );
592 static const ::rtl::OUString aFooterString( B2UCONST( "IsFooterVisible" ) );
593 static const ::rtl::OUString aDateTimeString( B2UCONST( "IsDateTimeVisible" ) );
594 static const ::rtl::OUString aPageNumberString( B2UCONST( "IsPageNumberVisible" ) );
596 Any aProperty;
597 bool bValue = sal_False;
599 if( ( aShapeType.lastIndexOf( B2UCONST( "presentation.HeaderShape" ) ) != -1 ) &&
600 xPagePropSetInfo->hasPropertyByName( aHeaderString ) &&
601 ( ( aProperty = xDefaultPagePropertySet->getPropertyValue( aHeaderString ) ) >>= bValue ) &&
602 !bValue )
604 bHideObj = true;
606 else if( ( aShapeType.lastIndexOf( B2UCONST( "presentation.FooterShape" ) ) != -1 ) &&
607 xPagePropSetInfo->hasPropertyByName( aFooterString ) &&
608 ( ( aProperty = xDefaultPagePropertySet->getPropertyValue( aFooterString ) ) >>= bValue ) &&
609 !bValue )
611 bHideObj = true;
613 else if( ( aShapeType.lastIndexOf( B2UCONST( "presentation.DateTimeShape" ) ) != -1 ) &&
614 xPagePropSetInfo->hasPropertyByName( aDateTimeString ) &&
615 ( ( aProperty = xDefaultPagePropertySet->getPropertyValue( aDateTimeString ) ) >>= bValue ) &&
616 !bValue )
618 bHideObj = true;
620 else if( ( aShapeType.lastIndexOf( B2UCONST( "presentation.SlideNumberShape" ) ) != -1 ) &&
621 xPagePropSetInfo->hasPropertyByName( aPageNumberString ) &&
622 ( ( aProperty = xDefaultPagePropertySet->getPropertyValue( aPageNumberString ) ) >>= bValue ) &&
623 !bValue )
625 bHideObj = true;
631 if( !bHideObj )
633 OUString aObjName( implGetValidIDFromInterface( rxShape ) ), aObjDesc;
635 if( aObjName.getLength() )
636 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "id", aObjName );
638 if( aShapeType.lastIndexOf( B2UCONST( "drawing.GroupShape" ) ) != -1 )
640 Reference< XShapes > xShapes( rxShape, UNO_QUERY );
642 if( xShapes.is() )
644 SvXMLElementExport aExp( *mpSVGExport, XML_NAMESPACE_NONE, "g", TRUE, TRUE );
647 SvXMLElementExport aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "desc", TRUE, TRUE );
648 Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
650 xExtDocHandler->unknown( B2UCONST( "Group" ) );
653 bRet = implExportShapes( xShapes );
657 if( !bRet )
659 Reference< XText > xText( rxShape, UNO_QUERY );
660 ::com::sun::star::awt::Rectangle aBoundRect;
661 const GDIMetaFile& rMtf = (*mpObjects)[ rxShape ].GetRepresentation();
663 xShapePropSet->getPropertyValue( B2UCONST( "BoundRect" ) ) >>= aBoundRect;
664 const Point aTopLeft( aBoundRect.X, aBoundRect.Y );
665 const Size aSize( aBoundRect.Width, aBoundRect.Height );
668 SvXMLElementExport aExp( *mpSVGExport, XML_NAMESPACE_NONE, "g", TRUE, TRUE );
671 SvXMLElementExport aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "desc", TRUE, TRUE );
672 Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
674 xExtDocHandler->unknown( implGetDescriptionFromShape( rxShape ) );
677 if( rMtf.GetActionCount() )
679 if( ( aShapeType.lastIndexOf( B2UCONST( "drawing.OLE2Shape" ) ) != -1 ) ||
680 ( aShapeType.lastIndexOf( B2UCONST( "drawing.GraphicObjectShape" ) ) != -1 ) )
682 SvXMLElementExport aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "g", TRUE, TRUE );
683 mpSVGWriter->WriteMetaFile( aTopLeft, aSize, rMtf, SVGWRITER_WRITE_ALL);
685 else
687 // write geometries
688 SvXMLElementExport aGeometryExp( *mpSVGExport, XML_NAMESPACE_NONE, "g", TRUE, TRUE );
689 mpSVGWriter->WriteMetaFile( aTopLeft, aSize, rMtf, SVGWRITER_WRITE_FILL );
691 // write text separately
692 SvXMLElementExport aTextExp( *mpSVGExport, XML_NAMESPACE_NONE, "g", TRUE, TRUE );
693 mpSVGWriter->WriteMetaFile( aTopLeft, aSize, rMtf, SVGWRITER_WRITE_TEXT );
698 bRet = sal_True;
703 return bRet;
706 // -----------------------------------------------------------------------------
708 sal_Bool SVGFilter::implCreateObjects( const Reference< XDrawPages >& rxMasterPages,
709 const Reference< XDrawPages >& rxDrawPages,
710 sal_Int32 nPageToExport )
712 if( SVG_EXPORT_ALLPAGES == nPageToExport )
714 sal_Int32 i, nCount;
716 for( i = 0, nCount = rxMasterPages->getCount(); i < nCount; ++i )
718 Reference< XDrawPage > xMasterPage;
720 rxMasterPages->getByIndex( i ) >>= xMasterPage;
722 if( xMasterPage.is() )
724 Reference< XShapes > xShapes( xMasterPage, UNO_QUERY );
726 implCreateObjectsFromBackground( xMasterPage );
728 if( xShapes.is() )
729 implCreateObjectsFromShapes( xShapes );
733 for( i = 0, nCount = rxDrawPages->getCount(); i < nCount; ++i )
735 Reference< XDrawPage > xDrawPage;
737 rxDrawPages->getByIndex( i ) >>= xDrawPage;
739 if( xDrawPage.is() )
741 Reference< XShapes > xShapes( xDrawPage, UNO_QUERY );
743 if( xShapes.is() )
744 implCreateObjectsFromShapes( xShapes );
748 else
750 DBG_ASSERT( nPageToExport >= 0 && nPageToExport < rxDrawPages->getCount(),
751 "SVGFilter::implCreateObjects: invalid page number to export" );
753 Reference< XDrawPage > xDrawPage;
755 rxDrawPages->getByIndex( nPageToExport ) >>= xDrawPage;
757 if( xDrawPage.is() )
759 Reference< XMasterPageTarget > xMasterTarget( xDrawPage, UNO_QUERY );
761 if( xMasterTarget.is() )
763 Reference< XDrawPage > xMasterPage( xMasterTarget->getMasterPage() );
765 if( xMasterPage.is() )
767 Reference< XShapes > xShapes( xMasterPage, UNO_QUERY );
769 implCreateObjectsFromBackground( xMasterPage );
771 if( xShapes.is() )
772 implCreateObjectsFromShapes( xShapes );
776 Reference< XShapes > xShapes( xDrawPage, UNO_QUERY );
778 if( xShapes.is() )
779 implCreateObjectsFromShapes( xShapes );
783 return sal_True;
786 // -----------------------------------------------------------------------------
788 sal_Bool SVGFilter::implCreateObjectsFromShapes( const Reference< XShapes >& rxShapes )
790 Reference< XShape > xShape;
791 sal_Bool bRet = sal_False;
793 for( sal_Int32 i = 0, nCount = rxShapes->getCount(); i < nCount; ++i )
795 if( ( rxShapes->getByIndex( i ) >>= xShape ) && xShape.is() )
796 bRet = implCreateObjectsFromShape( xShape ) || bRet;
798 xShape = NULL;
801 return bRet;
804 // -----------------------------------------------------------------------------
806 sal_Bool SVGFilter::implCreateObjectsFromShape( const Reference< XShape >& rxShape )
808 sal_Bool bRet = sal_False;
810 if( rxShape->getShapeType().lastIndexOf( B2UCONST( "drawing.GroupShape" ) ) != -1 )
812 Reference< XShapes > xShapes( rxShape, UNO_QUERY );
814 if( xShapes.is() )
815 bRet = implCreateObjectsFromShapes( xShapes );
817 else
819 SdrObject* pObj = GetSdrObjectFromXShape( rxShape );
821 if( pObj )
823 Graphic aGraphic( SdrExchangeView::GetObjGraphic( pObj->GetModel(), pObj ) );
825 if( aGraphic.GetType() != GRAPHIC_NONE )
827 if( aGraphic.GetType() == GRAPHIC_BITMAP )
829 GDIMetaFile aMtf;
830 const Point aNullPt;
831 const Size aSize( pObj->GetCurrentBoundRect().GetSize() );
833 aMtf.AddAction( new MetaBmpExScaleAction( aNullPt, aSize, aGraphic.GetBitmapEx() ) );
834 aMtf.SetPrefSize( aSize );
835 aMtf.SetPrefMapMode( MAP_100TH_MM );
837 (*mpObjects)[ rxShape ] = ObjectRepresentation( rxShape, aMtf );
839 else
840 (*mpObjects)[ rxShape ] = ObjectRepresentation( rxShape, aGraphic.GetGDIMetaFile() );
842 bRet = sal_True;
847 return bRet;
850 // -----------------------------------------------------------------------------
852 sal_Bool SVGFilter::implCreateObjectsFromBackground( const Reference< XDrawPage >& rxMasterPage )
854 Reference< XExporter > xExporter( mxMSF->createInstance( B2UCONST( "com.sun.star.drawing.GraphicExportFilter" ) ), UNO_QUERY );
855 sal_Bool bRet = sal_False;
857 if( xExporter.is() )
859 GDIMetaFile aMtf;
860 Reference< XFilter > xFilter( xExporter, UNO_QUERY );
862 utl::TempFile aFile;
863 aFile.EnableKillingFile();
865 Sequence< PropertyValue > aDescriptor( 3 );
866 aDescriptor[0].Name = B2UCONST( "FilterName" );
867 aDescriptor[0].Value <<= B2UCONST( "SVM" );
868 aDescriptor[1].Name = B2UCONST( "URL" );
869 aDescriptor[1].Value <<= OUString( aFile.GetURL() );
870 aDescriptor[2].Name = B2UCONST( "ExportOnlyBackground" );
871 aDescriptor[2].Value <<= (sal_Bool) sal_True;
873 xExporter->setSourceDocument( Reference< XComponent >( rxMasterPage, UNO_QUERY ) );
874 xFilter->filter( aDescriptor );
875 aMtf.Read( *aFile.GetStream( STREAM_READ ) );
877 (*mpObjects)[ rxMasterPage ] = ObjectRepresentation( rxMasterPage, aMtf );
879 bRet = sal_True;
882 return bRet;
885 // -----------------------------------------------------------------------------
887 OUString SVGFilter::implGetDescriptionFromShape( const Reference< XShape >& rxShape )
889 OUString aRet;
890 const OUString aShapeType( rxShape->getShapeType() );
892 if( aShapeType.lastIndexOf( B2UCONST( "drawing.GroupShape" ) ) != -1 )
893 aRet = B2UCONST( "Group" );
894 else if( aShapeType.lastIndexOf( B2UCONST( "drawing.GraphicObjectShape" ) ) != -1 )
895 aRet = B2UCONST( "Graphic" );
896 else if( aShapeType.lastIndexOf( B2UCONST( "drawing.OLE2Shape" ) ) != -1 )
897 aRet = B2UCONST( "OLE2" );
898 else if( aShapeType.lastIndexOf( B2UCONST( "presentation.HeaderShape" ) ) != -1 )
899 aRet = B2UCONST( "Header" );
900 else if( aShapeType.lastIndexOf( B2UCONST( "presentation.FooterShape" ) ) != -1 )
901 aRet = B2UCONST( "Footer" );
902 else if( aShapeType.lastIndexOf( B2UCONST( "presentation.DateTimeShape" ) ) != -1 )
903 aRet = B2UCONST( "Date/Time" );
904 else if( aShapeType.lastIndexOf( B2UCONST( "presentation.SlideNumberShape" ) ) != -1 )
905 aRet = B2UCONST( "Slide Number" );
906 else
907 aRet = B2UCONST( "Drawing" );
909 return aRet;
912 // -----------------------------------------------------------------------------
914 OUString SVGFilter::implGetValidIDFromInterface( const Reference< XInterface >& rxIf )
916 Reference< XNamed > xNamed( rxIf, UNO_QUERY );
917 OUString aRet;
919 if( xNamed.is() )
920 aRet = xNamed->getName().replace( ' ', '_' );
922 return aRet;
925 // -----------------------------------------------------------------------------
927 IMPL_LINK( SVGFilter, CalcFieldHdl, EditFieldInfo*, pInfo )
929 OUString aRepresentation;
930 bool bFieldProcessed = false;
932 if( pInfo )
934 static const ::rtl::OUString aHeaderText( B2UCONST( "HeaderText" ) );
935 static const ::rtl::OUString aFooterText( B2UCONST( "FooterText" ) );
936 static const ::rtl::OUString aDateTimeText( B2UCONST( "DateTimeText" ) );
937 static const ::rtl::OUString aPageNumberText( B2UCONST( "Number" ) );
939 const Reference< XPropertySet > xDefaultPagePropertySet( mxDefaultPage, UNO_QUERY );
940 Reference< XPropertySetInfo > xDefaultPagePropSetInfo( xDefaultPagePropertySet->getPropertySetInfo() );
942 if( xDefaultPagePropSetInfo.is() )
944 const SvxFieldData* pField = pInfo->GetField().GetField();
945 Any aProperty;
947 if( pField->ISA( SvxHeaderField ) &&
948 xDefaultPagePropSetInfo->hasPropertyByName( aHeaderText ) )
950 xDefaultPagePropertySet->getPropertyValue( aHeaderText ) >>= aRepresentation;
951 bFieldProcessed = true;
953 else if( pField->ISA( SvxFooterField ) &&
954 xDefaultPagePropSetInfo->hasPropertyByName( aFooterText ) )
956 xDefaultPagePropertySet->getPropertyValue( aFooterText ) >>= aRepresentation;
957 bFieldProcessed = true;
959 else if( pField->ISA( SvxDateTimeField ) &&
960 xDefaultPagePropSetInfo->hasPropertyByName( aDateTimeText ) )
962 xDefaultPagePropertySet->getPropertyValue( aDateTimeText ) >>= aRepresentation;
963 bFieldProcessed = true;
965 else if( pField->ISA( SvxPageField ) &&
966 xDefaultPagePropSetInfo->hasPropertyByName( aPageNumberText ) )
968 String aPageNumValue;
969 sal_Int16 nPageNumber = 0;
971 xDefaultPagePropertySet->getPropertyValue( aPageNumberText ) >>= nPageNumber;
973 if( mpSdrModel )
975 bool bUpper = false;
977 switch( mpSdrModel->GetPageNumType() )
979 case SVX_CHARS_UPPER_LETTER:
980 aPageNumValue += (sal_Unicode)(char)( ( nPageNumber - 1 ) % 26 + 'A' );
981 break;
982 case SVX_CHARS_LOWER_LETTER:
983 aPageNumValue += (sal_Unicode)(char)( ( nPageNumber- 1 ) % 26 + 'a' );
984 break;
985 case SVX_ROMAN_UPPER:
986 bUpper = true;
987 case SVX_ROMAN_LOWER:
988 aPageNumValue += SvxNumberFormat::CreateRomanString( nPageNumber, bUpper );
989 break;
990 case SVX_NUMBER_NONE:
991 aPageNumValue.Erase();
992 aPageNumValue += sal_Unicode(' ');
993 break;
994 default : break;
998 if( !aPageNumValue.Len() )
999 aPageNumValue += String::CreateFromInt32( nPageNumber );
1001 aRepresentation = aPageNumValue;
1002 bFieldProcessed = true;
1006 pInfo->SetRepresentation( aRepresentation );
1009 return( bFieldProcessed ? 0 : maOldFieldHdl.Call( pInfo ) );