LibreOffice Module vcl (master)  1
GraphicLoader.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  */
10 
11 #include <vcl/GraphicLoader.hxx>
12 
13 #include <com/sun/star/awt/XWindow.hpp>
15 #include <vcl/graphicfilter.hxx>
16 #include <vcl/weld.hxx>
17 
18 using namespace css;
19 
20 namespace vcl::graphic
21 {
22 Graphic loadFromURL(OUString const& rURL, weld::Window* pParentWin)
23 {
24  Graphic aGraphic;
25 
26  std::unique_ptr<SvStream> pInputStream = utl::UcbStreamHelper::CreateStream(
27  rURL, StreamMode::READ, pParentWin ? pParentWin->GetXWindow() : nullptr);
28 
29  if (pInputStream)
30  {
32 
33  ErrCode nError
34  = rFilter.ImportGraphic(aGraphic, rURL, *pInputStream, GRFILTER_FORMAT_DONTKNOW,
36  /*pExtHeader*/ static_cast<WmfExternal const*>(nullptr));
37  if (nError != ERRCODE_NONE || aGraphic.GetType() == GraphicType::NONE)
38  return Graphic();
39  }
40 
41  return aGraphic;
42 }
43 } // end vcl::graphic
44 
45 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
Class to import and export graphic formats.
Graphic loadFromURL(OUString const &rURL, weld::Window *pParentWin)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
GraphicType GetType() const
Definition: graph.cxx:294
#define GRFILTER_FORMAT_DONTKNOW
#define ERRCODE_NONE
Definition: errcode.hxx:196
static GraphicFilter & GetGraphicFilter()