update dev300-m58
[ooovba.git] / extensions / source / svg / svgwriter.cxx
blobb59b1926ee53a0b810ec09d173710c74e3c9808f
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: svgwriter.cxx,v $
10 * $Revision: 1.10 $
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_extensions.hxx"
34 #include "svgwriter.hxx"
35 #include "svgaction.hxx"
36 #include <uno/mapping.hxx>
38 // ----------------
39 // - SVGMtfExport -
40 // ----------------
42 class SVGMtfExport : public SvXMLExport
44 private:
46 SVGMtfExport();
48 protected:
50 virtual void _ExportMeta() {}
51 virtual void _ExportStyles( BOOL /*bUsed*/ ) {}
52 virtual void _ExportAutoStyles() {}
53 virtual void _ExportContent() {}
54 virtual void _ExportMasterStyles() {}
55 virtual sal_uInt32 exportDoc( enum ::xmloff::token::XMLTokenEnum /*eClass*/ ) { return 0; }
57 public:
59 // #110680#
60 SVGMtfExport(
61 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
62 const REF( NMSP_SAX::XDocumentHandler )& rxHandler );
64 virtual ~SVGMtfExport();
66 virtual void writeMtf( const GDIMetaFile& rMtf );
69 // -----------------------------------------------------------------------------
71 // #110680#
72 SVGMtfExport::SVGMtfExport(
73 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
74 const REF( NMSP_SAX::XDocumentHandler )& rxHandler )
75 : SvXMLExport( xServiceFactory, NMSP_RTL::OUString(), rxHandler )
77 GetDocHandler()->startDocument();
80 // -----------------------------------------------------------------------------
82 SVGMtfExport::~SVGMtfExport()
84 GetDocHandler()->endDocument();
87 // -----------------------------------------------------------------------------
89 void SVGMtfExport::writeMtf( const GDIMetaFile& rMtf )
91 const Size aSize( OutputDevice::LogicToLogic( rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MAP_MM ) );
92 NMSP_RTL::OUString aAttr;
93 REF( NMSP_SAX::XExtendedDocumentHandler ) xExtDocHandler( GetDocHandler(), NMSP_UNO::UNO_QUERY );
95 if( xExtDocHandler.is() )
96 xExtDocHandler->unknown( SVG_DTD_STRING );
98 aAttr = NMSP_RTL::OUString::valueOf( aSize.Width() );
99 aAttr += B2UCONST( "mm" );
100 AddAttribute( XML_NAMESPACE_NONE, "width", aAttr );
102 aAttr = NMSP_RTL::OUString::valueOf( aSize.Height() );
103 aAttr += B2UCONST( "mm" );
104 AddAttribute( XML_NAMESPACE_NONE, "height", aAttr );
106 aAttr = B2UCONST( "0 0 " );
107 aAttr += NMSP_RTL::OUString::valueOf( aSize.Width() * 100L );
108 aAttr += B2UCONST( " " );
109 aAttr += NMSP_RTL::OUString::valueOf( aSize.Height() * 100L );
110 AddAttribute( XML_NAMESPACE_NONE, "viewBox", aAttr );
113 SvXMLElementExport aSVG( *this, XML_NAMESPACE_NONE, "svg", TRUE, TRUE );
114 SVGActionWriter* pWriter = new SVGActionWriter( *this, rMtf );
116 delete pWriter;
120 // -------------
121 // - SVGWriter -
122 // -------------
124 SVGWriter::SVGWriter( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr ) :
125 mxFact( rxMgr )
129 // -----------------------------------------------------------------------------
131 SVGWriter::~SVGWriter()
135 // -----------------------------------------------------------------------------
138 ANY SAL_CALL SVGWriter::queryInterface( const NMSP_UNO::Type & rType ) throw( NMSP_UNO::RuntimeException )
140 const ANY aRet( NMSP_CPPU::queryInterface( rType, static_cast< NMSP_SVG::XSVGWriter* >( this ) ) );
142 return( aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ) );
145 // -----------------------------------------------------------------------------
147 void SAL_CALL SVGWriter::acquire() throw()
149 OWeakObject::acquire();
152 // -----------------------------------------------------------------------------
154 void SAL_CALL SVGWriter::release() throw()
156 OWeakObject::release();
159 // -----------------------------------------------------------------------------
161 void SAL_CALL SVGWriter::write( const REF( NMSP_SAX::XDocumentHandler )& rxDocHandler,
162 const SEQ( sal_Int8 )& rMtfSeq ) throw( NMSP_UNO::RuntimeException )
164 SvMemoryStream aMemStm( (char*) rMtfSeq.getConstArray(), rMtfSeq.getLength(), STREAM_READ );
165 GDIMetaFile aMtf;
167 aMemStm.SetCompressMode( COMPRESSMODE_FULL );
168 aMemStm >> aMtf;
170 const REF( NMSP_SAX::XDocumentHandler ) xDocumentHandler( rxDocHandler );
172 // #110680#
173 // SVGMtfExport* pWriter = new SVGMtfExport( xDocumentHandler );
174 SVGMtfExport* pWriter = new SVGMtfExport( mxFact, xDocumentHandler );
176 pWriter->writeMtf( aMtf );
177 delete pWriter;