Files
libreoffice/svtools/source/graphic/provider.cxx

865 lines
33 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
2009-12-15 21:55:40 +01:00
#include "precompiled_svtools.hxx"
#include <rtl/uuid.h>
#include <osl/mutex.hxx>
#include <vcl/svapp.hxx>
#include <vcl/image.hxx>
#include <vcl/metaact.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/imagerepository.hxx>
#include <tools/rcid.h>
#include <tools/resid.hxx>
#include <tools/resmgr.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <svtools/filter.hxx>
#include <svl/solar.hrc>
#include <vcl/salbtype.hxx>
#include <vcl/virdev.hxx>
#include <com/sun/star/io/XStream.hpp>
#include <com/sun/star/text/GraphicCrop.hpp>
#include "descriptor.hxx"
#include "graphic.hxx"
2009-12-15 21:55:40 +01:00
#include <svtools/grfmgr.hxx>
#include "provider.hxx"
using namespace com::sun::star;
namespace unographic {
CWS-TOOLING: integrate CWS dba31e 2008-11-19 12:36:23 +0100 msc r263980 : i96104 2008-11-19 12:31:19 +0100 msc r263979 : i96104 2008-11-19 12:21:55 +0100 msc r263977 : i96104 2008-11-19 12:18:53 +0100 msc r263976 : i96104 2008-11-18 09:09:45 +0100 oj r263746 : disable color entry when area is set 2008-11-18 08:37:52 +0100 oj r263741 : #remove sub report entry 2008-11-17 11:20:25 +0100 fs r263708 : #i10000# 2008-11-17 11:06:52 +0100 fs r263706 : minimal version now is 3.1 2008-11-12 22:25:59 +0100 fs r263621 : #i96150# 2008-11-12 22:20:02 +0100 fs r263620 : rebased to m34 2008-11-12 21:39:41 +0100 fs r263618 : MANUAL REBASE: rebase CWS dba31d to DEV300_m34 2008-11-12 13:54:58 +0100 fs r263597 : #i96134# MediaDescriptor.URL is to be preferred over MediaDescriptor.FileName. Nonetheless, ensure both are handled 2008-11-12 13:53:40 +0100 fs r263596 : #i96134# re-enabled the code for #i41897#, a better fix is to come 2008-11-12 12:48:21 +0100 fs r263585 : #i96134# disable saving URLs of file-base databases relatively 2008-11-11 16:11:11 +0100 msc r263566 : #i96104# 2008-11-05 09:09:47 +0100 oj r263342 : #i88727# color noe added 2008-11-05 08:41:43 +0100 oj r263341 : #i77916# zoom added 2008-11-04 21:24:15 +0100 fs r263339 : disposing: call disposeAndClear without own mutex locked - some of our listeners insist on locking the SolarMutex, which sometimes led to deadlocks on the complex test cases 2008-11-04 21:23:15 +0100 fs r263338 : remove SolarMutex locking - this happned in CWS dba31c (in the CVS version), which this CWS was created from, but seems to got lost during resync 2008-11-04 20:49:50 +0100 fs r263335 : docu formatting 2008-11-04 20:06:39 +0100 fs r263334 : #i95826# use m_aMutex, not a DocumentGuard (wrongly resolved merge conflicts) 2008-11-04 17:36:29 +0100 fs r263332 : #i92688# properly revoke as XEventListener from m_xActiveController when disposing 2008-11-04 14:49:34 +0100 fs r263324 : #i92322# enable Input Required if EmptyIsNULL does not exist at the control 2008-10-31 11:10:04 +0100 oj r262857 : merge from cvs to svn 2008-10-31 09:46:45 +0100 oj r262853 : merge from cvs to svn 2008-10-31 08:46:37 +0100 oj r262849 : merge from cvs to svn 2008-10-31 08:44:24 +0100 oj r262848 : merge from cvs to svn 2008-10-31 08:43:33 +0100 oj r262847 : merge from cvs to svn 2008-10-31 08:42:28 +0100 oj r262846 : merge from cvs to svn 2008-10-31 08:41:58 +0100 oj r262845 : merge from cvs to svn 2008-10-31 08:41:32 +0100 oj r262844 : merge from cvs to svn 2008-10-28 12:19:50 +0100 oj r262733 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:42 +0100 oj r262732 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:36 +0100 oj r262731 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:31 +0100 oj r262730 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:22 +0100 oj r262729 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:18 +0100 oj r262728 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:10 +0100 oj r262727 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:06 +0100 oj r262726 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:05 +0100 oj r262725 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:01 +0100 oj r262724 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:50 +0100 oj r262723 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:41 +0100 oj r262722 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:40 +0100 oj r262721 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:27 +0100 oj r262720 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:10 +0100 oj r262719 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:01 +0100 oj r262718 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:17:39 +0100 oj r262717 : #iXXXXX#: migrate CWS dba31e to SVN
2008-12-01 12:31:27 +00:00
#define UNO_NAME_GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:"
// -------------------
// - GraphicProvider -
// -------------------
2009-12-15 21:55:40 +01:00
uno::Reference< uno::XInterface > SAL_CALL GraphicProvider_CreateInstance( const uno::Reference< lang::XMultiServiceFactory >& )
{
return SAL_STATIC_CAST( ::cppu::OWeakObject*, new GraphicProvider );
}
GraphicProvider::GraphicProvider()
{
}
// ------------------------------------------------------------------------------
GraphicProvider::~GraphicProvider()
{
}
// ------------------------------------------------------------------------------
::rtl::OUString GraphicProvider::getImplementationName_Static()
throw()
{
return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.GraphicProvider" ) );
}
// ------------------------------------------------------------------------------
uno::Sequence< ::rtl::OUString > GraphicProvider::getSupportedServiceNames_Static()
throw()
{
uno::Sequence< ::rtl::OUString > aSeq( 1 );
aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicProvider" ) );
return aSeq;
}
// ------------------------------------------------------------------------------
::rtl::OUString SAL_CALL GraphicProvider::getImplementationName()
throw( uno::RuntimeException )
{
return getImplementationName_Static();
}
// ------------------------------------------------------------------------------
sal_Bool SAL_CALL GraphicProvider::supportsService( const ::rtl::OUString& ServiceName )
throw( uno::RuntimeException )
{
uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
const ::rtl::OUString* pArray = aSNL.getConstArray();
for( int i = 0; i < aSNL.getLength(); i++ )
if( pArray[i] == ServiceName )
return true;
return false;
}
// ------------------------------------------------------------------------------
uno::Sequence< ::rtl::OUString > SAL_CALL GraphicProvider::getSupportedServiceNames()
throw( uno::RuntimeException )
{
return getSupportedServiceNames_Static();
}
// ------------------------------------------------------------------------------
uno::Sequence< uno::Type > SAL_CALL GraphicProvider::getTypes()
throw(uno::RuntimeException)
{
uno::Sequence< uno::Type > aTypes( 3 );
uno::Type* pTypes = aTypes.getArray();
*pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
*pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
*pTypes++ = ::getCppuType((const uno::Reference< graphic::XGraphicProvider>*)0);
return aTypes;
}
// ------------------------------------------------------------------------------
uno::Sequence< sal_Int8 > SAL_CALL GraphicProvider::getImplementationId()
throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
static uno::Sequence< sal_Int8 > aId;
if( aId.getLength() == 0 )
{
aId.realloc( 16 );
rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True );
}
return aId;
}
// ------------------------------------------------------------------------------
CWS-TOOLING: integrate CWS dba31e 2008-11-19 12:36:23 +0100 msc r263980 : i96104 2008-11-19 12:31:19 +0100 msc r263979 : i96104 2008-11-19 12:21:55 +0100 msc r263977 : i96104 2008-11-19 12:18:53 +0100 msc r263976 : i96104 2008-11-18 09:09:45 +0100 oj r263746 : disable color entry when area is set 2008-11-18 08:37:52 +0100 oj r263741 : #remove sub report entry 2008-11-17 11:20:25 +0100 fs r263708 : #i10000# 2008-11-17 11:06:52 +0100 fs r263706 : minimal version now is 3.1 2008-11-12 22:25:59 +0100 fs r263621 : #i96150# 2008-11-12 22:20:02 +0100 fs r263620 : rebased to m34 2008-11-12 21:39:41 +0100 fs r263618 : MANUAL REBASE: rebase CWS dba31d to DEV300_m34 2008-11-12 13:54:58 +0100 fs r263597 : #i96134# MediaDescriptor.URL is to be preferred over MediaDescriptor.FileName. Nonetheless, ensure both are handled 2008-11-12 13:53:40 +0100 fs r263596 : #i96134# re-enabled the code for #i41897#, a better fix is to come 2008-11-12 12:48:21 +0100 fs r263585 : #i96134# disable saving URLs of file-base databases relatively 2008-11-11 16:11:11 +0100 msc r263566 : #i96104# 2008-11-05 09:09:47 +0100 oj r263342 : #i88727# color noe added 2008-11-05 08:41:43 +0100 oj r263341 : #i77916# zoom added 2008-11-04 21:24:15 +0100 fs r263339 : disposing: call disposeAndClear without own mutex locked - some of our listeners insist on locking the SolarMutex, which sometimes led to deadlocks on the complex test cases 2008-11-04 21:23:15 +0100 fs r263338 : remove SolarMutex locking - this happned in CWS dba31c (in the CVS version), which this CWS was created from, but seems to got lost during resync 2008-11-04 20:49:50 +0100 fs r263335 : docu formatting 2008-11-04 20:06:39 +0100 fs r263334 : #i95826# use m_aMutex, not a DocumentGuard (wrongly resolved merge conflicts) 2008-11-04 17:36:29 +0100 fs r263332 : #i92688# properly revoke as XEventListener from m_xActiveController when disposing 2008-11-04 14:49:34 +0100 fs r263324 : #i92322# enable Input Required if EmptyIsNULL does not exist at the control 2008-10-31 11:10:04 +0100 oj r262857 : merge from cvs to svn 2008-10-31 09:46:45 +0100 oj r262853 : merge from cvs to svn 2008-10-31 08:46:37 +0100 oj r262849 : merge from cvs to svn 2008-10-31 08:44:24 +0100 oj r262848 : merge from cvs to svn 2008-10-31 08:43:33 +0100 oj r262847 : merge from cvs to svn 2008-10-31 08:42:28 +0100 oj r262846 : merge from cvs to svn 2008-10-31 08:41:58 +0100 oj r262845 : merge from cvs to svn 2008-10-31 08:41:32 +0100 oj r262844 : merge from cvs to svn 2008-10-28 12:19:50 +0100 oj r262733 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:42 +0100 oj r262732 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:36 +0100 oj r262731 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:31 +0100 oj r262730 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:22 +0100 oj r262729 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:18 +0100 oj r262728 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:10 +0100 oj r262727 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:06 +0100 oj r262726 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:05 +0100 oj r262725 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:01 +0100 oj r262724 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:50 +0100 oj r262723 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:41 +0100 oj r262722 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:40 +0100 oj r262721 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:27 +0100 oj r262720 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:10 +0100 oj r262719 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:01 +0100 oj r262718 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:17:39 +0100 oj r262717 : #iXXXXX#: migrate CWS dba31e to SVN
2008-12-01 12:31:27 +00:00
uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadGraphicObject( const ::rtl::OUString& rResourceURL ) const
{
uno::Reference< ::graphic::XGraphic > xRet;
if( rResourceURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPREFIX ) ) == 0 )
{
// graphic manager url
String aTmpStr( rResourceURL.copy( sizeof( UNO_NAME_GRAPHOBJ_URLPREFIX ) - 1 ) );
ByteString aUniqueID( aTmpStr, RTL_TEXTENCODING_UTF8 );
GraphicObject aGrafObj( aUniqueID );
// I don't call aGrafObj.GetXGraphic because it will call us back
// into implLoadMemory ( with "private:memorygraphic" test )
::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic;
pUnoGraphic->init( aGrafObj.GetGraphic() );
xRet = pUnoGraphic;
}
return xRet;
}
uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadMemory( const ::rtl::OUString& rResourceURL ) const
{
uno::Reference< ::graphic::XGraphic > xRet;
sal_Int32 nIndex = 0;
if( ( 0 == rResourceURL.getToken( 0, '/', nIndex ).compareToAscii( "private:memorygraphic" ) ) )
{
sal_Int64 nGraphicAddress = rResourceURL.getToken( 0, '/', nIndex ).toInt64();
if( nGraphicAddress )
{
::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic;
pUnoGraphic->init( *reinterpret_cast< ::Graphic* >( nGraphicAddress ) );
xRet = pUnoGraphic;
}
}
return xRet;
}
// ------------------------------------------------------------------------------
uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadRepositoryImage( const ::rtl::OUString& rResourceURL ) const
{
uno::Reference< ::graphic::XGraphic > xRet;
sal_Int32 nIndex = 0;
if( ( 0 == rResourceURL.getToken( 0, '/', nIndex ).compareToAscii( "private:graphicrepository" ) ) )
{
String sPathName( rResourceURL.copy( nIndex ) );
BitmapEx aBitmap;
if ( ::vcl::ImageRepository::loadImage( sPathName, aBitmap, false ) )
{
Image aImage( aBitmap );
xRet = aImage.GetXGraphic();
}
}
return xRet;
}
// ------------------------------------------------------------------------------
uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadStandardImage( const ::rtl::OUString& rResourceURL ) const
{
uno::Reference< ::graphic::XGraphic > xRet;
sal_Int32 nIndex = 0;
if( ( 0 == rResourceURL.getToken( 0, '/', nIndex ).compareToAscii( "private:standardimage" ) ) )
{
rtl::OUString sImageName( rResourceURL.copy( nIndex ) );
2011-01-16 21:20:49 +00:00
if ( sImageName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("info")) )
{
xRet = InfoBox::GetStandardImage().GetXGraphic();
}
2011-01-16 21:20:49 +00:00
else if ( sImageName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("warning")) )
{
xRet = WarningBox::GetStandardImage().GetXGraphic();
}
2011-01-16 21:20:49 +00:00
else if ( sImageName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("error")) )
{
xRet = ErrorBox::GetStandardImage().GetXGraphic();
}
2011-01-16 21:20:49 +00:00
else if ( sImageName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("query")) )
{
xRet = QueryBox::GetStandardImage().GetXGraphic();
}
}
return xRet;
}
// ------------------------------------------------------------------------------
uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadBitmap( const uno::Reference< awt::XBitmap >& xBtm ) const
{
uno::Reference< ::graphic::XGraphic > xRet;
uno::Sequence< sal_Int8 > aBmpSeq( xBtm->getDIB() );
uno::Sequence< sal_Int8 > aMaskSeq( xBtm->getMaskDIB() );
SvMemoryStream aBmpStream( aBmpSeq.getArray(), aBmpSeq.getLength(), STREAM_READ );
Bitmap aBmp;
aBmpStream >> aBmp;
BitmapEx aBmpEx;
if( aMaskSeq.getLength() )
{
SvMemoryStream aMaskStream( aMaskSeq.getArray(), aMaskSeq.getLength(), STREAM_READ );
Bitmap aMask;
aMaskStream >> aMask;
aBmpEx = BitmapEx( aBmp, aMask );
}
else
aBmpEx = BitmapEx( aBmp );
if( !aBmpEx.IsEmpty() )
{
::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic;
pUnoGraphic->init( aBmpEx );
xRet = pUnoGraphic;
}
return xRet;
}
// ------------------------------------------------------------------------------
uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadResource( const ::rtl::OUString& rResourceURL ) const
{
uno::Reference< ::graphic::XGraphic > xRet;
sal_Int32 nIndex = 0;
if( ( 0 == rResourceURL.getToken( 0, '/', nIndex ).compareToAscii( "private:resource" ) ) )
{
ByteString aResMgrName( String( rResourceURL.getToken( 0, '/', nIndex ) ), RTL_TEXTENCODING_ASCII_US );
2004-06-30 09:22:18 +00:00
ResMgr* pResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() );
if( pResMgr )
{
const ::rtl::OUString aResourceType( rResourceURL.getToken( 0, '/', nIndex ) );
const ResId aResId( rResourceURL.getToken( 0, '/', nIndex ).toInt32(), *pResMgr );
if( aResourceType.getLength() )
{
BitmapEx aBmpEx;
if( ( 0 == aResourceType.compareToAscii( "bitmap" ) ) ||
( 0 == aResourceType.compareToAscii( "bitmapex" ) ) )
{
aResId.SetRT( RSC_BITMAP );
if( pResMgr->IsAvailable( aResId ) )
{
aBmpEx = BitmapEx( aResId );
}
}
else if( 0 == aResourceType.compareToAscii( "image" ) )
{
aResId.SetRT( RSC_IMAGE );
if( pResMgr->IsAvailable( aResId ) )
{
const Image aImage( aResId );
aBmpEx = aImage.GetBitmapEx();
}
}
else if( 0 == aResourceType.compareToAscii( "imagelist" ) )
{
aResId.SetRT( RSC_IMAGELIST );
if( pResMgr->IsAvailable( aResId ) )
{
const ImageList aImageList( aResId );
sal_Int32 nImageId = ( nIndex > -1 ) ? rResourceURL.getToken( 0, '/', nIndex ).toInt32() : 0;
if( 0 < nImageId )
{
const Image aImage( aImageList.GetImage( sal::static_int_cast< sal_uInt16 >(nImageId) ) );
aBmpEx = aImage.GetBitmapEx();
}
else
{
aBmpEx = aImageList.GetAsHorizontalStrip();
}
}
}
if( !aBmpEx.IsEmpty() )
{
::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic;
pUnoGraphic->init( aBmpEx );
xRet = pUnoGraphic;
}
}
delete pResMgr;
}
}
return xRet;
}
// ------------------------------------------------------------------------------
uno::Reference< beans::XPropertySet > SAL_CALL GraphicProvider::queryGraphicDescriptor( const uno::Sequence< beans::PropertyValue >& rMediaProperties )
throw ( io::IOException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
{
uno::Reference< beans::XPropertySet > xRet;
::rtl::OUString aURL;
uno::Reference< io::XInputStream > xIStm;
uno::Reference< awt::XBitmap >xBtm;
for( sal_Int32 i = 0; ( i < rMediaProperties.getLength() ) && !xRet.is(); ++i )
{
const ::rtl::OUString aName( rMediaProperties[ i ].Name );
const uno::Any aValue( rMediaProperties[ i ].Value );
if( COMPARE_EQUAL == aName.compareToAscii( "URL" ) )
{
aValue >>= aURL;
}
else if( COMPARE_EQUAL == aName.compareToAscii( "InputStream" ) )
{
aValue >>= xIStm;
}
else if( COMPARE_EQUAL == aName.compareToAscii( "Bitmap" ) )
{
aValue >>= xBtm;
}
}
if( xIStm.is() )
{
GraphicDescriptor* pDescriptor = new GraphicDescriptor;
pDescriptor->init( xIStm, aURL );
xRet = pDescriptor;
}
else if( aURL.getLength() )
{
uno::Reference< ::graphic::XGraphic > xGraphic( implLoadMemory( aURL ) );
if( !xGraphic.is() )
xGraphic = implLoadResource( aURL );
CWS-TOOLING: integrate CWS dba31e 2008-11-19 12:36:23 +0100 msc r263980 : i96104 2008-11-19 12:31:19 +0100 msc r263979 : i96104 2008-11-19 12:21:55 +0100 msc r263977 : i96104 2008-11-19 12:18:53 +0100 msc r263976 : i96104 2008-11-18 09:09:45 +0100 oj r263746 : disable color entry when area is set 2008-11-18 08:37:52 +0100 oj r263741 : #remove sub report entry 2008-11-17 11:20:25 +0100 fs r263708 : #i10000# 2008-11-17 11:06:52 +0100 fs r263706 : minimal version now is 3.1 2008-11-12 22:25:59 +0100 fs r263621 : #i96150# 2008-11-12 22:20:02 +0100 fs r263620 : rebased to m34 2008-11-12 21:39:41 +0100 fs r263618 : MANUAL REBASE: rebase CWS dba31d to DEV300_m34 2008-11-12 13:54:58 +0100 fs r263597 : #i96134# MediaDescriptor.URL is to be preferred over MediaDescriptor.FileName. Nonetheless, ensure both are handled 2008-11-12 13:53:40 +0100 fs r263596 : #i96134# re-enabled the code for #i41897#, a better fix is to come 2008-11-12 12:48:21 +0100 fs r263585 : #i96134# disable saving URLs of file-base databases relatively 2008-11-11 16:11:11 +0100 msc r263566 : #i96104# 2008-11-05 09:09:47 +0100 oj r263342 : #i88727# color noe added 2008-11-05 08:41:43 +0100 oj r263341 : #i77916# zoom added 2008-11-04 21:24:15 +0100 fs r263339 : disposing: call disposeAndClear without own mutex locked - some of our listeners insist on locking the SolarMutex, which sometimes led to deadlocks on the complex test cases 2008-11-04 21:23:15 +0100 fs r263338 : remove SolarMutex locking - this happned in CWS dba31c (in the CVS version), which this CWS was created from, but seems to got lost during resync 2008-11-04 20:49:50 +0100 fs r263335 : docu formatting 2008-11-04 20:06:39 +0100 fs r263334 : #i95826# use m_aMutex, not a DocumentGuard (wrongly resolved merge conflicts) 2008-11-04 17:36:29 +0100 fs r263332 : #i92688# properly revoke as XEventListener from m_xActiveController when disposing 2008-11-04 14:49:34 +0100 fs r263324 : #i92322# enable Input Required if EmptyIsNULL does not exist at the control 2008-10-31 11:10:04 +0100 oj r262857 : merge from cvs to svn 2008-10-31 09:46:45 +0100 oj r262853 : merge from cvs to svn 2008-10-31 08:46:37 +0100 oj r262849 : merge from cvs to svn 2008-10-31 08:44:24 +0100 oj r262848 : merge from cvs to svn 2008-10-31 08:43:33 +0100 oj r262847 : merge from cvs to svn 2008-10-31 08:42:28 +0100 oj r262846 : merge from cvs to svn 2008-10-31 08:41:58 +0100 oj r262845 : merge from cvs to svn 2008-10-31 08:41:32 +0100 oj r262844 : merge from cvs to svn 2008-10-28 12:19:50 +0100 oj r262733 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:42 +0100 oj r262732 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:36 +0100 oj r262731 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:31 +0100 oj r262730 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:22 +0100 oj r262729 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:18 +0100 oj r262728 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:10 +0100 oj r262727 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:06 +0100 oj r262726 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:05 +0100 oj r262725 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:01 +0100 oj r262724 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:50 +0100 oj r262723 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:41 +0100 oj r262722 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:40 +0100 oj r262721 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:27 +0100 oj r262720 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:10 +0100 oj r262719 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:01 +0100 oj r262718 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:17:39 +0100 oj r262717 : #iXXXXX#: migrate CWS dba31e to SVN
2008-12-01 12:31:27 +00:00
if( !xGraphic.is() )
xGraphic = implLoadGraphicObject( aURL );
if ( !xGraphic.is() )
xGraphic = implLoadRepositoryImage( aURL );
if ( !xGraphic.is() )
xGraphic = implLoadStandardImage( aURL );
if( xGraphic.is() )
{
xRet = uno::Reference< beans::XPropertySet >( xGraphic, uno::UNO_QUERY );
}
else
{
GraphicDescriptor* pDescriptor = new GraphicDescriptor;
pDescriptor->init( aURL );
xRet = pDescriptor;
}
}
else if( xBtm.is() )
{
uno::Reference< ::graphic::XGraphic > xGraphic( implLoadBitmap( xBtm ) );
if( xGraphic.is() )
xRet = uno::Reference< beans::XPropertySet >( xGraphic, uno::UNO_QUERY );
}
return xRet;
}
// ------------------------------------------------------------------------------
uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( const uno::Sequence< ::beans::PropertyValue >& rMediaProperties )
throw ( io::IOException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
{
uno::Reference< ::graphic::XGraphic > xRet;
String aPath;
SvStream* pIStm = NULL;
uno::Reference< io::XInputStream > xIStm;
uno::Reference< awt::XBitmap >xBtm;
for( sal_Int32 i = 0; ( i < rMediaProperties.getLength() ) && !pIStm && !xRet.is(); ++i )
{
const ::rtl::OUString aName( rMediaProperties[ i ].Name );
const uno::Any aValue( rMediaProperties[ i ].Value );
if( COMPARE_EQUAL == aName.compareToAscii( "URL" ) )
{
::rtl::OUString aURL;
aValue >>= aURL;
aPath = aURL;
}
else if( COMPARE_EQUAL == aName.compareToAscii( "InputStream" ) )
{
aValue >>= xIStm;
}
else if( COMPARE_EQUAL == aName.compareToAscii( "Bitmap" ) )
{
aValue >>= xBtm;
}
}
if( xIStm.is() )
{
pIStm = ::utl::UcbStreamHelper::CreateStream( xIStm );
}
else if( aPath.Len() )
{
xRet = implLoadMemory( aPath );
CWS-TOOLING: integrate CWS dba31e 2008-11-19 12:36:23 +0100 msc r263980 : i96104 2008-11-19 12:31:19 +0100 msc r263979 : i96104 2008-11-19 12:21:55 +0100 msc r263977 : i96104 2008-11-19 12:18:53 +0100 msc r263976 : i96104 2008-11-18 09:09:45 +0100 oj r263746 : disable color entry when area is set 2008-11-18 08:37:52 +0100 oj r263741 : #remove sub report entry 2008-11-17 11:20:25 +0100 fs r263708 : #i10000# 2008-11-17 11:06:52 +0100 fs r263706 : minimal version now is 3.1 2008-11-12 22:25:59 +0100 fs r263621 : #i96150# 2008-11-12 22:20:02 +0100 fs r263620 : rebased to m34 2008-11-12 21:39:41 +0100 fs r263618 : MANUAL REBASE: rebase CWS dba31d to DEV300_m34 2008-11-12 13:54:58 +0100 fs r263597 : #i96134# MediaDescriptor.URL is to be preferred over MediaDescriptor.FileName. Nonetheless, ensure both are handled 2008-11-12 13:53:40 +0100 fs r263596 : #i96134# re-enabled the code for #i41897#, a better fix is to come 2008-11-12 12:48:21 +0100 fs r263585 : #i96134# disable saving URLs of file-base databases relatively 2008-11-11 16:11:11 +0100 msc r263566 : #i96104# 2008-11-05 09:09:47 +0100 oj r263342 : #i88727# color noe added 2008-11-05 08:41:43 +0100 oj r263341 : #i77916# zoom added 2008-11-04 21:24:15 +0100 fs r263339 : disposing: call disposeAndClear without own mutex locked - some of our listeners insist on locking the SolarMutex, which sometimes led to deadlocks on the complex test cases 2008-11-04 21:23:15 +0100 fs r263338 : remove SolarMutex locking - this happned in CWS dba31c (in the CVS version), which this CWS was created from, but seems to got lost during resync 2008-11-04 20:49:50 +0100 fs r263335 : docu formatting 2008-11-04 20:06:39 +0100 fs r263334 : #i95826# use m_aMutex, not a DocumentGuard (wrongly resolved merge conflicts) 2008-11-04 17:36:29 +0100 fs r263332 : #i92688# properly revoke as XEventListener from m_xActiveController when disposing 2008-11-04 14:49:34 +0100 fs r263324 : #i92322# enable Input Required if EmptyIsNULL does not exist at the control 2008-10-31 11:10:04 +0100 oj r262857 : merge from cvs to svn 2008-10-31 09:46:45 +0100 oj r262853 : merge from cvs to svn 2008-10-31 08:46:37 +0100 oj r262849 : merge from cvs to svn 2008-10-31 08:44:24 +0100 oj r262848 : merge from cvs to svn 2008-10-31 08:43:33 +0100 oj r262847 : merge from cvs to svn 2008-10-31 08:42:28 +0100 oj r262846 : merge from cvs to svn 2008-10-31 08:41:58 +0100 oj r262845 : merge from cvs to svn 2008-10-31 08:41:32 +0100 oj r262844 : merge from cvs to svn 2008-10-28 12:19:50 +0100 oj r262733 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:42 +0100 oj r262732 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:36 +0100 oj r262731 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:31 +0100 oj r262730 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:22 +0100 oj r262729 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:18 +0100 oj r262728 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:10 +0100 oj r262727 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:06 +0100 oj r262726 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:05 +0100 oj r262725 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:01 +0100 oj r262724 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:50 +0100 oj r262723 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:41 +0100 oj r262722 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:40 +0100 oj r262721 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:27 +0100 oj r262720 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:10 +0100 oj r262719 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:01 +0100 oj r262718 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:17:39 +0100 oj r262717 : #iXXXXX#: migrate CWS dba31e to SVN
2008-12-01 12:31:27 +00:00
if( !xRet.is() )
xRet = implLoadGraphicObject( aPath );
if( !xRet.is() )
xRet = implLoadResource( aPath );
if ( !xRet.is() )
xRet = implLoadRepositoryImage( aPath );
if ( !xRet.is() )
xRet = implLoadStandardImage( aPath );
if( !xRet.is() )
pIStm = ::utl::UcbStreamHelper::CreateStream( aPath, STREAM_READ );
}
else if( xBtm.is() )
{
xRet = implLoadBitmap( xBtm );
}
if( pIStm )
{
::GraphicFilter* pFilter = ::GraphicFilter::GetGraphicFilter();
if( pFilter )
{
::Graphic aVCLGraphic;
if( ( pFilter->ImportGraphic( aVCLGraphic, aPath, *pIStm ) == GRFILTER_OK ) &&
( aVCLGraphic.GetType() != GRAPHIC_NONE ) )
{
::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic;
pUnoGraphic->init( aVCLGraphic );
xRet = pUnoGraphic;
}
}
delete pIStm;
}
return xRet;
}
void ImplCalculateCropRect( ::Graphic& rGraphic, const text::GraphicCrop& rGraphicCropLogic, Rectangle& rGraphicCropPixel )
{
if ( rGraphicCropLogic.Left || rGraphicCropLogic.Top || rGraphicCropLogic.Right || rGraphicCropLogic.Bottom )
{
Size aSourceSizePixel( rGraphic.GetSizePixel() );
if ( aSourceSizePixel.Width() && aSourceSizePixel.Height() )
{
if ( rGraphicCropLogic.Left || rGraphicCropLogic.Top || rGraphicCropLogic.Right || rGraphicCropLogic.Bottom )
{
Size aSize100thMM( 0, 0 );
if( rGraphic.GetPrefMapMode().GetMapUnit() != MAP_PIXEL )
{
aSize100thMM = OutputDevice::LogicToLogic( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode(), MAP_100TH_MM );
}
else
{
aSize100thMM = Application::GetDefaultDevice()->PixelToLogic( rGraphic.GetPrefSize(), MAP_100TH_MM );
}
if ( aSize100thMM.Width() && aSize100thMM.Height() )
{
double fSourceSizePixelWidth = static_cast<double>(aSourceSizePixel.Width());
double fSourceSizePixelHeight= static_cast<double>(aSourceSizePixel.Height());
rGraphicCropPixel.Left() = static_cast< sal_Int32 >((fSourceSizePixelWidth * rGraphicCropLogic.Left ) / aSize100thMM.Width());
rGraphicCropPixel.Top() = static_cast< sal_Int32 >((fSourceSizePixelHeight * rGraphicCropLogic.Top ) / aSize100thMM.Height());
rGraphicCropPixel.Right() = static_cast< sal_Int32 >(( fSourceSizePixelWidth * ( aSize100thMM.Width() - rGraphicCropLogic.Right ) ) / aSize100thMM.Width() );
rGraphicCropPixel.Bottom() = static_cast< sal_Int32 >(( fSourceSizePixelHeight * ( aSize100thMM.Height() - rGraphicCropLogic.Bottom ) ) / aSize100thMM.Height() );
}
}
}
}
}
void ImplApplyBitmapScaling( ::Graphic& rGraphic, sal_Int32 nPixelWidth, sal_Int32 nPixelHeight )
{
if ( nPixelWidth && nPixelHeight )
{
BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
MapMode aPrefMapMode( aBmpEx.GetPrefMapMode() );
Size aPrefSize( aBmpEx.GetPrefSize() );
aBmpEx.Scale( Size( nPixelWidth, nPixelHeight ) );
aBmpEx.SetPrefMapMode( aPrefMapMode );
aBmpEx.SetPrefSize( aPrefSize );
rGraphic = aBmpEx;
}
}
void ImplApplyBitmapResolution( ::Graphic& rGraphic, sal_Int32 nImageResolution, const Size& rVisiblePixelSize, const awt::Size& rLogicalSize )
{
if ( nImageResolution && rLogicalSize.Width && rLogicalSize.Height )
{
const double fImageResolution = static_cast<double>( nImageResolution );
const double fSourceDPIX = ( static_cast<double>(rVisiblePixelSize.Width()) * 2540.0 ) / static_cast<double>(rLogicalSize.Width);
const double fSourceDPIY = ( static_cast<double>(rVisiblePixelSize.Height()) * 2540.0 ) / static_cast<double>(rLogicalSize.Height);
const sal_Int32 nSourcePixelWidth( rGraphic.GetSizePixel().Width() );
const sal_Int32 nSourcePixelHeight( rGraphic.GetSizePixel().Height() );
const double fSourcePixelWidth = static_cast<double>( nSourcePixelWidth );
const double fSourcePixelHeight= static_cast<double>( nSourcePixelHeight );
sal_Int32 nDestPixelWidth = nSourcePixelWidth;
sal_Int32 nDestPixelHeight = nSourcePixelHeight;
// check, if the bitmap DPI exceeds the maximum DPI
if( fSourceDPIX > fImageResolution )
{
nDestPixelWidth = static_cast<sal_Int32>(( fSourcePixelWidth * fImageResolution ) / fSourceDPIX);
if ( !nDestPixelWidth || ( nDestPixelWidth > nSourcePixelWidth ) )
nDestPixelWidth = nSourcePixelWidth;
}
if ( fSourceDPIY > fImageResolution )
{
nDestPixelHeight= static_cast<sal_Int32>(( fSourcePixelHeight* fImageResolution ) / fSourceDPIY);
if ( !nDestPixelHeight || ( nDestPixelHeight > nSourcePixelHeight ) )
nDestPixelHeight = nSourcePixelHeight;
}
if ( ( nDestPixelWidth != nSourcePixelWidth ) || ( nDestPixelHeight != nSourcePixelHeight ) )
ImplApplyBitmapScaling( rGraphic, nDestPixelWidth, nDestPixelHeight );
}
}
void ImplApplyFilterData( ::Graphic& rGraphic, uno::Sequence< beans::PropertyValue >& rFilterData )
{
/* this method applies following attributes to the graphic, in the first step the
cropping area (logical size in 100thmm) is applied, in the second step the resolution
is applied, in the third step the graphic is scaled to the corresponding pixelsize.
if a parameter value is zero or not available the corresponding step will be skipped */
sal_Int32 nPixelWidth = 0;
sal_Int32 nPixelHeight= 0;
sal_Int32 nImageResolution = 0;
awt::Size aLogicalSize( 0, 0 );
text::GraphicCrop aCropLogic( 0, 0, 0, 0 );
sal_Bool bRemoveCropArea = sal_True;
for( sal_Int32 i = 0; i < rFilterData.getLength(); ++i )
{
const ::rtl::OUString aName( rFilterData[ i ].Name );
const uno::Any aValue( rFilterData[ i ].Value );
if( COMPARE_EQUAL == aName.compareToAscii( "PixelWidth" ) )
aValue >>= nPixelWidth;
else if( COMPARE_EQUAL == aName.compareToAscii( "PixelHeight" ) )
aValue >>= nPixelHeight;
else if( COMPARE_EQUAL == aName.compareToAscii( "LogicalSize" ) )
aValue >>= aLogicalSize;
else if (COMPARE_EQUAL == aName.compareToAscii( "GraphicCropLogic" ) )
aValue >>= aCropLogic;
else if (COMPARE_EQUAL == aName.compareToAscii( "RemoveCropArea" ) )
aValue >>= bRemoveCropArea;
else if (COMPARE_EQUAL == aName.compareToAscii( "ImageResolution" ) )
aValue >>= nImageResolution;
}
if ( rGraphic.GetType() == GRAPHIC_BITMAP )
{
Rectangle aCropPixel( Point( 0, 0 ), rGraphic.GetSizePixel() );
ImplCalculateCropRect( rGraphic, aCropLogic, aCropPixel );
if ( bRemoveCropArea )
{
BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
aBmpEx.Crop( aCropPixel );
rGraphic = aBmpEx;
}
Size aVisiblePixelSize( bRemoveCropArea ? rGraphic.GetSizePixel() : aCropPixel.GetSize() );
ImplApplyBitmapResolution( rGraphic, nImageResolution, aVisiblePixelSize, aLogicalSize );
ImplApplyBitmapScaling( rGraphic, nPixelWidth, nPixelHeight );
}
else if ( ( rGraphic.GetType() == GRAPHIC_GDIMETAFILE ) && nImageResolution )
{
VirtualDevice aDummyVDev;
GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
Size aMtfSize( aDummyVDev.LogicToLogic( aMtf.GetPrefSize(), aMtf.GetPrefMapMode(), MAP_100TH_MM ) );
if ( aMtfSize.Width() && aMtfSize.Height() )
{
MapMode aNewMapMode( MAP_100TH_MM );
aNewMapMode.SetScaleX( static_cast< double >( aLogicalSize.Width ) / static_cast< double >( aMtfSize.Width() ) );
aNewMapMode.SetScaleY( static_cast< double >( aLogicalSize.Height ) / static_cast< double >( aMtfSize.Height() ) );
aDummyVDev.EnableOutput( sal_False );
aDummyVDev.SetMapMode( aNewMapMode );
for( sal_uInt32 i = 0, nObjCount = aMtf.GetActionCount(); i < nObjCount; i++ )
{
MetaAction* pAction = aMtf.GetAction( i );
switch( pAction->GetType() )
{
// only optimizing common bitmap actions:
case( META_MAPMODE_ACTION ):
{
const_cast< MetaAction* >( pAction )->Execute( &aDummyVDev );
break;
}
case( META_PUSH_ACTION ):
{
const MetaPushAction* pA = (const MetaPushAction*)pAction;
aDummyVDev.Push( pA->GetFlags() );
break;
}
case( META_POP_ACTION ):
{
aDummyVDev.Pop();
break;
}
case( META_BMPSCALE_ACTION ):
case( META_BMPEXSCALE_ACTION ):
{
BitmapEx aBmpEx;
Point aPos;
Size aSize;
if ( pAction->GetType() == META_BMPSCALE_ACTION )
{
MetaBmpScaleAction* pScaleAction = dynamic_cast< MetaBmpScaleAction* >( pAction );
aBmpEx = pScaleAction->GetBitmap();
aPos = pScaleAction->GetPoint();
aSize = pScaleAction->GetSize();
}
else
{
MetaBmpExScaleAction* pScaleAction = dynamic_cast< MetaBmpExScaleAction* >( pAction );
aBmpEx = pScaleAction->GetBitmapEx();
aPos = pScaleAction->GetPoint();
aSize = pScaleAction->GetSize();
}
::Graphic aGraphic( aBmpEx );
const Size aSize100thmm( aDummyVDev.LogicToPixel( aSize ) );
Size aSize100thmm2( aDummyVDev.PixelToLogic( aSize100thmm, MAP_100TH_MM ) );
ImplApplyBitmapResolution( aGraphic, nImageResolution,
aGraphic.GetSizePixel(), awt::Size( aSize100thmm2.Width(), aSize100thmm2.Height() ) );
MetaAction* pNewAction;
if ( pAction->GetType() == META_BMPSCALE_ACTION )
pNewAction = new MetaBmpScaleAction ( aPos, aSize, aGraphic.GetBitmap() );
else
pNewAction = new MetaBmpExScaleAction( aPos, aSize, aGraphic.GetBitmapEx() );
aMtf.ReplaceAction( pNewAction, i );
pAction->Delete();
break;
}
default:
case( META_BMP_ACTION ):
case( META_BMPSCALEPART_ACTION ):
case( META_BMPEX_ACTION ):
case( META_BMPEXSCALEPART_ACTION ):
case( META_MASK_ACTION ):
case( META_MASKSCALE_ACTION ):
break;
}
}
rGraphic = aMtf;
}
}
}
// ------------------------------------------------------------------------------
void SAL_CALL GraphicProvider::storeGraphic( const uno::Reference< ::graphic::XGraphic >& rxGraphic, const uno::Sequence< beans::PropertyValue >& rMediaProperties )
throw ( io::IOException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
{
SvStream* pOStm = NULL;
String aPath;
sal_Int32 i;
for( i = 0; ( i < rMediaProperties.getLength() ) && !pOStm; ++i )
{
const ::rtl::OUString aName( rMediaProperties[ i ].Name );
const uno::Any aValue( rMediaProperties[ i ].Value );
if( COMPARE_EQUAL == aName.compareToAscii( "URL" ) )
{
::rtl::OUString aURL;
aValue >>= aURL;
pOStm = ::utl::UcbStreamHelper::CreateStream( aURL, STREAM_WRITE | STREAM_TRUNC );
aPath = aURL;
}
else if( COMPARE_EQUAL == aName.compareToAscii( "OutputStream" ) )
{
uno::Reference< io::XStream > xOStm;
aValue >>= xOStm;
if( xOStm.is() )
pOStm = ::utl::UcbStreamHelper::CreateStream( xOStm );
}
}
if( pOStm )
{
uno::Sequence< beans::PropertyValue > aFilterDataSeq;
const char* pFilterShortName = NULL;
for( i = 0; i < rMediaProperties.getLength(); ++i )
{
const ::rtl::OUString aName( rMediaProperties[ i ].Name );
const uno::Any aValue( rMediaProperties[ i ].Value );
if( COMPARE_EQUAL == aName.compareToAscii( "FilterData" ) )
{
aValue >>= aFilterDataSeq;
}
else if( COMPARE_EQUAL == aName.compareToAscii( "MimeType" ) )
{
::rtl::OUString aMimeType;
aValue >>= aMimeType;
if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_BMP ) )
pFilterShortName = "bmp";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_EPS ) )
pFilterShortName = "eps";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_GIF ) )
pFilterShortName = "gif";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_JPG ) )
pFilterShortName = "jpg";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_MET ) )
pFilterShortName = "met";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_PNG ) )
pFilterShortName = "png";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_PCT ) )
pFilterShortName = "pct";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_PBM ) )
pFilterShortName = "pbm";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_PGM ) )
pFilterShortName = "pgm";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_PPM ) )
pFilterShortName = "ppm";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_RAS ) )
pFilterShortName = "ras";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_SVM ) )
pFilterShortName = "svm";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_TIF ) )
pFilterShortName = "tif";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_EMF ) )
pFilterShortName = "emf";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_WMF ) )
pFilterShortName = "wmf";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_XPM ) )
pFilterShortName = "xpm";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_SVG ) )
pFilterShortName = "svg";
else if( COMPARE_EQUAL == aMimeType.compareToAscii( MIMETYPE_VCLGRAPHIC ) )
pFilterShortName = MIMETYPE_VCLGRAPHIC;
}
}
if( pFilterShortName )
{
::GraphicFilter* pFilter = ::GraphicFilter::GetGraphicFilter();
if( pFilter )
{
const uno::Reference< XInterface > xIFace( rxGraphic, uno::UNO_QUERY );
const ::Graphic* pGraphic = ::unographic::Graphic::getImplementation( xIFace );
if( pGraphic && ( pGraphic->GetType() != GRAPHIC_NONE ) )
{
::Graphic aGraphic( *pGraphic );
ImplApplyFilterData( aGraphic, aFilterDataSeq );
/* sj: using a temporary memory stream, because some graphic filters are seeking behind
stream end (which leads to an invalid argument exception then). */
SvMemoryStream aMemStrm;
aMemStrm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
if( 0 == strcmp( pFilterShortName, MIMETYPE_VCLGRAPHIC ) )
aMemStrm << aGraphic;
else
{
pFilter->ExportGraphic( aGraphic, aPath, aMemStrm,
pFilter->GetExportFormatNumberForShortName( ::rtl::OUString::createFromAscii( pFilterShortName ) ),
( aFilterDataSeq.getLength() ? &aFilterDataSeq : NULL ) );
}
aMemStrm.Seek( STREAM_SEEK_TO_END );
pOStm->Write( aMemStrm.GetData(), aMemStrm.Tell() );
}
}
}
delete pOStm;
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */