basic/source/uno/dlgcont.cxx | 21 +++- dbaccess/source/core/dataaccess/databasedocument.cxx | 21 +++- include/vcl/GraphicObject.hxx | 26 ++++-- vcl/source/graphic/GraphicObject.cxx | 80 +++++++++++-------- 4 files changed, 96 insertions(+), 52 deletions(-)
New commits: commit d775ef360168271f429466bbc174ae7dec402f1d Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Thu Mar 15 09:57:46 2018 +0900 change recursive ImageURL prop. search to use XGraphic In two cases we need to traverse and gather all ImageURL properties and get the URL string and store the graphic content to a storage (like we do in xmloff filter). ImageURL property can now only store external URL and Graphic stores the embedded XGraphic, so this was changed to look into Graphic property first and then ImageURL. We also don't gather URL sting anymore so they need to be loaded to XGraphic when gathering them. Change-Id: I5f3f4be2b403b9589d72b8733df0c97109f2b65d Reviewed-on: https://gerrit.libreoffice.org/51308 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/basic/source/uno/dlgcont.cxx b/basic/source/uno/dlgcont.cxx index ac347db045de..24ecf29d4d22 100644 --- a/basic/source/uno/dlgcont.cxx +++ b/basic/source/uno/dlgcont.cxx @@ -31,6 +31,7 @@ #include <com/sun/star/resource/StringResourceWithStorage.hpp> #include <com/sun/star/resource/StringResourceWithLocation.hpp> #include <com/sun/star/document/GraphicObjectResolver.hpp> +#include <com/sun/star/document/XGraphicStorageHandler.hpp> #include <dlgcont.hxx> #include <comphelper/fileformat.h> #include <comphelper/processfactory.hxx> @@ -236,17 +237,21 @@ void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< e mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", mxContext), UNO_QUERY ); ::xmlscript::importDialogModel( xInput, xDialogModel, mxContext, mxOwnerDocument ); - std::vector< OUString > vEmbeddedImageURLs; - GraphicObject::InspectForGraphicObjectImageURL( Reference<XInterface>(xDialogModel, UNO_QUERY), vEmbeddedImageURLs ); - if ( !vEmbeddedImageURLs.empty() ) + std::vector<uno::Reference<graphic::XGraphic>> vxGraphicList; + vcl::graphic::SearchForGraphics(Reference<XInterface>(xDialogModel, UNO_QUERY), vxGraphicList); + if (!vxGraphicList.empty()) { // Export the images to the storage - Reference< document::XGraphicObjectResolver > xGraphicResolver = - document::GraphicObjectResolver::createWithStorage( mxContext, xStorage ); - if ( xGraphicResolver.is() ) + Reference<document::XGraphicObjectResolver> xGraphicResolver; + xGraphicResolver.set(document::GraphicObjectResolver::createWithStorage(mxContext, xStorage)); + Reference<document::XGraphicStorageHandler> xGraphicStorageHandler; + xGraphicStorageHandler.set(xGraphicResolver, uno::UNO_QUERY); + if (xGraphicStorageHandler.is()) { - for ( const OUString& rURL : vEmbeddedImageURLs ) - xGraphicResolver->resolveGraphicObjectURL( rURL ); + for (uno::Reference<graphic::XGraphic> const & rxGraphic : vxGraphicList) + { + xGraphicStorageHandler->saveGraphic(rxGraphic); + } } } } diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index b8c15f49df88..27a2114ae9fb 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -61,6 +61,7 @@ #include <com/sun/star/awt/XControl.hpp> #include <com/sun/star/awt/DialogProvider.hpp> #include <com/sun/star/document/XGraphicObjectResolver.hpp> +#include <com/sun/star/document/XGraphicStorageHandler.hpp> #include <comphelper/documentconstants.hxx> #include <comphelper/enumhelper.hxx> @@ -355,7 +356,7 @@ void lcl_uglyHackToStoreDialogeEmbedImages( const Reference< XStorageBasedLibrar Sequence< OUString > sLibraries = xDlgCont->getElementNames(); Reference< XStorage > xTmpPic = xStorage->openStorageElement( "tempPictures", ElementModes::READWRITE ); - std::vector< OUString > vEmbedImgUrls; + std::vector<uno::Reference<graphic::XGraphic>> vxGraphicList; for ( sal_Int32 i=0; i < sLibraries.getLength(); ++i ) { OUString sLibrary( sLibraries[ i ] ); @@ -374,21 +375,25 @@ void lcl_uglyHackToStoreDialogeEmbedImages( const Reference< XStorageBasedLibrar Reference< css::awt::XControl > xDialog( xDlgPrv->createDialog( sDialogUrl ), UNO_QUERY ); Reference< XInterface > xModel( xDialog->getModel() ); - GraphicObject::InspectForGraphicObjectImageURL( xModel, vEmbedImgUrls ); + vcl::graphic::SearchForGraphics(xModel, vxGraphicList); } } } // if we have any image urls, make sure we copy the associated images into tempPictures - if ( !vEmbedImgUrls.empty() ) + if (!vxGraphicList.empty()) { // Export the images to the storage - Reference< XGraphicObjectResolver > xGraphicResolver = GraphicObjectResolver::createWithStorage(rxContext, xTmpPic); - if ( xGraphicResolver.is() ) + uno::Reference<document::XGraphicObjectResolver> xGraphicResolver; + xGraphicResolver.set(GraphicObjectResolver::createWithStorage(rxContext, xTmpPic)); + uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler; + xGraphicStorageHandler.set(xGraphicResolver, uno::UNO_QUERY); + if (xGraphicStorageHandler.is()) { - for ( const OUString& rURL : vEmbedImgUrls ) - xGraphicResolver->resolveGraphicObjectURL( rURL ); + for (uno::Reference<graphic::XGraphic> const & rxGraphic : vxGraphicList) + { + xGraphicStorageHandler->saveGraphic(rxGraphic); + } } - // delete old 'Pictures' storage and copy the contents of tempPictures into xStorage xStorage->removeElement( sPictures ); xTmpPic->copyElementTo( sPictures, xStorage, sPictures ); diff --git a/include/vcl/GraphicObject.hxx b/include/vcl/GraphicObject.hxx index 3025b48fee05..877df26f9289 100644 --- a/include/vcl/GraphicObject.hxx +++ b/include/vcl/GraphicObject.hxx @@ -25,6 +25,8 @@ #include <vcl/dllapi.h> #include <o3tl/typed_flags_set.hxx> +#include <com/sun/star/graphic/XGraphic.hpp> + #include <unordered_set> enum class GraphicManagerDrawFlags @@ -466,12 +468,6 @@ public: static bool isGraphicObjectUniqueIdURL(OUString const & rURL); - // will inspect an object ( e.g. a control ) for any 'ImageURL' - // properties and return these in a vector. Note: this implementation - // will cater for XNameContainer objects and deep inspect any containers - // if they exist - static void InspectForGraphicObjectImageURL( const css::uno::Reference< css::uno::XInterface >& rxIf, std::vector< OUString >& rvEmbedImgUrls ); - // create CropScaling information // fWidth, fHeight: object size // f*Crop: crop values relative to original bitmap size @@ -605,6 +601,24 @@ public: ); }; +namespace vcl +{ +namespace graphic +{ + +// Will search an object ( e.g. a control ) for any 'ImageURL' or 'Graphic' +// properties and return graphics from the properties in a vector. ImageURL +// will be loaded from the URL. +// +// Note: this implementation will cater for XNameContainer objects and deep inspect any containers +// if they exist + +VCL_DLLPUBLIC void SearchForGraphics(css::uno::Reference<css::uno::XInterface> const & rxInterface, + std::vector<css::uno::Reference<css::graphic::XGraphic>> & raGraphicList); + +} +} // end namespace vcl::graphic + #endif // INCLUDED_VCL_GRAPHICOBJECT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/graphic/GraphicObject.cxx b/vcl/source/graphic/GraphicObject.cxx index a4dbddea1cae..aa8465c76b26 100644 --- a/vcl/source/graphic/GraphicObject.cxx +++ b/vcl/source/graphic/GraphicObject.cxx @@ -34,11 +34,14 @@ #include <vcl/metaact.hxx> #include <vcl/virdev.hxx> #include <vcl/GraphicObject.hxx> +#include <vcl/GraphicLoader.hxx> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <memory> + +using namespace css; using com::sun::star::uno::Reference; using com::sun::star::uno::XInterface; using com::sun::star::uno::UNO_QUERY; @@ -46,6 +49,53 @@ using com::sun::star::uno::Sequence; using com::sun::star::container::XNameContainer; using com::sun::star::beans::XPropertySet; +namespace vcl +{ +namespace graphic +{ + +void SearchForGraphics(uno::Reference<uno::XInterface> const & xInterface, + std::vector<uno::Reference<css::graphic::XGraphic>> & raGraphicList) +{ + uno::Reference<beans::XPropertySet> xPropertySet(xInterface, UNO_QUERY); + if (xPropertySet.is()) + { + if (xPropertySet->getPropertySetInfo()->hasPropertyByName("ImageURL")) + { + OUString sURL; + xPropertySet->getPropertyValue("ImageURL") >>= sURL; + if (!sURL.isEmpty() && !GraphicObject::isGraphicObjectUniqueIdURL(sURL)) + { + Graphic aGraphic = vcl::graphic::loadFromURL(sURL); + if (aGraphic) + { + raGraphicList.push_back(aGraphic.GetXGraphic()); + } + } + } else if (xPropertySet->getPropertySetInfo()->hasPropertyByName("Graphic")) + { + uno::Reference<css::graphic::XGraphic> xGraphic; + xPropertySet->getPropertyValue("Graphic") >>= xGraphic; + if (xGraphic.is()) + { + raGraphicList.push_back(xGraphic); + } + } + } + Reference<XNameContainer> xContainer(xInterface, UNO_QUERY); + if (xContainer.is()) + { + for (OUString const & rName : xContainer->getElementNames()) + { + uno::Reference<XInterface> xInnerInterface; + xContainer->getByName(rName) >>= xInnerInterface; + SearchForGraphics(xInnerInterface, raGraphicList); + } + } +} + +}} // end namespace vcl::graphic + GraphicManager* GraphicObject::mpGlobalMgr = nullptr; struct GrfSimpleCacheObj @@ -1045,36 +1095,6 @@ bool GraphicObject::isGraphicObjectUniqueIdURL(OUString const & rURL) return rURL.startsWith(aPrefix); } -void -GraphicObject::InspectForGraphicObjectImageURL( const Reference< XInterface >& xIf, std::vector< OUString >& rvEmbedImgUrls ) -{ - static const char sImageURL[] = "ImageURL"; - Reference< XPropertySet > xProps( xIf, UNO_QUERY ); - if ( xProps.is() ) - { - - if ( xProps->getPropertySetInfo()->hasPropertyByName( sImageURL ) ) - { - OUString sURL; - xProps->getPropertyValue( sImageURL ) >>= sURL; - if ( !sURL.isEmpty() && sURL.startsWith( UNO_NAME_GRAPHOBJ_URLPREFIX ) ) - rvEmbedImgUrls.push_back( sURL ); - } - } - Reference< XNameContainer > xContainer( xIf, UNO_QUERY ); - if ( xContainer.is() ) - { - Sequence< OUString > sNames = xContainer->getElementNames(); - sal_Int32 nContainees = sNames.getLength(); - for ( sal_Int32 index = 0; index < nContainees; ++index ) - { - Reference< XInterface > xCtrl; - xContainer->getByName( sNames[ index ] ) >>= xCtrl; - InspectForGraphicObjectImageURL( xCtrl, rvEmbedImgUrls ); - } - } -} - // calculate scalings between real image size and logic object size. This // is necessary since the crop values are relative to original bitmap size basegfx::B2DVector GraphicObject::calculateCropScaling( _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits