diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-04-13 16:58:49 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-04-16 02:52:02 +0200 |
commit | 9fb7aaf570c03c8a26d763f1205fb8c890e8211a (patch) | |
tree | 8f4466b24d9fcae2da5043479a57fabc662a2c43 /vcl | |
parent | ba69036c8e889237da4bb312d7c5c94066abbfd3 (diff) |
Make linked graphic register into LinkedManager again
Change-Id: I16b162f86d6221d120f6355f9a52c1abfcd0ac73
Reviewed-on: https://gerrit.libreoffice.org/52911
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/graphic/Manager.hxx | 2 | ||||
-rw-r--r-- | vcl/source/gdi/graph.cxx | 7 | ||||
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 10 | ||||
-rw-r--r-- | vcl/source/graphic/GraphicLoader.cxx | 53 | ||||
-rw-r--r-- | vcl/source/graphic/Manager.cxx | 7 |
5 files changed, 53 insertions, 26 deletions
diff --git a/vcl/inc/graphic/Manager.hxx b/vcl/inc/graphic/Manager.hxx index ec3761534493..4b4585203639 100644 --- a/vcl/inc/graphic/Manager.hxx +++ b/vcl/inc/graphic/Manager.hxx @@ -17,6 +17,7 @@ #include <vcl/vectorgraphicdata.hxx> #include <vcl/metaact.hxx> #include <vcl/timer.hxx> +#include <vcl/GraphicExternalLink.hxx> #include <officecfg/Office/Common.hxx> #include <unotools/configmgr.hxx> @@ -62,6 +63,7 @@ public: std::shared_ptr<ImpGraphic> newInstance(const VectorGraphicDataPtr& rVectorGraphicDataPtr); std::shared_ptr<ImpGraphic> newInstance(const Animation& rAnimation); std::shared_ptr<ImpGraphic> newInstance(const GDIMetaFile& rMtf); + std::shared_ptr<ImpGraphic> newInstance(const GraphicExternalLink& rGraphicLink); }; } } // end namespace vcl::graphic diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx index cdc747eae019..91dcad7e4ae5 100644 --- a/vcl/source/gdi/graph.cxx +++ b/vcl/source/gdi/graph.cxx @@ -31,6 +31,8 @@ #include <com/sun/star/graphic/XGraphic.hpp> #include <cppuhelper/typeprovider.hxx> #include <graphic/UnoGraphic.hxx> +#include <vcl/GraphicExternalLink.hxx> + using namespace ::com::sun::star; @@ -199,6 +201,11 @@ Graphic::Graphic(Graphic&& rGraphic) { } +Graphic::Graphic(GraphicExternalLink const & rGraphicExternalLink) + : mxImpGraphic(vcl::graphic::Manager::get().newInstance(rGraphicExternalLink)) +{ +} + Graphic::Graphic(const Bitmap& rBmp) : mxImpGraphic(vcl::graphic::Manager::get().newInstance(rBmp)) { diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 13f09ee2bb9c..0f1e849183de 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -226,6 +226,16 @@ ImpGraphic::ImpGraphic(ImpGraphic&& rImpGraphic) rImpGraphic.mbDummyContext = false; } +ImpGraphic::ImpGraphic(GraphicExternalLink const & rGraphicExternalLink) : + meType ( GraphicType::Default ), + mnSizeBytes ( 0 ), + mbSwapOut ( false ), + mbDummyContext ( false ), + maGraphicExternalLink(rGraphicExternalLink), + maLastUsed (std::chrono::high_resolution_clock::now()) +{ +} + ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) : maEx ( rBitmap ), meType ( !rBitmap.IsEmpty() ? GraphicType::Bitmap : GraphicType::NONE ), diff --git a/vcl/source/graphic/GraphicLoader.cxx b/vcl/source/graphic/GraphicLoader.cxx index b07b345cb982..9c453acf0864 100644 --- a/vcl/source/graphic/GraphicLoader.cxx +++ b/vcl/source/graphic/GraphicLoader.cxx @@ -10,11 +10,9 @@ #include <vcl/GraphicLoader.hxx> -#include <comphelper/processfactory.hxx> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/graphic/GraphicProvider.hpp> -#include <com/sun/star/graphic/XGraphicProvider.hpp> -#include <com/sun/star/graphic/XGraphic.hpp> +#include <unotools/ucbstreamhelper.hxx> +#include <vcl/graphicfilter.hxx> +#include <vcl/wmf.hxx> using namespace css; @@ -22,35 +20,38 @@ namespace vcl { namespace graphic { -Graphic loadFromURL(OUString const& rURL) +Graphic loadFromURL(OUString const& rURL, sal_Int16 nExtWidth, sal_Int16 nExtHeight, + sal_Int16 nExtMapMode) { + // Define APM Header if goal height and width are defined + WmfExternal aExtHeader; + aExtHeader.xExt = nExtWidth; + aExtHeader.yExt = nExtHeight; + aExtHeader.mapMode = nExtMapMode; + WmfExternal* pExtHeader = nullptr; + if (nExtMapMode > 0) + pExtHeader = &aExtHeader; + Graphic aGraphic; - try - { - uno::Reference<css::graphic::XGraphic> xGraphic; - uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext()); - uno::Reference<css::graphic::XGraphicProvider> xProvider; - xProvider.set(css::graphic::GraphicProvider::create(xContext)); - - uno::Sequence<beans::PropertyValue> aLoadProps(1); - aLoadProps[0].Name = "URL"; - aLoadProps[0].Value <<= rURL; - - xGraphic = xProvider->queryGraphic(aLoadProps); - - if (xGraphic.is()) - aGraphic = Graphic(xGraphic); - else - aGraphic.SetDefaultType(); - aGraphic.setOriginURL(rURL); - } - catch (uno::Exception const&) + std::unique_ptr<SvStream> pInputStream; + pInputStream.reset(utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ)); + + if (pInputStream) { + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + + ErrCode nError + = rFilter.ImportGraphic(aGraphic, rURL, *pInputStream, GRFILTER_FORMAT_DONTKNOW, + nullptr, GraphicFilterImportFlags::NONE, pExtHeader); + if (nError != ERRCODE_NONE || aGraphic.GetType() == GraphicType::NONE) + return Graphic(); } return aGraphic; } + +Graphic loadFromURL(OUString const& rURL) { return loadFromURL(rURL, 0, 0, 0); } } } // end vcl::graphic diff --git a/vcl/source/graphic/Manager.cxx b/vcl/source/graphic/Manager.cxx index ee161c23d878..549b9c6d6add 100644 --- a/vcl/source/graphic/Manager.cxx +++ b/vcl/source/graphic/Manager.cxx @@ -179,6 +179,13 @@ std::shared_ptr<ImpGraphic> Manager::newInstance(const GDIMetaFile& rMetaFile) return pReturn; } +std::shared_ptr<ImpGraphic> Manager::newInstance(const GraphicExternalLink& rGraphicLink) +{ + auto pReturn = std::make_shared<ImpGraphic>(rGraphicLink); + registerGraphic(pReturn, "GraphicExternalLink"); + return pReturn; +} + void Manager::swappedIn(const ImpGraphic* pImpGraphic) { mnUsedSize += pImpGraphic->ImplGetSizeBytes(); |