merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / svg / svgwriter.cxx
blob0a2ae22242ffe13ad9b1d7720f8268bfa3b8ec78
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
31 #include "svgwriter.hxx"
32 #include "svgaction.hxx"
33 #include <uno/mapping.hxx>
35 // ----------------
36 // - SVGMtfExport -
37 // ----------------
39 class SVGMtfExport : public SvXMLExport
41 private:
43 SVGMtfExport();
45 protected:
47 virtual void _ExportMeta() {}
48 virtual void _ExportStyles( BOOL /*bUsed*/ ) {}
49 virtual void _ExportAutoStyles() {}
50 virtual void _ExportContent() {}
51 virtual void _ExportMasterStyles() {}
52 virtual sal_uInt32 exportDoc( enum ::xmloff::token::XMLTokenEnum /*eClass*/ ) { return 0; }
54 public:
56 // #110680#
57 SVGMtfExport(
58 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
59 const REF( NMSP_SAX::XDocumentHandler )& rxHandler );
61 virtual ~SVGMtfExport();
63 virtual void writeMtf( const GDIMetaFile& rMtf );
66 // -----------------------------------------------------------------------------
68 // #110680#
69 SVGMtfExport::SVGMtfExport(
70 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
71 const REF( NMSP_SAX::XDocumentHandler )& rxHandler )
72 : SvXMLExport( xServiceFactory, NMSP_RTL::OUString(), rxHandler )
74 GetDocHandler()->startDocument();
77 // -----------------------------------------------------------------------------
79 SVGMtfExport::~SVGMtfExport()
81 GetDocHandler()->endDocument();
84 // -----------------------------------------------------------------------------
86 void SVGMtfExport::writeMtf( const GDIMetaFile& rMtf )
88 const Size aSize( OutputDevice::LogicToLogic( rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MAP_MM ) );
89 NMSP_RTL::OUString aAttr;
90 REF( NMSP_SAX::XExtendedDocumentHandler ) xExtDocHandler( GetDocHandler(), NMSP_UNO::UNO_QUERY );
92 if( xExtDocHandler.is() )
93 xExtDocHandler->unknown( SVG_DTD_STRING );
95 aAttr = NMSP_RTL::OUString::valueOf( aSize.Width() );
96 aAttr += B2UCONST( "mm" );
97 AddAttribute( XML_NAMESPACE_NONE, "width", aAttr );
99 aAttr = NMSP_RTL::OUString::valueOf( aSize.Height() );
100 aAttr += B2UCONST( "mm" );
101 AddAttribute( XML_NAMESPACE_NONE, "height", aAttr );
103 aAttr = B2UCONST( "0 0 " );
104 aAttr += NMSP_RTL::OUString::valueOf( aSize.Width() * 100L );
105 aAttr += B2UCONST( " " );
106 aAttr += NMSP_RTL::OUString::valueOf( aSize.Height() * 100L );
107 AddAttribute( XML_NAMESPACE_NONE, "viewBox", aAttr );
110 SvXMLElementExport aSVG( *this, XML_NAMESPACE_NONE, "svg", TRUE, TRUE );
111 SVGActionWriter* pWriter = new SVGActionWriter( *this, rMtf );
113 delete pWriter;
117 // -------------
118 // - SVGWriter -
119 // -------------
121 SVGWriter::SVGWriter( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr ) :
122 mxFact( rxMgr )
126 // -----------------------------------------------------------------------------
128 SVGWriter::~SVGWriter()
132 // -----------------------------------------------------------------------------
135 ANY SAL_CALL SVGWriter::queryInterface( const NMSP_UNO::Type & rType ) throw( NMSP_UNO::RuntimeException )
137 const ANY aRet( NMSP_CPPU::queryInterface( rType, static_cast< NMSP_SVG::XSVGWriter* >( this ) ) );
139 return( aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ) );
142 // -----------------------------------------------------------------------------
144 void SAL_CALL SVGWriter::acquire() throw()
146 OWeakObject::acquire();
149 // -----------------------------------------------------------------------------
151 void SAL_CALL SVGWriter::release() throw()
153 OWeakObject::release();
156 // -----------------------------------------------------------------------------
158 void SAL_CALL SVGWriter::write( const REF( NMSP_SAX::XDocumentHandler )& rxDocHandler,
159 const SEQ( sal_Int8 )& rMtfSeq ) throw( NMSP_UNO::RuntimeException )
161 SvMemoryStream aMemStm( (char*) rMtfSeq.getConstArray(), rMtfSeq.getLength(), STREAM_READ );
162 GDIMetaFile aMtf;
164 aMemStm.SetCompressMode( COMPRESSMODE_FULL );
165 aMemStm >> aMtf;
167 const REF( NMSP_SAX::XDocumentHandler ) xDocumentHandler( rxDocHandler );
169 // #110680#
170 // SVGMtfExport* pWriter = new SVGMtfExport( xDocumentHandler );
171 SVGMtfExport* pWriter = new SVGMtfExport( mxFact, xDocumentHandler );
173 pWriter->writeMtf( aMtf );
174 delete pWriter;