1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svgexport.cxx,v $
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
;
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() :
78 // -----------------------------------------------------------------------------
80 ObjectRepresentation::ObjectRepresentation( const Reference
< XInterface
>& rxObject
,
81 const GDIMetaFile
& rMtf
) :
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()
102 // -----------------------------------------------------------------------------
104 ObjectRepresentation
& ObjectRepresentation::operator=( const ObjectRepresentation
& rPresentation
)
106 mxObject
= rPresentation
.mxObject
;
107 delete mpMtf
, ( mpMtf
= rPresentation
.mpMtf
? new GDIMetaFile( *rPresentation
.mpMtf
) : NULL
);
112 // -----------------------------------------------------------------------------
114 bool ObjectRepresentation::operator==( const ObjectRepresentation
& rPresentation
) const
116 return( ( mxObject
== rPresentation
.mxObject
) &&
117 ( *mpMtf
== *rPresentation
.mpMtf
) );
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
);
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
;
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
);
192 mpDefaultSdrPage
= pSvxDrawPage
->GetSdrPage();
193 mpSdrModel
= mpDefaultSdrPage
->GetModel();
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() );
210 while( aIter
!= mpObjects
->end() )
212 aObjects
[ nPos
++ ] = (*aIter
).second
;
216 mpSVGFontExport
= new SVGFontExport( *mpSVGExport
, aObjects
);
217 mpSVGWriter
= new SVGActionWriter( *mpSVGExport
, *mpSVGFontExport
);
219 bRet
= implExportDocument( xMasterPages
, xDrawPages
, nPageToExport
);
225 delete mpSVGDoc
, mpSVGDoc
= NULL
;
226 DBG_ERROR( "Exception caught" );
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
;
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
);
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" );
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
);
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" ) );
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
;
342 Reference
< XPropertySet
> xPropSet( xDrawPage
, UNO_QUERY
);
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() );
359 for( sal_Int32 nMaster
= 0, nMasterCount
= rxMasterPages
->getCount();
360 ( nMaster
< nMasterCount
) && ( -1 == nVisibleMaster
);
363 Reference
< XDrawPage
> xMasterTestPage
;
365 rxMasterPages
->getByIndex( nMaster
) >>= xMasterTestPage
;
367 if( xMasterTestPage
== xMasterPage
)
368 nVisibleMaster
= nMaster
;
378 #ifdef _SVG_EMBED_FONTS
379 mpSVGFontExport
->EmbedFonts();
385 implExportPages( rxMasterPages
, nVisibleMaster
, nVisibleMaster
, nVisibleMaster
, sal_True
);
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
;
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
);
431 Reference
< XPropertySet
> xPropSet( xDrawPage
, UNO_QUERY
);
434 xPropSet
->getPropertyValue( B2UCONST( "Background" ) ) >>= bMasterVisible
;
438 aMasterVisibility
= B2UCONST( "visible" );
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
);
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
) );
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
;
500 Reference
< XShapes
> xShapes( xDrawPage
, UNO_QUERY
);
506 if( i
== nVisiblePage
)
507 aAttr
= B2UCONST( "visible" );
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
);
519 Reference
< XExtendedDocumentHandler
> xExtDocHandler( mpSVGExport
->GetDocHandler(), UNO_QUERY
);
521 if( xExtDocHandler
.is() )
523 SvXMLElementExport
aExp2( *mpSVGExport
, XML_NAMESPACE_NONE
, "desc", TRUE
, TRUE
);
527 aDesc
= B2UCONST( "Master slide" );
529 aDesc
= B2UCONST( "Slide" );
531 xExtDocHandler
->unknown( aDesc
);
537 const GDIMetaFile
& rMtf
= (*mpObjects
)[ xDrawPage
].GetRepresentation();
538 mpSVGWriter
->WriteMetaFile( aNullPt
, rMtf
.GetPrefSize(), rMtf
, SVGWRITER_WRITE_FILL
);
541 bRet
= implExportShapes( xShapes
) || 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
;
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;
582 xShapePropSet
->getPropertyValue( B2UCONST( "IsEmptyPresentationObject" ) ) >>= 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" ) );
597 bool bValue
= sal_False
;
599 if( ( aShapeType
.lastIndexOf( B2UCONST( "presentation.HeaderShape" ) ) != -1 ) &&
600 xPagePropSetInfo
->hasPropertyByName( aHeaderString
) &&
601 ( ( aProperty
= xDefaultPagePropertySet
->getPropertyValue( aHeaderString
) ) >>= bValue
) &&
606 else if( ( aShapeType
.lastIndexOf( B2UCONST( "presentation.FooterShape" ) ) != -1 ) &&
607 xPagePropSetInfo
->hasPropertyByName( aFooterString
) &&
608 ( ( aProperty
= xDefaultPagePropertySet
->getPropertyValue( aFooterString
) ) >>= bValue
) &&
613 else if( ( aShapeType
.lastIndexOf( B2UCONST( "presentation.DateTimeShape" ) ) != -1 ) &&
614 xPagePropSetInfo
->hasPropertyByName( aDateTimeString
) &&
615 ( ( aProperty
= xDefaultPagePropertySet
->getPropertyValue( aDateTimeString
) ) >>= bValue
) &&
620 else if( ( aShapeType
.lastIndexOf( B2UCONST( "presentation.SlideNumberShape" ) ) != -1 ) &&
621 xPagePropSetInfo
->hasPropertyByName( aPageNumberString
) &&
622 ( ( aProperty
= xDefaultPagePropertySet
->getPropertyValue( aPageNumberString
) ) >>= bValue
) &&
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
);
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
);
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
);
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
);
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
)
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
);
729 implCreateObjectsFromShapes( xShapes
);
733 for( i
= 0, nCount
= rxDrawPages
->getCount(); i
< nCount
; ++i
)
735 Reference
< XDrawPage
> xDrawPage
;
737 rxDrawPages
->getByIndex( i
) >>= xDrawPage
;
741 Reference
< XShapes
> xShapes( xDrawPage
, UNO_QUERY
);
744 implCreateObjectsFromShapes( xShapes
);
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
;
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
);
772 implCreateObjectsFromShapes( xShapes
);
776 Reference
< XShapes
> xShapes( xDrawPage
, UNO_QUERY
);
779 implCreateObjectsFromShapes( xShapes
);
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
;
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
);
815 bRet
= implCreateObjectsFromShapes( xShapes
);
819 SdrObject
* pObj
= GetSdrObjectFromXShape( rxShape
);
823 Graphic
aGraphic( SdrExchangeView::GetObjGraphic( pObj
->GetModel(), pObj
) );
825 if( aGraphic
.GetType() != GRAPHIC_NONE
)
827 if( aGraphic
.GetType() == GRAPHIC_BITMAP
)
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
);
840 (*mpObjects
)[ rxShape
] = ObjectRepresentation( rxShape
, aGraphic
.GetGDIMetaFile() );
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
;
860 Reference
< XFilter
> xFilter( xExporter
, UNO_QUERY
);
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
);
885 // -----------------------------------------------------------------------------
887 OUString
SVGFilter::implGetDescriptionFromShape( const Reference
< XShape
>& rxShape
)
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" );
907 aRet
= B2UCONST( "Drawing" );
912 // -----------------------------------------------------------------------------
914 OUString
SVGFilter::implGetValidIDFromInterface( const Reference
< XInterface
>& rxIf
)
916 Reference
< XNamed
> xNamed( rxIf
, UNO_QUERY
);
920 aRet
= xNamed
->getName().replace( ' ', '_' );
925 // -----------------------------------------------------------------------------
927 IMPL_LINK( SVGFilter
, CalcFieldHdl
, EditFieldInfo
*, pInfo
)
929 OUString aRepresentation
;
930 bool bFieldProcessed
= false;
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();
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
;
977 switch( mpSdrModel
->GetPageNumType() )
979 case SVX_CHARS_UPPER_LETTER
:
980 aPageNumValue
+= (sal_Unicode
)(char)( ( nPageNumber
- 1 ) % 26 + 'A' );
982 case SVX_CHARS_LOWER_LETTER
:
983 aPageNumValue
+= (sal_Unicode
)(char)( ( nPageNumber
- 1 ) % 26 + 'a' );
985 case SVX_ROMAN_UPPER
:
987 case SVX_ROMAN_LOWER
:
988 aPageNumValue
+= SvxNumberFormat::CreateRomanString( nPageNumber
, bUpper
);
990 case SVX_NUMBER_NONE
:
991 aPageNumValue
.Erase();
992 aPageNumValue
+= sal_Unicode(' ');
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
) );