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