crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / vcl / source / graphic / GraphicLoader.cxx
blob63d35efb688ae2f9f8816acca32cd7688ef35ff8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #include <vcl/GraphicLoader.hxx>
13 #include <com/sun/star/awt/XWindow.hpp>
14 #include <unotools/ucbstreamhelper.hxx>
15 #include <vcl/graphicfilter.hxx>
16 #include <vcl/weld.hxx>
18 using namespace css;
20 namespace vcl::graphic
22 Graphic loadFromURL(OUString const& rURL, weld::Window* pParentWin)
24 Graphic aGraphic;
26 std::unique_ptr<SvStream> pInputStream = utl::UcbStreamHelper::CreateStream(
27 rURL, StreamMode::READ, pParentWin ? pParentWin->GetXWindow() : nullptr);
29 if (pInputStream)
31 GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
33 ErrCode nError
34 = rFilter.ImportGraphic(aGraphic, rURL, *pInputStream, GRFILTER_FORMAT_DONTKNOW,
35 nullptr, GraphicFilterImportFlags::NONE);
36 if (nError != ERRCODE_NONE || aGraphic.GetType() == GraphicType::NONE)
37 return Graphic();
40 return aGraphic;
42 } // end vcl::graphic
44 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */