summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-05-23 12:10:44 +0200
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-16 20:45:03 -0400
commitcda0cc8ab05718fcca75a9e18da14ce5249c8c2b (patch)
treecd9f987a19e18d44e2eef80809bdc0df985546e3
parente9f049a5c6721fd29599292de1d00be21a07a5e5 (diff)
svtools: add GraphicProvider::queryGraphics()
This allows moving the for() loop from oox to svtools when importing multiple images. That means in case later we parallelize that loop, then the performance benefit won't be restricted to oox, but also will be available for all clients of the graphic provider. Reviewed-on: https://gerrit.libreoffice.org/37945 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> (cherry picked from commit 252e524094893063e4bcc822571a14c4558e1d00) Change-Id: Icd7bd447e7ae623b0a8548e020d8f6ab38da47bb
-rw-r--r--include/cppuhelper/implbase.hxx6
-rw-r--r--include/oox/helper/graphichelper.hxx3
-rw-r--r--offapi/UnoApi_offapi.mk1
-rw-r--r--offapi/com/sun/star/graphic/XGraphicProvider2.idl47
-rw-r--r--oox/source/helper/graphichelper.cxx29
-rw-r--r--svtools/source/graphic/provider.cxx156
6 files changed, 121 insertions, 121 deletions
diff --git a/include/cppuhelper/implbase.hxx b/include/cppuhelper/implbase.hxx
index f8c8bae54d5f..0d36e9c92580 100644
--- a/include/cppuhelper/implbase.hxx
+++ b/include/cppuhelper/implbase.hxx
@@ -112,12 +112,10 @@ public:
void SAL_CALL release() throw () override { OWeakObject::release(); }
- css::uno::Sequence<css::uno::Type> SAL_CALL getTypes()
- throw (css::uno::RuntimeException, std::exception) override
+ css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
{ return WeakImplHelper_getTypes(cd::get()); }
- css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId()
- throw (css::uno::RuntimeException, std::exception) override
+ css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
{ return css::uno::Sequence<sal_Int8>(); }
};
diff --git a/include/oox/helper/graphichelper.hxx b/include/oox/helper/graphichelper.hxx
index 42d400cd4614..72d858d46018 100644
--- a/include/oox/helper/graphichelper.hxx
+++ b/include/oox/helper/graphichelper.hxx
@@ -31,6 +31,7 @@
#include <oox/helper/storagebase.hxx>
#include <rtl/ustring.hxx>
#include <sal/types.h>
+#include <com/sun/star/graphic/XGraphicProvider2.hpp>
struct WMF_EXTERNALHEADER;
@@ -158,7 +159,7 @@ private:
typedef ::std::map< OUString, css::uno::Reference< css::graphic::XGraphic > > EmbeddedGraphicMap;
css::uno::Reference< css::uno::XComponentContext > mxContext;
- css::uno::Reference< css::graphic::XGraphicProvider > mxGraphicProvider;
+ css::uno::Reference< css::graphic::XGraphicProvider2 > mxGraphicProvider;
css::uno::Reference< css::awt::XUnitConversion > mxUnitConversion;
css::awt::DeviceInfo maDeviceInfo; ///< Current output device info.
SystemPalette maSystemPalette; ///< Maps system colors (XML tokens) to RGB color values.
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index ce984d6fbd25..ea93dce1a0b7 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -2707,6 +2707,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/graphic,\
XGraphic \
XGraphicObject \
XGraphicProvider \
+ XGraphicProvider2 \
XGraphicRasterizer \
XGraphicRenderer \
XGraphicTransformer \
diff --git a/offapi/com/sun/star/graphic/XGraphicProvider2.idl b/offapi/com/sun/star/graphic/XGraphicProvider2.idl
new file mode 100644
index 000000000000..04b5f02589d5
--- /dev/null
+++ b/offapi/com/sun/star/graphic/XGraphicProvider2.idl
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef com_sun_star_graphic_XGraphicProvider2_idl
+#define com_sun_star_graphic_XGraphicProvider2_idl
+
+#include <com/sun/star/graphic/XGraphicProvider.idl>
+
+module com { module sun { module star { module graphic
+{
+
+/** This interface allows operations on multiple graphics with one method
+ call.
+ */
+interface XGraphicProvider2 : XGraphicProvider
+{
+ /** Calling this method returns XGraphic interfaces
+ that hold loaded graphics.
+
+ @param MediaPropertiesSeq
+ A sequence of sequence of property values to describe the location
+ of the graphics.
+
+ @returns
+ The XGraphic interfaces
+
+ @see XGraphicProvider::queryGraphic
+
+ @since LibreOffice 5.5
+ */
+ sequence< XGraphic > queryGraphics([in] sequence< com::sun::star::beans::PropertyValues> MediaPropertiesSeq)
+ raises( com::sun::star::io::IOException,
+ com::sun::star::lang::IllegalArgumentException,
+ com::sun::star::lang::WrappedTargetException );
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx
index faec970208eb..66a7131243d7 100644
--- a/oox/source/helper/graphichelper.cxx
+++ b/oox/source/helper/graphichelper.cxx
@@ -37,6 +37,7 @@
#include <vcl/svapp.hxx>
#include <tools/gen.hxx>
#include <comphelper/propertysequence.hxx>
+#include <comphelper/sequence.hxx>
#include "oox/helper/containerhelper.hxx"
#include "oox/helper/propertyset.hxx"
#include "oox/token/properties.hxx"
@@ -68,7 +69,7 @@ GraphicHelper::GraphicHelper( const Reference< XComponentContext >& rxContext, c
{
OSL_ENSURE( mxContext.is(), "GraphicHelper::GraphicHelper - missing component context" );
if( mxContext.is() )
- mxGraphicProvider.set( graphic::GraphicProvider::create( mxContext ) );
+ mxGraphicProvider.set( graphic::GraphicProvider::create( mxContext ), uno::UNO_QUERY );
//! TODO: get colors from system
maSystemPalette[ XML_3dDkShadow ] = 0x716F64;
@@ -266,29 +267,25 @@ Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStrea
std::vector< uno::Reference<graphic::XGraphic> > GraphicHelper::importGraphics(const std::vector< uno::Reference<io::XInputStream> >& rStreams) const
{
- std::vector< uno::Reference<graphic::XGraphic> > aRet;
+ std::vector< uno::Sequence<beans::PropertyValue> > aArgsVec;
for (const auto& rStream : rStreams)
{
- uno::Reference<graphic::XGraphic> xGraphic;
- if (rStream.is() && mxGraphicProvider.is())
+ if (rStream.is())
{
- try
- {
- uno::Sequence<beans::PropertyValue > aArgs = comphelper::InitPropertySequence(
- {
- {"InputStream", uno::makeAny(rStream)}
- });
- xGraphic = mxGraphicProvider->queryGraphic(aArgs);
- }
- catch( const uno::Exception& rException)
+ uno::Sequence<beans::PropertyValue > aArgs = comphelper::InitPropertySequence(
{
- SAL_WARN("oox", "GraphicHelper::importGraphic: queryGraphics() failed: " << rException.Message);
- }
+ {"InputStream", uno::makeAny(rStream)}
+ });
+ aArgsVec.push_back(aArgs);
}
- aRet.push_back(xGraphic);
}
+ std::vector< uno::Reference<graphic::XGraphic> > aRet;
+
+ if (mxGraphicProvider.is())
+ aRet = comphelper::sequenceToContainer< std::vector< uno::Reference<graphic::XGraphic> > >(mxGraphicProvider->queryGraphics(comphelper::containerToSequence(aArgsVec)));
+
return aRet;
}
diff --git a/svtools/source/graphic/provider.cxx b/svtools/source/graphic/provider.cxx
index 1f559d6c5e28..2cd845a7dcf7 100644
--- a/svtools/source/graphic/provider.cxx
+++ b/svtools/source/graphic/provider.cxx
@@ -33,18 +33,22 @@
#include <svl/solar.hrc>
#include <vcl/virdev.hxx>
#include <vcl/settings.hxx>
+#include <com/sun/star/awt/XBitmap.hpp>
+#include <com/sun/star/graphic/XGraphicProvider2.hpp>
#include <com/sun/star/io/XStream.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/text/GraphicCrop.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <comphelper/servicehelper.hxx>
+#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include "descriptor.hxx"
#include "graphic.hxx"
#include <rtl/ref.hxx>
#include <svtools/grfmgr.hxx>
-#include "provider.hxx"
#include <vcl/dibtools.hxx>
+#include <comphelper/sequence.hxx>
#include <memory>
using namespace com::sun::star;
@@ -53,35 +57,62 @@ namespace {
#define UNO_NAME_GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:"
-GraphicProvider::GraphicProvider()
+class GraphicProvider : public ::cppu::WeakImplHelper< css::graphic::XGraphicProvider2,
+ css::lang::XServiceInfo >
{
-}
+public:
+
+ GraphicProvider();
+
+protected:
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName() override;
+ virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
+ virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
+
+ // XTypeProvider
+ virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
+ virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
+
+ // XGraphicProvider
+ virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL queryGraphicDescriptor( const css::uno::Sequence< css::beans::PropertyValue >& MediaProperties ) override;
+ virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL queryGraphic( const css::uno::Sequence< css::beans::PropertyValue >& MediaProperties ) override;
+ virtual void SAL_CALL storeGraphic( const css::uno::Reference< css::graphic::XGraphic >& Graphic, const css::uno::Sequence< css::beans::PropertyValue >& MediaProperties ) override;
+
+ // XGraphicProvider2
+ uno::Sequence< uno::Reference<graphic::XGraphic> > SAL_CALL queryGraphics(const uno::Sequence< uno::Sequence<beans::PropertyValue> >& MediaPropertiesSeq ) override;
+
+private:
-GraphicProvider::~GraphicProvider()
+ static css::uno::Reference< css::graphic::XGraphic > implLoadMemory( const OUString& rResourceURL );
+ static css::uno::Reference< css::graphic::XGraphic > implLoadGraphicObject( const OUString& rResourceURL );
+ static css::uno::Reference< css::graphic::XGraphic > implLoadRepositoryImage( const OUString& rResourceURL );
+ static css::uno::Reference< css::graphic::XGraphic > implLoadBitmap( const css::uno::Reference< css::awt::XBitmap >& rBitmap );
+ static css::uno::Reference< css::graphic::XGraphic > implLoadStandardImage( const OUString& rResourceURL );
+};
+
+GraphicProvider::GraphicProvider()
{
}
OUString SAL_CALL GraphicProvider::getImplementationName()
- throw( uno::RuntimeException, std::exception )
{
return OUString( "com.sun.star.comp.graphic.GraphicProvider" );
}
sal_Bool SAL_CALL GraphicProvider::supportsService( const OUString& ServiceName )
- throw( uno::RuntimeException, std::exception )
{
return cppu::supportsService( this, ServiceName );
}
uno::Sequence< OUString > SAL_CALL GraphicProvider::getSupportedServiceNames()
- throw( uno::RuntimeException, std::exception )
{
uno::Sequence<OUString> aSeq { "com.sun.star.graphic.GraphicProvider" };
return aSeq;
}
uno::Sequence< uno::Type > SAL_CALL GraphicProvider::getTypes()
- throw(uno::RuntimeException, std::exception)
{
uno::Sequence< uno::Type > aTypes( 3 );
uno::Type* pTypes = aTypes.getArray();
@@ -94,7 +125,6 @@ uno::Sequence< uno::Type > SAL_CALL GraphicProvider::getTypes()
}
uno::Sequence< sal_Int8 > SAL_CALL GraphicProvider::getImplementationId()
- throw(uno::RuntimeException, std::exception)
{
return css::uno::Sequence<sal_Int8>();
}
@@ -152,8 +182,7 @@ uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadRepositoryImage(
BitmapEx aBitmap;
if ( vcl::ImageRepository::loadImage( sPathName, aBitmap, false ) )
{
- Image aImage( aBitmap );
- xRet = aImage.GetXGraphic();
+ xRet = Graphic(aBitmap).GetXGraphic();
}
}
return xRet;
@@ -170,19 +199,19 @@ uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadStandardImage( co
OUString sImageName( rResourceURL.copy( nIndex ) );
if ( sImageName == "info" )
{
- xRet = InfoBox::GetStandardImage().GetXGraphic();
+ xRet = Graphic(InfoBox::GetStandardImage().GetBitmapEx()).GetXGraphic();
}
else if ( sImageName == "warning" )
{
- xRet = WarningBox::GetStandardImage().GetXGraphic();
+ xRet = Graphic(WarningBox::GetStandardImage().GetBitmapEx()).GetXGraphic();
}
else if ( sImageName == "error" )
{
- xRet = ErrorBox::GetStandardImage().GetXGraphic();
+ xRet = Graphic(ErrorBox::GetStandardImage().GetBitmapEx()).GetXGraphic();
}
else if ( sImageName == "query" )
{
- xRet = QueryBox::GetStandardImage().GetXGraphic();
+ xRet = Graphic(QueryBox::GetStandardImage().GetBitmapEx()).GetXGraphic();
}
}
return xRet;
@@ -221,85 +250,7 @@ uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadBitmap( const uno
return xRet;
}
-
-uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadResource( const OUString& rResourceURL )
-{
- uno::Reference< ::graphic::XGraphic > xRet;
- sal_Int32 nIndex = 0;
-
- if( rResourceURL.getToken( 0, '/', nIndex ) == "private:resource" )
- {
- OString aResMgrName(OUStringToOString(
- rResourceURL.getToken(0, '/', nIndex), RTL_TEXTENCODING_ASCII_US));
-
- std::unique_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( aResMgrName.getStr(), Application::GetSettings().GetUILanguageTag() ));
-
- if( pResMgr )
- {
- const OUString aResourceType( rResourceURL.getToken( 0, '/', nIndex ) );
- const ResId aResId( rResourceURL.getToken( 0, '/', nIndex ).toInt32(), *pResMgr );
-
- if( !aResourceType.isEmpty() )
- {
- BitmapEx aBmpEx;
-
- if( aResourceType == "bitmap" || aResourceType == "bitmapex" )
- {
- aResId.SetRT( RSC_BITMAP );
-
- if( pResMgr->IsAvailable( aResId ) )
- {
- aBmpEx = BitmapEx( aResId );
- }
- }
- else if( aResourceType == "image" )
- {
- aResId.SetRT( RSC_IMAGE );
-
- if( pResMgr->IsAvailable( aResId ) )
- {
- const Image aImage( aResId );
- aBmpEx = aImage.GetBitmapEx();
- }
- }
- else if( aResourceType == "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;
- }
- }
- }
- }
-
- 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, std::exception)
{
uno::Reference< beans::XPropertySet > xRet;
@@ -338,8 +289,6 @@ uno::Reference< beans::XPropertySet > SAL_CALL GraphicProvider::queryGraphicDesc
{
uno::Reference< ::graphic::XGraphic > xGraphic( implLoadMemory( aURL ) );
if( !xGraphic.is() )
- xGraphic = implLoadResource( aURL );
- if( !xGraphic.is() )
xGraphic = implLoadGraphicObject( aURL );
if ( !xGraphic.is() )
@@ -371,7 +320,6 @@ uno::Reference< beans::XPropertySet > SAL_CALL GraphicProvider::queryGraphicDesc
uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( const uno::Sequence< ::beans::PropertyValue >& rMediaProperties )
- throw ( io::IOException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
{
uno::Reference< ::graphic::XGraphic > xRet;
OUString aPath;
@@ -443,9 +391,6 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
if( !xRet.is() )
xRet = implLoadGraphicObject( aPath );
- if( !xRet.is() )
- xRet = implLoadResource( aPath );
-
if ( !xRet.is() )
xRet = implLoadRepositoryImage( aPath );
@@ -491,6 +436,18 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
return xRet;
}
+uno::Sequence< uno::Reference<graphic::XGraphic> > SAL_CALL GraphicProvider::queryGraphics(const uno::Sequence< uno::Sequence<beans::PropertyValue> >& rMediaPropertiesSeq)
+{
+ std::vector< uno::Reference<graphic::XGraphic> > aRet;
+
+ for (const auto& rMediaProperties : rMediaPropertiesSeq)
+ {
+ aRet.push_back(queryGraphic(rMediaProperties));
+ }
+
+ return comphelper::containerToSequence(aRet);
+}
+
void ImplCalculateCropRect( ::Graphic& rGraphic, const text::GraphicCrop& rGraphicCropLogic, Rectangle& rGraphicCropPixel )
{
if ( rGraphicCropLogic.Left || rGraphicCropLogic.Top || rGraphicCropLogic.Right || rGraphicCropLogic.Bottom )
@@ -713,7 +670,6 @@ void ImplApplyFilterData( ::Graphic& rGraphic, uno::Sequence< beans::PropertyVal
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, std::exception)
{
SolarMutexGuard g;