15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file
55900e8ecSAndrew Rist * distributed with this work for additional information
65900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file
75900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
135900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist * software distributed under the License is distributed on an
155900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist * KIND, either express or implied. See the License for the
175900e8ecSAndrew Rist * specific language governing permissions and limitations
185900e8ecSAndrew Rist * under the License.
19cdf0e10cSrcweir *
205900e8ecSAndrew Rist *************************************************************/
215900e8ecSAndrew Rist
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svtools.hxx"
24cdf0e10cSrcweir
25cdf0e10cSrcweir #include <rtl/uuid.h>
26cdf0e10cSrcweir #include <vos/mutex.hxx>
27cdf0e10cSrcweir #include <vcl/svapp.hxx>
28cdf0e10cSrcweir #include <vcl/image.hxx>
29cdf0e10cSrcweir #include <vcl/metaact.hxx>
30cdf0e10cSrcweir #include <vcl/msgbox.hxx>
31cdf0e10cSrcweir #include <vcl/imagerepository.hxx>
32cdf0e10cSrcweir #include <tools/rcid.h>
33cdf0e10cSrcweir #include <tools/resid.hxx>
34cdf0e10cSrcweir #include <tools/resmgr.hxx>
35cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
36cdf0e10cSrcweir #include <svtools/filter.hxx>
37cdf0e10cSrcweir #include <svl/solar.hrc>
38cdf0e10cSrcweir #include <vcl/salbtype.hxx>
39cdf0e10cSrcweir #include <vcl/virdev.hxx>
40cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
41cdf0e10cSrcweir #include <com/sun/star/text/GraphicCrop.hpp>
42cdf0e10cSrcweir #include "descriptor.hxx"
43cdf0e10cSrcweir #include "graphic.hxx"
44cdf0e10cSrcweir #include <svtools/grfmgr.hxx>
45cdf0e10cSrcweir #include "provider.hxx"
46*45fd3b9aSArmin Le Grand #include <vcl/dibtools.hxx>
47cdf0e10cSrcweir
48cdf0e10cSrcweir using namespace com::sun::star;
49cdf0e10cSrcweir
50cdf0e10cSrcweir namespace unographic {
51cdf0e10cSrcweir
52cdf0e10cSrcweir #define UNO_NAME_GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:"
53cdf0e10cSrcweir
54cdf0e10cSrcweir // -------------------
55cdf0e10cSrcweir // - GraphicProvider -
56cdf0e10cSrcweir // -------------------
57cdf0e10cSrcweir
GraphicProvider_CreateInstance(const uno::Reference<lang::XMultiServiceFactory> &)58cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL GraphicProvider_CreateInstance( const uno::Reference< lang::XMultiServiceFactory >& )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir return SAL_STATIC_CAST( ::cppu::OWeakObject*, new GraphicProvider );
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
GraphicProvider()63cdf0e10cSrcweir GraphicProvider::GraphicProvider()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir // ------------------------------------------------------------------------------
68cdf0e10cSrcweir
~GraphicProvider()69cdf0e10cSrcweir GraphicProvider::~GraphicProvider()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
73cdf0e10cSrcweir // ------------------------------------------------------------------------------
74cdf0e10cSrcweir
getImplementationName_Static()75cdf0e10cSrcweir ::rtl::OUString GraphicProvider::getImplementationName_Static()
76cdf0e10cSrcweir throw()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.GraphicProvider" ) );
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
81cdf0e10cSrcweir // ------------------------------------------------------------------------------
82cdf0e10cSrcweir
getSupportedServiceNames_Static()83cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > GraphicProvider::getSupportedServiceNames_Static()
84cdf0e10cSrcweir throw()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSeq( 1 );
87cdf0e10cSrcweir
88cdf0e10cSrcweir aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicProvider" ) );
89cdf0e10cSrcweir
90cdf0e10cSrcweir return aSeq;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
93cdf0e10cSrcweir // ------------------------------------------------------------------------------
94cdf0e10cSrcweir
getImplementationName()95cdf0e10cSrcweir ::rtl::OUString SAL_CALL GraphicProvider::getImplementationName()
96cdf0e10cSrcweir throw( uno::RuntimeException )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir return getImplementationName_Static();
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
101cdf0e10cSrcweir // ------------------------------------------------------------------------------
102cdf0e10cSrcweir
supportsService(const::rtl::OUString & ServiceName)103cdf0e10cSrcweir sal_Bool SAL_CALL GraphicProvider::supportsService( const ::rtl::OUString& ServiceName )
104cdf0e10cSrcweir throw( uno::RuntimeException )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
107cdf0e10cSrcweir const ::rtl::OUString* pArray = aSNL.getConstArray();
108cdf0e10cSrcweir
109cdf0e10cSrcweir for( int i = 0; i < aSNL.getLength(); i++ )
110cdf0e10cSrcweir if( pArray[i] == ServiceName )
111cdf0e10cSrcweir return true;
112cdf0e10cSrcweir
113cdf0e10cSrcweir return false;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir // ------------------------------------------------------------------------------
117cdf0e10cSrcweir
getSupportedServiceNames()118cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL GraphicProvider::getSupportedServiceNames()
119cdf0e10cSrcweir throw( uno::RuntimeException )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir return getSupportedServiceNames_Static();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir // ------------------------------------------------------------------------------
125cdf0e10cSrcweir
getTypes()126cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL GraphicProvider::getTypes()
127cdf0e10cSrcweir throw(uno::RuntimeException)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir uno::Sequence< uno::Type > aTypes( 3 );
130cdf0e10cSrcweir uno::Type* pTypes = aTypes.getArray();
131cdf0e10cSrcweir
132cdf0e10cSrcweir *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
133cdf0e10cSrcweir *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
134cdf0e10cSrcweir *pTypes++ = ::getCppuType((const uno::Reference< graphic::XGraphicProvider>*)0);
135cdf0e10cSrcweir
136cdf0e10cSrcweir return aTypes;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir // ------------------------------------------------------------------------------
140cdf0e10cSrcweir
getImplementationId()141cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL GraphicProvider::getImplementationId()
142cdf0e10cSrcweir throw(uno::RuntimeException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() );
145cdf0e10cSrcweir static uno::Sequence< sal_Int8 > aId;
146cdf0e10cSrcweir
147cdf0e10cSrcweir if( aId.getLength() == 0 )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir aId.realloc( 16 );
150cdf0e10cSrcweir rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True );
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
153cdf0e10cSrcweir return aId;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir // ------------------------------------------------------------------------------
157cdf0e10cSrcweir
implLoadGraphicObject(const::rtl::OUString & rResourceURL) const158cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadGraphicObject( const ::rtl::OUString& rResourceURL ) const
159cdf0e10cSrcweir {
160cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > xRet;
161cdf0e10cSrcweir if( rResourceURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPREFIX ) ) == 0 )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir // graphic manager url
164cdf0e10cSrcweir String aTmpStr( rResourceURL.copy( sizeof( UNO_NAME_GRAPHOBJ_URLPREFIX ) - 1 ) );
165cdf0e10cSrcweir ByteString aUniqueID( aTmpStr, RTL_TEXTENCODING_UTF8 );
166cdf0e10cSrcweir GraphicObject aGrafObj( aUniqueID );
167cdf0e10cSrcweir // I don't call aGrafObj.GetXGraphic because it will call us back
168cdf0e10cSrcweir // into implLoadMemory ( with "private:memorygraphic" test )
169cdf0e10cSrcweir ::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic;
170cdf0e10cSrcweir pUnoGraphic->init( aGrafObj.GetGraphic() );
171cdf0e10cSrcweir xRet = pUnoGraphic;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir return xRet;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
implLoadMemory(const::rtl::OUString & rResourceURL) const176cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadMemory( const ::rtl::OUString& rResourceURL ) const
177cdf0e10cSrcweir {
178cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > xRet;
179cdf0e10cSrcweir sal_Int32 nIndex = 0;
180cdf0e10cSrcweir
181cdf0e10cSrcweir if( ( 0 == rResourceURL.getToken( 0, '/', nIndex ).compareToAscii( "private:memorygraphic" ) ) )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir sal_Int64 nGraphicAddress = rResourceURL.getToken( 0, '/', nIndex ).toInt64();
184cdf0e10cSrcweir
185cdf0e10cSrcweir if( nGraphicAddress )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir ::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic;
188cdf0e10cSrcweir
189cdf0e10cSrcweir pUnoGraphic->init( *reinterpret_cast< ::Graphic* >( nGraphicAddress ) );
190cdf0e10cSrcweir xRet = pUnoGraphic;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
194cdf0e10cSrcweir return xRet;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
197cdf0e10cSrcweir // ------------------------------------------------------------------------------
198cdf0e10cSrcweir
implLoadRepositoryImage(const::rtl::OUString & rResourceURL) const199cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadRepositoryImage( const ::rtl::OUString& rResourceURL ) const
200cdf0e10cSrcweir {
201cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > xRet;
202cdf0e10cSrcweir sal_Int32 nIndex = 0;
203cdf0e10cSrcweir
204cdf0e10cSrcweir if( ( 0 == rResourceURL.getToken( 0, '/', nIndex ).compareToAscii( "private:graphicrepository" ) ) )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir String sPathName( rResourceURL.copy( nIndex ) );
207cdf0e10cSrcweir BitmapEx aBitmap;
208cdf0e10cSrcweir if ( ::vcl::ImageRepository::loadImage( sPathName, aBitmap, false ) )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir Image aImage( aBitmap );
211cdf0e10cSrcweir xRet = aImage.GetXGraphic();
212cdf0e10cSrcweir }
213cdf0e10cSrcweir }
214cdf0e10cSrcweir return xRet;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
217cdf0e10cSrcweir
218cdf0e10cSrcweir // ------------------------------------------------------------------------------
219cdf0e10cSrcweir
implLoadStandardImage(const::rtl::OUString & rResourceURL) const220cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadStandardImage( const ::rtl::OUString& rResourceURL ) const
221cdf0e10cSrcweir {
222cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > xRet;
223cdf0e10cSrcweir sal_Int32 nIndex = 0;
224cdf0e10cSrcweir
225cdf0e10cSrcweir if( ( 0 == rResourceURL.getToken( 0, '/', nIndex ).compareToAscii( "private:standardimage" ) ) )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir rtl::OUString sImageName( rResourceURL.copy( nIndex ) );
228cdf0e10cSrcweir if ( sImageName.equalsAscii( "info" ) )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir xRet = InfoBox::GetStandardImage().GetXGraphic();
231cdf0e10cSrcweir }
232cdf0e10cSrcweir else if ( sImageName.equalsAscii( "warning" ) )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir xRet = WarningBox::GetStandardImage().GetXGraphic();
235cdf0e10cSrcweir }
236cdf0e10cSrcweir else if ( sImageName.equalsAscii( "error" ) )
237cdf0e10cSrcweir {
238cdf0e10cSrcweir xRet = ErrorBox::GetStandardImage().GetXGraphic();
239cdf0e10cSrcweir }
240cdf0e10cSrcweir else if ( sImageName.equalsAscii( "query" ) )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir xRet = QueryBox::GetStandardImage().GetXGraphic();
243cdf0e10cSrcweir }
244cdf0e10cSrcweir }
245cdf0e10cSrcweir return xRet;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
248cdf0e10cSrcweir // ------------------------------------------------------------------------------
249cdf0e10cSrcweir
implLoadBitmap(const uno::Reference<awt::XBitmap> & xBtm) const250cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadBitmap( const uno::Reference< awt::XBitmap >& xBtm ) const
251cdf0e10cSrcweir {
252cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > xRet;
253cdf0e10cSrcweir uno::Sequence< sal_Int8 > aBmpSeq( xBtm->getDIB() );
254cdf0e10cSrcweir uno::Sequence< sal_Int8 > aMaskSeq( xBtm->getMaskDIB() );
255cdf0e10cSrcweir SvMemoryStream aBmpStream( aBmpSeq.getArray(), aBmpSeq.getLength(), STREAM_READ );
256cdf0e10cSrcweir Bitmap aBmp;
257cdf0e10cSrcweir BitmapEx aBmpEx;
258cdf0e10cSrcweir
259*45fd3b9aSArmin Le Grand ReadDIB(aBmp, aBmpStream, true);
260*45fd3b9aSArmin Le Grand
261cdf0e10cSrcweir if( aMaskSeq.getLength() )
262cdf0e10cSrcweir {
263cdf0e10cSrcweir SvMemoryStream aMaskStream( aMaskSeq.getArray(), aMaskSeq.getLength(), STREAM_READ );
264cdf0e10cSrcweir Bitmap aMask;
265*45fd3b9aSArmin Le Grand
266*45fd3b9aSArmin Le Grand ReadDIB(aMask, aMaskStream, true);
267cdf0e10cSrcweir aBmpEx = BitmapEx( aBmp, aMask );
268cdf0e10cSrcweir }
269cdf0e10cSrcweir else
270cdf0e10cSrcweir aBmpEx = BitmapEx( aBmp );
271cdf0e10cSrcweir
272cdf0e10cSrcweir if( !aBmpEx.IsEmpty() )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir ::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic;
275cdf0e10cSrcweir
276cdf0e10cSrcweir pUnoGraphic->init( aBmpEx );
277cdf0e10cSrcweir xRet = pUnoGraphic;
278cdf0e10cSrcweir }
279cdf0e10cSrcweir return xRet;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir
282cdf0e10cSrcweir // ------------------------------------------------------------------------------
283cdf0e10cSrcweir
implLoadResource(const::rtl::OUString & rResourceURL) const284cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadResource( const ::rtl::OUString& rResourceURL ) const
285cdf0e10cSrcweir {
286cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > xRet;
287cdf0e10cSrcweir sal_Int32 nIndex = 0;
288cdf0e10cSrcweir
289cdf0e10cSrcweir if( ( 0 == rResourceURL.getToken( 0, '/', nIndex ).compareToAscii( "private:resource" ) ) )
290cdf0e10cSrcweir {
291cdf0e10cSrcweir ByteString aResMgrName( String( rResourceURL.getToken( 0, '/', nIndex ) ), RTL_TEXTENCODING_ASCII_US );
292cdf0e10cSrcweir
293cdf0e10cSrcweir ResMgr* pResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() );
294cdf0e10cSrcweir
295cdf0e10cSrcweir if( pResMgr )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir const ::rtl::OUString aResourceType( rResourceURL.getToken( 0, '/', nIndex ) );
298cdf0e10cSrcweir const ResId aResId( rResourceURL.getToken( 0, '/', nIndex ).toInt32(), *pResMgr );
299cdf0e10cSrcweir
300cdf0e10cSrcweir if( aResourceType.getLength() )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir BitmapEx aBmpEx;
303cdf0e10cSrcweir
304cdf0e10cSrcweir if( ( 0 == aResourceType.compareToAscii( "bitmap" ) ) ||
305cdf0e10cSrcweir ( 0 == aResourceType.compareToAscii( "bitmapex" ) ) )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir aResId.SetRT( RSC_BITMAP );
308cdf0e10cSrcweir
309cdf0e10cSrcweir if( pResMgr->IsAvailable( aResId ) )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir aBmpEx = BitmapEx( aResId );
312cdf0e10cSrcweir }
313cdf0e10cSrcweir }
314cdf0e10cSrcweir else if( 0 == aResourceType.compareToAscii( "image" ) )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir aResId.SetRT( RSC_IMAGE );
317cdf0e10cSrcweir
318cdf0e10cSrcweir if( pResMgr->IsAvailable( aResId ) )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir const Image aImage( aResId );
321cdf0e10cSrcweir aBmpEx = aImage.GetBitmapEx();
322cdf0e10cSrcweir }
323cdf0e10cSrcweir }
324cdf0e10cSrcweir else if( 0 == aResourceType.compareToAscii( "imagelist" ) )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir aResId.SetRT( RSC_IMAGELIST );
327cdf0e10cSrcweir
328cdf0e10cSrcweir if( pResMgr->IsAvailable( aResId ) )
329cdf0e10cSrcweir {
330cdf0e10cSrcweir const ImageList aImageList( aResId );
331cdf0e10cSrcweir sal_Int32 nImageId = ( nIndex > -1 ) ? rResourceURL.getToken( 0, '/', nIndex ).toInt32() : 0;
332cdf0e10cSrcweir
333cdf0e10cSrcweir if( 0 < nImageId )
334cdf0e10cSrcweir {
335cdf0e10cSrcweir const Image aImage( aImageList.GetImage( sal::static_int_cast< sal_uInt16 >(nImageId) ) );
336cdf0e10cSrcweir aBmpEx = aImage.GetBitmapEx();
337cdf0e10cSrcweir }
338cdf0e10cSrcweir else
339cdf0e10cSrcweir {
340cdf0e10cSrcweir aBmpEx = aImageList.GetAsHorizontalStrip();
341cdf0e10cSrcweir }
342cdf0e10cSrcweir }
343cdf0e10cSrcweir }
344cdf0e10cSrcweir
345cdf0e10cSrcweir if( !aBmpEx.IsEmpty() )
346cdf0e10cSrcweir {
347cdf0e10cSrcweir ::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic;
348cdf0e10cSrcweir
349cdf0e10cSrcweir pUnoGraphic->init( aBmpEx );
350cdf0e10cSrcweir xRet = pUnoGraphic;
351cdf0e10cSrcweir }
352cdf0e10cSrcweir }
353cdf0e10cSrcweir
354cdf0e10cSrcweir delete pResMgr;
355cdf0e10cSrcweir }
356cdf0e10cSrcweir }
357cdf0e10cSrcweir
358cdf0e10cSrcweir return xRet;
359cdf0e10cSrcweir }
360cdf0e10cSrcweir
361cdf0e10cSrcweir // ------------------------------------------------------------------------------
362cdf0e10cSrcweir
queryGraphicDescriptor(const uno::Sequence<beans::PropertyValue> & rMediaProperties)363cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL GraphicProvider::queryGraphicDescriptor( const uno::Sequence< beans::PropertyValue >& rMediaProperties )
364cdf0e10cSrcweir throw ( io::IOException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
365cdf0e10cSrcweir {
366cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xRet;
367cdf0e10cSrcweir
368cdf0e10cSrcweir ::rtl::OUString aURL;
369cdf0e10cSrcweir uno::Reference< io::XInputStream > xIStm;
370cdf0e10cSrcweir uno::Reference< awt::XBitmap >xBtm;
371cdf0e10cSrcweir
372cdf0e10cSrcweir for( sal_Int32 i = 0; ( i < rMediaProperties.getLength() ) && !xRet.is(); ++i )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir const ::rtl::OUString aName( rMediaProperties[ i ].Name );
375cdf0e10cSrcweir const uno::Any aValue( rMediaProperties[ i ].Value );
376cdf0e10cSrcweir
377cdf0e10cSrcweir if( COMPARE_EQUAL == aName.compareToAscii( "URL" ) )
378cdf0e10cSrcweir {
379cdf0e10cSrcweir aValue >>= aURL;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir else if( COMPARE_EQUAL == aName.compareToAscii( "InputStream" ) )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir aValue >>= xIStm;
384cdf0e10cSrcweir }
385cdf0e10cSrcweir else if( COMPARE_EQUAL == aName.compareToAscii( "Bitmap" ) )
386cdf0e10cSrcweir {
387cdf0e10cSrcweir aValue >>= xBtm;
388cdf0e10cSrcweir }
389cdf0e10cSrcweir }
390cdf0e10cSrcweir
391cdf0e10cSrcweir if( xIStm.is() )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir GraphicDescriptor* pDescriptor = new GraphicDescriptor;
394cdf0e10cSrcweir pDescriptor->init( xIStm, aURL );
395cdf0e10cSrcweir xRet = pDescriptor;
396cdf0e10cSrcweir }
397cdf0e10cSrcweir else if( aURL.getLength() )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > xGraphic( implLoadMemory( aURL ) );
400cdf0e10cSrcweir if( !xGraphic.is() )
401cdf0e10cSrcweir xGraphic = implLoadResource( aURL );
402cdf0e10cSrcweir if( !xGraphic.is() )
403cdf0e10cSrcweir xGraphic = implLoadGraphicObject( aURL );
404cdf0e10cSrcweir
405cdf0e10cSrcweir if ( !xGraphic.is() )
406cdf0e10cSrcweir xGraphic = implLoadRepositoryImage( aURL );
407cdf0e10cSrcweir
408cdf0e10cSrcweir if ( !xGraphic.is() )
409cdf0e10cSrcweir xGraphic = implLoadStandardImage( aURL );
410cdf0e10cSrcweir
411cdf0e10cSrcweir if( xGraphic.is() )
412cdf0e10cSrcweir {
413cdf0e10cSrcweir xRet = uno::Reference< beans::XPropertySet >( xGraphic, uno::UNO_QUERY );
414cdf0e10cSrcweir }
415cdf0e10cSrcweir else
416cdf0e10cSrcweir {
417cdf0e10cSrcweir GraphicDescriptor* pDescriptor = new GraphicDescriptor;
418cdf0e10cSrcweir pDescriptor->init( aURL );
419cdf0e10cSrcweir xRet = pDescriptor;
420cdf0e10cSrcweir }
421cdf0e10cSrcweir }
422cdf0e10cSrcweir else if( xBtm.is() )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > xGraphic( implLoadBitmap( xBtm ) );
425cdf0e10cSrcweir if( xGraphic.is() )
426cdf0e10cSrcweir xRet = uno::Reference< beans::XPropertySet >( xGraphic, uno::UNO_QUERY );
427cdf0e10cSrcweir }
428cdf0e10cSrcweir
429cdf0e10cSrcweir return xRet;
430cdf0e10cSrcweir }
431cdf0e10cSrcweir
432cdf0e10cSrcweir // ------------------------------------------------------------------------------
433cdf0e10cSrcweir
queryGraphic(const uno::Sequence<::beans::PropertyValue> & rMediaProperties)434cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( const uno::Sequence< ::beans::PropertyValue >& rMediaProperties )
435cdf0e10cSrcweir throw ( io::IOException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
436cdf0e10cSrcweir {
437cdf0e10cSrcweir uno::Reference< ::graphic::XGraphic > xRet;
438cdf0e10cSrcweir String aPath;
439cdf0e10cSrcweir SvStream* pIStm = NULL;
440cdf0e10cSrcweir
441cdf0e10cSrcweir uno::Reference< io::XInputStream > xIStm;
442cdf0e10cSrcweir uno::Reference< awt::XBitmap >xBtm;
443cdf0e10cSrcweir
444cdf0e10cSrcweir for( sal_Int32 i = 0; ( i < rMediaProperties.getLength() ) && !pIStm && !xRet.is(); ++i )
445cdf0e10cSrcweir {
446cdf0e10cSrcweir const ::rtl::OUString aName( rMediaProperties[ i ].Name );
447cdf0e10cSrcweir const uno::Any aValue( rMediaProperties[ i ].Value );
448cdf0e10cSrcweir
449cdf0e10cSrcweir if( COMPARE_EQUAL == aName.compareToAscii( "URL" ) )
450cdf0e10cSrcweir {
451cdf0e10cSrcweir ::rtl::OUString aURL;
452cdf0e10cSrcweir aValue >>= aURL;
453cdf0e10cSrcweir aPath = aURL;
454cdf0e10cSrcweir }
455cdf0e10cSrcweir else if( COMPARE_EQUAL == aName.compareToAscii( "InputStream" ) )
456cdf0e10cSrcweir {
457cdf0e10cSrcweir aValue >>= xIStm;
458cdf0e10cSrcweir }
459cdf0e10cSrcweir else if( COMPARE_EQUAL == aName.compareToAscii( "Bitmap" ) )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir aValue >>= xBtm;
462cdf0e10cSrcweir }
463cdf0e10cSrcweir }
464cdf0e10cSrcweir
465cdf0e10cSrcweir if( xIStm.is() )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir pIStm = ::utl::UcbStreamHelper::CreateStream( xIStm );
468cdf0e10cSrcweir }
469cdf0e10cSrcweir else if( aPath.Len() )
470cdf0e10cSrcweir {
471cdf0e10cSrcweir xRet = implLoadMemory( aPath );
472cdf0e10cSrcweir
473cdf0e10cSrcweir if( !xRet.is() )
474cdf0e10cSrcweir xRet = implLoadGraphicObject( aPath );
475cdf0e10cSrcweir
476cdf0e10cSrcweir if( !xRet.is() )
477cdf0e10cSrcweir xRet = implLoadResource( aPath );
478cdf0e10cSrcweir
479cdf0e10cSrcweir if ( !xRet.is() )
480cdf0e10cSrcweir xRet = implLoadRepositoryImage( aPath );
481cdf0e10cSrcweir
482cdf0e10cSrcweir if ( !xRet.is() )
483cdf0e10cSrcweir xRet = implLoadStandardImage( aPath );
484cdf0e10cSrcweir
485cdf0e10cSrcweir if( !xRet.is() )
486cdf0e10cSrcweir pIStm = ::utl::UcbStreamHelper::CreateStream( aPath, STREAM_READ );
487cdf0e10cSrcweir }
488cdf0e10cSrcweir else if( xBtm.is() )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir xRet = implLoadBitmap( xBtm );
491cdf0e10cSrcweir }
492cdf0e10cSrcweir
493cdf0e10cSrcweir if( pIStm )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir ::GraphicFilter* pFilter = ::GraphicFilter::GetGraphicFilter();
496cdf0e10cSrcweir
497cdf0e10cSrcweir if( pFilter )
498cdf0e10cSrcweir {
499cdf0e10cSrcweir ::Graphic aVCLGraphic;
500cdf0e10cSrcweir
501cdf0e10cSrcweir if( ( pFilter->ImportGraphic( aVCLGraphic, aPath, *pIStm ) == GRFILTER_OK ) &&
502cdf0e10cSrcweir ( aVCLGraphic.GetType() != GRAPHIC_NONE ) )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir ::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic;
505cdf0e10cSrcweir
506cdf0e10cSrcweir pUnoGraphic->init( aVCLGraphic );
507cdf0e10cSrcweir xRet = pUnoGraphic;
508cdf0e10cSrcweir }
509cdf0e10cSrcweir }
510cdf0e10cSrcweir
511cdf0e10cSrcweir delete pIStm;
512cdf0e10cSrcweir }
513cdf0e10cSrcweir
514cdf0e10cSrcweir return xRet;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir
ImplCalculateCropRect(::Graphic & rGraphic,const text::GraphicCrop & rGraphicCropLogic,Rectangle & rGraphicCropPixel)517cdf0e10cSrcweir void ImplCalculateCropRect( ::Graphic& rGraphic, const text::GraphicCrop& rGraphicCropLogic, Rectangle& rGraphicCropPixel )
518cdf0e10cSrcweir {
519cdf0e10cSrcweir if ( rGraphicCropLogic.Left || rGraphicCropLogic.Top || rGraphicCropLogic.Right || rGraphicCropLogic.Bottom )
520cdf0e10cSrcweir {
521cdf0e10cSrcweir Size aSourceSizePixel( rGraphic.GetSizePixel() );
522cdf0e10cSrcweir if ( aSourceSizePixel.Width() && aSourceSizePixel.Height() )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir if ( rGraphicCropLogic.Left || rGraphicCropLogic.Top || rGraphicCropLogic.Right || rGraphicCropLogic.Bottom )
525cdf0e10cSrcweir {
526cdf0e10cSrcweir Size aSize100thMM( 0, 0 );
527cdf0e10cSrcweir if( rGraphic.GetPrefMapMode().GetMapUnit() != MAP_PIXEL )
528cdf0e10cSrcweir {
529cdf0e10cSrcweir aSize100thMM = OutputDevice::LogicToLogic( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode(), MAP_100TH_MM );
530cdf0e10cSrcweir }
531cdf0e10cSrcweir else
532cdf0e10cSrcweir {
533cdf0e10cSrcweir aSize100thMM = Application::GetDefaultDevice()->PixelToLogic( rGraphic.GetPrefSize(), MAP_100TH_MM );
534cdf0e10cSrcweir }
535cdf0e10cSrcweir if ( aSize100thMM.Width() && aSize100thMM.Height() )
536cdf0e10cSrcweir {
537cdf0e10cSrcweir double fSourceSizePixelWidth = static_cast<double>(aSourceSizePixel.Width());
538cdf0e10cSrcweir double fSourceSizePixelHeight= static_cast<double>(aSourceSizePixel.Height());
539cdf0e10cSrcweir rGraphicCropPixel.Left() = static_cast< sal_Int32 >((fSourceSizePixelWidth * rGraphicCropLogic.Left ) / aSize100thMM.Width());
540cdf0e10cSrcweir rGraphicCropPixel.Top() = static_cast< sal_Int32 >((fSourceSizePixelHeight * rGraphicCropLogic.Top ) / aSize100thMM.Height());
541cdf0e10cSrcweir rGraphicCropPixel.Right() = static_cast< sal_Int32 >(( fSourceSizePixelWidth * ( aSize100thMM.Width() - rGraphicCropLogic.Right ) ) / aSize100thMM.Width() );
542cdf0e10cSrcweir rGraphicCropPixel.Bottom() = static_cast< sal_Int32 >(( fSourceSizePixelHeight * ( aSize100thMM.Height() - rGraphicCropLogic.Bottom ) ) / aSize100thMM.Height() );
543cdf0e10cSrcweir }
544cdf0e10cSrcweir }
545cdf0e10cSrcweir }
546cdf0e10cSrcweir }
547cdf0e10cSrcweir }
548cdf0e10cSrcweir
ImplApplyBitmapScaling(::Graphic & rGraphic,sal_Int32 nPixelWidth,sal_Int32 nPixelHeight)549cdf0e10cSrcweir void ImplApplyBitmapScaling( ::Graphic& rGraphic, sal_Int32 nPixelWidth, sal_Int32 nPixelHeight )
550cdf0e10cSrcweir {
551cdf0e10cSrcweir if ( nPixelWidth && nPixelHeight )
552cdf0e10cSrcweir {
553cdf0e10cSrcweir BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
554cdf0e10cSrcweir MapMode aPrefMapMode( aBmpEx.GetPrefMapMode() );
555cdf0e10cSrcweir Size aPrefSize( aBmpEx.GetPrefSize() );
556cdf0e10cSrcweir aBmpEx.Scale( Size( nPixelWidth, nPixelHeight ) );
557cdf0e10cSrcweir aBmpEx.SetPrefMapMode( aPrefMapMode );
558cdf0e10cSrcweir aBmpEx.SetPrefSize( aPrefSize );
559cdf0e10cSrcweir rGraphic = aBmpEx;
560cdf0e10cSrcweir }
561cdf0e10cSrcweir }
562cdf0e10cSrcweir
ImplApplyBitmapResolution(::Graphic & rGraphic,sal_Int32 nImageResolution,const Size & rVisiblePixelSize,const awt::Size & rLogicalSize)563cdf0e10cSrcweir void ImplApplyBitmapResolution( ::Graphic& rGraphic, sal_Int32 nImageResolution, const Size& rVisiblePixelSize, const awt::Size& rLogicalSize )
564cdf0e10cSrcweir {
565cdf0e10cSrcweir if ( nImageResolution && rLogicalSize.Width && rLogicalSize.Height )
566cdf0e10cSrcweir {
567cdf0e10cSrcweir const double fImageResolution = static_cast<double>( nImageResolution );
568cdf0e10cSrcweir const double fSourceDPIX = ( static_cast<double>(rVisiblePixelSize.Width()) * 2540.0 ) / static_cast<double>(rLogicalSize.Width);
569cdf0e10cSrcweir const double fSourceDPIY = ( static_cast<double>(rVisiblePixelSize.Height()) * 2540.0 ) / static_cast<double>(rLogicalSize.Height);
570cdf0e10cSrcweir const sal_Int32 nSourcePixelWidth( rGraphic.GetSizePixel().Width() );
571cdf0e10cSrcweir const sal_Int32 nSourcePixelHeight( rGraphic.GetSizePixel().Height() );
572cdf0e10cSrcweir const double fSourcePixelWidth = static_cast<double>( nSourcePixelWidth );
573cdf0e10cSrcweir const double fSourcePixelHeight= static_cast<double>( nSourcePixelHeight );
574cdf0e10cSrcweir
575cdf0e10cSrcweir sal_Int32 nDestPixelWidth = nSourcePixelWidth;
576cdf0e10cSrcweir sal_Int32 nDestPixelHeight = nSourcePixelHeight;
577cdf0e10cSrcweir
578cdf0e10cSrcweir // check, if the bitmap DPI exceeds the maximum DPI
579cdf0e10cSrcweir if( fSourceDPIX > fImageResolution )
580cdf0e10cSrcweir {
581cdf0e10cSrcweir nDestPixelWidth = static_cast<sal_Int32>(( fSourcePixelWidth * fImageResolution ) / fSourceDPIX);
582cdf0e10cSrcweir if ( !nDestPixelWidth || ( nDestPixelWidth > nSourcePixelWidth ) )
583cdf0e10cSrcweir nDestPixelWidth = nSourcePixelWidth;
584cdf0e10cSrcweir }
585cdf0e10cSrcweir if ( fSourceDPIY > fImageResolution )
586cdf0e10cSrcweir {
587cdf0e10cSrcweir nDestPixelHeight= static_cast<sal_Int32>(( fSourcePixelHeight* fImageResolution ) / fSourceDPIY);
588cdf0e10cSrcweir if ( !nDestPixelHeight || ( nDestPixelHeight > nSourcePixelHeight ) )
589cdf0e10cSrcweir nDestPixelHeight = nSourcePixelHeight;
590cdf0e10cSrcweir }
591cdf0e10cSrcweir if ( ( nDestPixelWidth != nSourcePixelWidth ) || ( nDestPixelHeight != nSourcePixelHeight ) )
592cdf0e10cSrcweir ImplApplyBitmapScaling( rGraphic, nDestPixelWidth, nDestPixelHeight );
593cdf0e10cSrcweir }
594cdf0e10cSrcweir }
595cdf0e10cSrcweir
ImplApplyFilterData(::Graphic & rGraphic,uno::Sequence<beans::PropertyValue> & rFilterData)596cdf0e10cSrcweir void ImplApplyFilterData( ::Graphic& rGraphic, uno::Sequence< beans::PropertyValue >& rFilterData )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir /* this method applies following attributes to the graphic, in the first step the
599cdf0e10cSrcweir cropping area (logical size in 100thmm) is applied, in the second step the resolution
600cdf0e10cSrcweir is applied, in the third step the graphic is scaled to the corresponding pixelsize.
601cdf0e10cSrcweir if a parameter value is zero or not available the corresponding step will be skipped */
602cdf0e10cSrcweir
603cdf0e10cSrcweir sal_Int32 nPixelWidth = 0;
604cdf0e10cSrcweir sal_Int32 nPixelHeight= 0;
605cdf0e10cSrcweir sal_Int32 nImageResolution = 0;
606cdf0e10cSrcweir awt::Size aLogicalSize( 0, 0 );
607cdf0e10cSrcweir text::GraphicCrop aCropLogic( 0, 0, 0, 0 );
608cdf0e10cSrcweir sal_Bool bRemoveCropArea = sal_True;
609cdf0e10cSrcweir
610cdf0e10cSrcweir for( sal_Int32 i = 0; i < rFilterData.getLength(); ++i )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir const ::rtl::OUString aName( rFilterData[ i ].Name );
613cdf0e10cSrcweir const uno::Any aValue( rFilterData[ i ].Value );
614cdf0e10cSrcweir
615cdf0e10cSrcweir if( COMPARE_EQUAL == aName.compareToAscii( "PixelWidth" ) )
616cdf0e10cSrcweir aValue >>= nPixelWidth;
617cdf0e10cSrcweir else if( COMPARE_EQUAL == aName.compareToAscii( "PixelHeight" ) )
618cdf0e10cSrcweir aValue >>= nPixelHeight;
619cdf0e10cSrcweir else if( COMPARE_EQUAL == aName.compareToAscii( "LogicalSize" ) )
620cdf0e10cSrcweir aValue >>= aLogicalSize;
621cdf0e10cSrcweir else if (COMPARE_EQUAL == aName.compareToAscii( "GraphicCropLogic" ) )
622cdf0e10cSrcweir aValue >>= aCropLogic;
623cdf0e10cSrcweir else if (COMPARE_EQUAL == aName.compareToAscii( "RemoveCropArea" ) )
624cdf0e10cSrcweir aValue >>= bRemoveCropArea;
625cdf0e10cSrcweir else if (COMPARE_EQUAL == aName.compareToAscii( "ImageResolution" ) )
626cdf0e10cSrcweir aValue >>= nImageResolution;
627cdf0e10cSrcweir }
628cdf0e10cSrcweir if ( rGraphic.GetType() == GRAPHIC_BITMAP )
629cdf0e10cSrcweir {
630ddde725dSArmin Le Grand if(rGraphic.getSvgData().get())
631ddde725dSArmin Le Grand {
632ddde725dSArmin Le Grand // embedded Svg, no need to scale. Also no method to apply crop data currently
633ddde725dSArmin Le Grand }
634ddde725dSArmin Le Grand else
635ddde725dSArmin Le Grand {
636cdf0e10cSrcweir Rectangle aCropPixel( Point( 0, 0 ), rGraphic.GetSizePixel() );
637cdf0e10cSrcweir ImplCalculateCropRect( rGraphic, aCropLogic, aCropPixel );
638cdf0e10cSrcweir if ( bRemoveCropArea )
639cdf0e10cSrcweir {
640cdf0e10cSrcweir BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
641cdf0e10cSrcweir aBmpEx.Crop( aCropPixel );
642cdf0e10cSrcweir rGraphic = aBmpEx;
643cdf0e10cSrcweir }
644cdf0e10cSrcweir Size aVisiblePixelSize( bRemoveCropArea ? rGraphic.GetSizePixel() : aCropPixel.GetSize() );
645cdf0e10cSrcweir ImplApplyBitmapResolution( rGraphic, nImageResolution, aVisiblePixelSize, aLogicalSize );
646cdf0e10cSrcweir ImplApplyBitmapScaling( rGraphic, nPixelWidth, nPixelHeight );
647cdf0e10cSrcweir }
648ddde725dSArmin Le Grand }
649cdf0e10cSrcweir else if ( ( rGraphic.GetType() == GRAPHIC_GDIMETAFILE ) && nImageResolution )
650cdf0e10cSrcweir {
651cdf0e10cSrcweir VirtualDevice aDummyVDev;
652cdf0e10cSrcweir GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
653cdf0e10cSrcweir Size aMtfSize( aDummyVDev.LogicToLogic( aMtf.GetPrefSize(), aMtf.GetPrefMapMode(), MAP_100TH_MM ) );
654cdf0e10cSrcweir if ( aMtfSize.Width() && aMtfSize.Height() )
655cdf0e10cSrcweir {
656cdf0e10cSrcweir MapMode aNewMapMode( MAP_100TH_MM );
657cdf0e10cSrcweir aNewMapMode.SetScaleX( static_cast< double >( aLogicalSize.Width ) / static_cast< double >( aMtfSize.Width() ) );
658cdf0e10cSrcweir aNewMapMode.SetScaleY( static_cast< double >( aLogicalSize.Height ) / static_cast< double >( aMtfSize.Height() ) );
659cdf0e10cSrcweir aDummyVDev.EnableOutput( sal_False );
660cdf0e10cSrcweir aDummyVDev.SetMapMode( aNewMapMode );
661cdf0e10cSrcweir
662cdf0e10cSrcweir for( sal_uInt32 i = 0, nObjCount = aMtf.GetActionCount(); i < nObjCount; i++ )
663cdf0e10cSrcweir {
664cdf0e10cSrcweir MetaAction* pAction = aMtf.GetAction( i );
665cdf0e10cSrcweir switch( pAction->GetType() )
666cdf0e10cSrcweir {
667cdf0e10cSrcweir // only optimizing common bitmap actions:
668cdf0e10cSrcweir case( META_MAPMODE_ACTION ):
669cdf0e10cSrcweir {
670cdf0e10cSrcweir const_cast< MetaAction* >( pAction )->Execute( &aDummyVDev );
671cdf0e10cSrcweir break;
672cdf0e10cSrcweir }
673cdf0e10cSrcweir case( META_PUSH_ACTION ):
674cdf0e10cSrcweir {
675cdf0e10cSrcweir const MetaPushAction* pA = (const MetaPushAction*)pAction;
676cdf0e10cSrcweir aDummyVDev.Push( pA->GetFlags() );
677cdf0e10cSrcweir break;
678cdf0e10cSrcweir }
679cdf0e10cSrcweir case( META_POP_ACTION ):
680cdf0e10cSrcweir {
681cdf0e10cSrcweir aDummyVDev.Pop();
682cdf0e10cSrcweir break;
683cdf0e10cSrcweir }
684cdf0e10cSrcweir case( META_BMPSCALE_ACTION ):
685cdf0e10cSrcweir case( META_BMPEXSCALE_ACTION ):
686cdf0e10cSrcweir {
687cdf0e10cSrcweir BitmapEx aBmpEx;
688cdf0e10cSrcweir Point aPos;
689cdf0e10cSrcweir Size aSize;
690cdf0e10cSrcweir if ( pAction->GetType() == META_BMPSCALE_ACTION )
691cdf0e10cSrcweir {
692cdf0e10cSrcweir MetaBmpScaleAction* pScaleAction = dynamic_cast< MetaBmpScaleAction* >( pAction );
693cdf0e10cSrcweir aBmpEx = pScaleAction->GetBitmap();
694cdf0e10cSrcweir aPos = pScaleAction->GetPoint();
695cdf0e10cSrcweir aSize = pScaleAction->GetSize();
696cdf0e10cSrcweir }
697cdf0e10cSrcweir else
698cdf0e10cSrcweir {
699cdf0e10cSrcweir MetaBmpExScaleAction* pScaleAction = dynamic_cast< MetaBmpExScaleAction* >( pAction );
700cdf0e10cSrcweir aBmpEx = pScaleAction->GetBitmapEx();
701cdf0e10cSrcweir aPos = pScaleAction->GetPoint();
702cdf0e10cSrcweir aSize = pScaleAction->GetSize();
703cdf0e10cSrcweir }
704cdf0e10cSrcweir ::Graphic aGraphic( aBmpEx );
705cdf0e10cSrcweir const Size aSize100thmm( aDummyVDev.LogicToPixel( aSize ) );
706cdf0e10cSrcweir Size aSize100thmm2( aDummyVDev.PixelToLogic( aSize100thmm, MAP_100TH_MM ) );
707cdf0e10cSrcweir
708cdf0e10cSrcweir ImplApplyBitmapResolution( aGraphic, nImageResolution,
709cdf0e10cSrcweir aGraphic.GetSizePixel(), awt::Size( aSize100thmm2.Width(), aSize100thmm2.Height() ) );
710cdf0e10cSrcweir
711cdf0e10cSrcweir MetaAction* pNewAction;
712cdf0e10cSrcweir if ( pAction->GetType() == META_BMPSCALE_ACTION )
713cdf0e10cSrcweir pNewAction = new MetaBmpScaleAction ( aPos, aSize, aGraphic.GetBitmap() );
714cdf0e10cSrcweir else
715cdf0e10cSrcweir pNewAction = new MetaBmpExScaleAction( aPos, aSize, aGraphic.GetBitmapEx() );
716cdf0e10cSrcweir
717cdf0e10cSrcweir aMtf.ReplaceAction( pNewAction, i );
718cdf0e10cSrcweir pAction->Delete();
719cdf0e10cSrcweir break;
720cdf0e10cSrcweir }
721cdf0e10cSrcweir default:
722cdf0e10cSrcweir case( META_BMP_ACTION ):
723cdf0e10cSrcweir case( META_BMPSCALEPART_ACTION ):
724cdf0e10cSrcweir case( META_BMPEX_ACTION ):
725cdf0e10cSrcweir case( META_BMPEXSCALEPART_ACTION ):
726cdf0e10cSrcweir case( META_MASK_ACTION ):
727cdf0e10cSrcweir case( META_MASKSCALE_ACTION ):
728cdf0e10cSrcweir break;
729cdf0e10cSrcweir }
730cdf0e10cSrcweir }
731cdf0e10cSrcweir rGraphic = aMtf;
732cdf0e10cSrcweir }
733cdf0e10cSrcweir }
734cdf0e10cSrcweir }
735cdf0e10cSrcweir
736cdf0e10cSrcweir // ------------------------------------------------------------------------------
737cdf0e10cSrcweir
storeGraphic(const uno::Reference<::graphic::XGraphic> & rxGraphic,const uno::Sequence<beans::PropertyValue> & rMediaProperties)738cdf0e10cSrcweir void SAL_CALL GraphicProvider::storeGraphic( const uno::Reference< ::graphic::XGraphic >& rxGraphic, const uno::Sequence< beans::PropertyValue >& rMediaProperties )
739cdf0e10cSrcweir throw ( io::IOException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
740cdf0e10cSrcweir {
741cdf0e10cSrcweir SvStream* pOStm = NULL;
742cdf0e10cSrcweir String aPath;
743cdf0e10cSrcweir sal_Int32 i;
744cdf0e10cSrcweir
745cdf0e10cSrcweir for( i = 0; ( i < rMediaProperties.getLength() ) && !pOStm; ++i )
746cdf0e10cSrcweir {
747cdf0e10cSrcweir const ::rtl::OUString aName( rMediaProperties[ i ].Name );
748cdf0e10cSrcweir const uno::Any aValue( rMediaProperties[ i ].Value );
749cdf0e10cSrcweir
750cdf0e10cSrcweir if( COMPARE_EQUAL == aName.compareToAscii( "URL" ) )
751cdf0e10cSrcweir {
752cdf0e10cSrcweir ::rtl::OUString aURL;
753cdf0e10cSrcweir
754cdf0e10cSrcweir aValue >>= aURL;
755cdf0e10cSrcweir pOStm = ::utl::UcbStreamHelper::CreateStream( aURL, STREAM_WRITE | STREAM_TRUNC );
756cdf0e10cSrcweir aPath = aURL;
757cdf0e10cSrcweir }
758cdf0e10cSrcweir else if( COMPARE_EQUAL == aName.compareToAscii( "OutputStream" ) )
759cdf0e10cSrcweir {
760cdf0e10cSrcweir uno::Reference< io::XStream > xOStm;
761cdf0e10cSrcweir
762cdf0e10cSrcweir aValue >>= xOStm;
763cdf0e10cSrcweir
764cdf0e10cSrcweir if( xOStm.is() )
765cdf0e10cSrcweir pOStm = ::utl::UcbStreamHelper::CreateStream( xOStm );
766cdf0e10cSrcweir }
767cdf0e10cSrcweir }
768cdf0e10cSrcweir
769cdf0e10cSrcweir if( pOStm )
770cdf0e10cSrcweir {
771cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aFilterDataSeq;
772cdf0e10cSrcweir const char* pFilterShortName = NULL;
773cdf0e10cSrcweir
774cdf0e10cSrcweir for( i = 0; i < rMediaProperties.getLength(); ++i )
775cdf0e10cSrcweir {
776cdf0e10cSrcweir const ::rtl::OUString aName( rMediaProperties[ i ].Name );
777cdf0e10cSrcweir const uno::Any aValue( rMediaProperties[ i ].Value );
778cdf0e10cSrcweir
779cdf0e10cSrcweir if( COMPARE_EQUAL == aName.compareToAscii( "FilterData" ) )
780cdf0e10cSrcweir {
781cdf0e10cSrcweir aValue >>= aFilterDataSeq;
782cdf0e10cSrcweir }
783cdf0e10cSrcweir else if( COMPARE_EQUAL == aName.compareToAscii( "MimeType" ) )
784cdf0e10cSrcweir {
785cdf0e10cSrcweir ::rtl::OUString aMimeType;
786cdf0e10cSrcweir
787cdf0e10cSrcweir aValue >>= aMimeType;
788cdf0e10cSrcweir
789cdf0e10cSrcweir if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_BMP ) )
790cdf0e10cSrcweir pFilterShortName = "bmp";
791cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_EPS ) )
792cdf0e10cSrcweir pFilterShortName = "eps";
793cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_GIF ) )
794cdf0e10cSrcweir pFilterShortName = "gif";
795cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_JPG ) )
796cdf0e10cSrcweir pFilterShortName = "jpg";
797cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_MET ) )
798cdf0e10cSrcweir pFilterShortName = "met";
799cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_PNG ) )
800cdf0e10cSrcweir pFilterShortName = "png";
801cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_PCT ) )
802cdf0e10cSrcweir pFilterShortName = "pct";
803cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_PBM ) )
804cdf0e10cSrcweir pFilterShortName = "pbm";
805cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_PGM ) )
806cdf0e10cSrcweir pFilterShortName = "pgm";
807cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_PPM ) )
808cdf0e10cSrcweir pFilterShortName = "ppm";
809cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_RAS ) )
810cdf0e10cSrcweir pFilterShortName = "ras";
811cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_SVM ) )
812cdf0e10cSrcweir pFilterShortName = "svm";
813cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_TIF ) )
814cdf0e10cSrcweir pFilterShortName = "tif";
815cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_EMF ) )
816cdf0e10cSrcweir pFilterShortName = "emf";
817cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_WMF ) )
818cdf0e10cSrcweir pFilterShortName = "wmf";
819cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_XPM ) )
820cdf0e10cSrcweir pFilterShortName = "xpm";
821cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_SVG ) )
822cdf0e10cSrcweir pFilterShortName = "svg";
823cdf0e10cSrcweir else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_VCLGRAPHIC ) )
824cdf0e10cSrcweir pFilterShortName = MIMETYPE_VCLGRAPHIC;
825cdf0e10cSrcweir }
826cdf0e10cSrcweir }
827cdf0e10cSrcweir
828cdf0e10cSrcweir if( pFilterShortName )
829cdf0e10cSrcweir {
830cdf0e10cSrcweir ::GraphicFilter* pFilter = ::GraphicFilter::GetGraphicFilter();
831cdf0e10cSrcweir
832cdf0e10cSrcweir if( pFilter )
833cdf0e10cSrcweir {
834cdf0e10cSrcweir const uno::Reference< XInterface > xIFace( rxGraphic, uno::UNO_QUERY );
835cdf0e10cSrcweir const ::Graphic* pGraphic = ::unographic::Graphic::getImplementation( xIFace );
836cdf0e10cSrcweir
837cdf0e10cSrcweir if( pGraphic && ( pGraphic->GetType() != GRAPHIC_NONE ) )
838cdf0e10cSrcweir {
839cdf0e10cSrcweir ::Graphic aGraphic( *pGraphic );
840cdf0e10cSrcweir ImplApplyFilterData( aGraphic, aFilterDataSeq );
841cdf0e10cSrcweir
842cdf0e10cSrcweir /* sj: using a temporary memory stream, because some graphic filters are seeking behind
843cdf0e10cSrcweir stream end (which leads to an invalid argument exception then). */
844cdf0e10cSrcweir SvMemoryStream aMemStrm;
845cdf0e10cSrcweir aMemStrm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
846cdf0e10cSrcweir if( 0 == strcmp( pFilterShortName, MIMETYPE_VCLGRAPHIC ) )
847cdf0e10cSrcweir aMemStrm << aGraphic;
848cdf0e10cSrcweir else
849cdf0e10cSrcweir {
850cdf0e10cSrcweir pFilter->ExportGraphic( aGraphic, aPath, aMemStrm,
851cdf0e10cSrcweir pFilter->GetExportFormatNumberForShortName( ::rtl::OUString::createFromAscii( pFilterShortName ) ),
852cdf0e10cSrcweir ( aFilterDataSeq.getLength() ? &aFilterDataSeq : NULL ) );
853cdf0e10cSrcweir }
854cdf0e10cSrcweir aMemStrm.Seek( STREAM_SEEK_TO_END );
855cdf0e10cSrcweir pOStm->Write( aMemStrm.GetData(), aMemStrm.Tell() );
856cdf0e10cSrcweir }
857cdf0e10cSrcweir }
858cdf0e10cSrcweir }
859cdf0e10cSrcweir delete pOStm;
860cdf0e10cSrcweir }
861cdf0e10cSrcweir }
862cdf0e10cSrcweir
863cdf0e10cSrcweir }
864