From e4db2bcaef12877258f691febab1a1260dcf9916 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Thu, 15 Mar 2018 20:09:41 +0900 Subject: more robust method to load a Graphic from URL, +clean up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib7fb107a56a3cc9fffb6cfaa9bbc2117434902df Reviewed-on: https://gerrit.libreoffice.org/51329 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- vcl/source/graphic/GraphicLoader.cxx | 42 +++++++++++++++++------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/vcl/source/graphic/GraphicLoader.cxx b/vcl/source/graphic/GraphicLoader.cxx index 03ca2a6f56a3..b07b345cb982 100644 --- a/vcl/source/graphic/GraphicLoader.cxx +++ b/vcl/source/graphic/GraphicLoader.cxx @@ -14,10 +14,7 @@ #include #include #include -//#include -//#include #include -//#include using namespace css; @@ -27,31 +24,32 @@ namespace graphic { Graphic loadFromURL(OUString const& rURL) { - uno::Reference xGraphic; + Graphic aGraphic; - uno::Reference xContext(comphelper::getProcessComponentContext()); - uno::Reference xProv( - css::graphic::GraphicProvider::create(xContext)); - - uno::Sequence aLoadProps(1); - aLoadProps[0].Name = "URL"; - aLoadProps[0].Value <<= rURL; - - xGraphic = xProv->queryGraphic(aLoadProps); - - std::unique_ptr pGraphic; - if (xGraphic.is()) + try { - pGraphic.reset(new Graphic(xGraphic)); + uno::Reference xGraphic; + uno::Reference xContext(comphelper::getProcessComponentContext()); + uno::Reference xProvider; + xProvider.set(css::graphic::GraphicProvider::create(xContext)); + + uno::Sequence 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); } - else + catch (uno::Exception const&) { - pGraphic.reset(new Graphic); - pGraphic->SetDefaultType(); } - pGraphic->setOriginURL(rURL); - return *pGraphic.get(); + return aGraphic; } } } // end vcl::graphic -- cgit