LibreOffice Module svx (master)  1
xmlgrhlp.hxx
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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SVX_XMLGRHLP_HXX
21 #define INCLUDED_SVX_XMLGRHLP_HXX
22 
23 #include <cppuhelper/compbase.hxx>
24 #include <osl/mutex.hxx>
25 #include <vcl/graph.hxx>
26 #include <rtl/ref.hxx>
27 #include <vector>
28 #include <unordered_map>
29 #include <utility>
30 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
31 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
32 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
33 #include <com/sun/star/embed/XStorage.hpp>
34 #include <svx/svxdllapi.h>
35 
37 {
38  Read, Write
39 };
40 
42 {
43  css::uno::Reference < css::embed::XStorage > xStorage;
44  css::uno::Reference < css::io::XStream > xStream;
45 };
46 
47 class SVXCORE_DLLPUBLIC SvXMLGraphicHelper final : public cppu::WeakComponentImplHelper<css::document::XGraphicObjectResolver,
48  css::document::XGraphicStorageHandler,
49  css::document::XBinaryStreamResolver>
50 {
51 private:
52  typedef ::std::vector< css::uno::Reference< css::io::XOutputStream > > GraphicOutputStreamVector;
53 
54  ::osl::Mutex maMutex;
55  css::uno::Reference < css::embed::XStorage > mxRootStorage;
56  OUString maCurStorageName;
57  GraphicOutputStreamVector maGrfStms;
58 
59  std::unordered_map<OUString, css::uno::Reference<css::graphic::XGraphic>> maGraphicObjects;
60  std::unordered_map<Graphic, std::pair<OUString, OUString>> maExportGraphics;
61 
63  OUString maOutputMimeType;
64 
65  SVX_DLLPRIVATE static bool ImplGetStreamNames( const OUString& rURLStr,
66  OUString& rPictureStorageName,
67  OUString& rPictureStreamName );
68  SVX_DLLPRIVATE css::uno::Reference < css::embed::XStorage >
69  ImplGetGraphicStorage( const OUString& rPictureStorageName );
71  ImplGetGraphicStream( const OUString& rPictureStorageName,
72  const OUString& rPictureStreamName );
73  SVX_DLLPRIVATE static OUString ImplGetGraphicMimeType( const OUString& rFileName );
74  SVX_DLLPRIVATE Graphic ImplReadGraphic( const OUString& rPictureStorageName,
75  const OUString& rPictureStreamName );
76 
78  virtual ~SvXMLGraphicHelper() override;
79  void Init( const css::uno::Reference < css::embed::XStorage >& xXMLStorage,
80  SvXMLGraphicHelperMode eCreateMode,
81  const OUString& rGraphicMimeType = OUString() );
82 
83  virtual void SAL_CALL disposing() override;
84 
85  SVX_DLLPRIVATE OUString implSaveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic,
86  OUString & rOutMimeType, OUString const & rRequestName);
87 
88 public:
90 
91  static rtl::Reference<SvXMLGraphicHelper> Create( const css::uno::Reference < css::embed::XStorage >& rXMLStorage,
92  SvXMLGraphicHelperMode eCreateMode );
94  const OUString& rMimeType = OUString() );
95 
96 public:
97 
98  // XGraphicObjectResolver
99  virtual OUString SAL_CALL resolveGraphicObjectURL( const OUString& aURL ) override;
100 
101  // XGraphicStorageHandler
102  virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL
103  loadGraphic(OUString const & aURL) override;
104 
105  virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL
106  loadGraphicFromOutputStream(css::uno::Reference<css::io::XOutputStream> const & rxOutputStream) override;
107 
108  virtual OUString SAL_CALL
109  saveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override;
110 
111  virtual OUString SAL_CALL
112  saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString & rOutSavedMimeType, OUString const & rRequestName) override;
113 
114  virtual css::uno::Reference<css::io::XInputStream> SAL_CALL
115  createInputStream(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override;
116 
117  // XBinaryStreamResolver
118  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( const OUString& rURL ) override;
119  virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL createOutputStream( ) override;
120  virtual OUString SAL_CALL resolveOutputStream( const css::uno::Reference< css::io::XOutputStream >& rxBinaryStream ) override;
121 };
122 
123 #endif
124 
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString maOutputMimeType
Definition: xmlgrhlp.hxx:63
void Init()
css::uno::Reference< css::embed::XStorage > xStorage
Definition: xmlgrhlp.hxx:43
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
GraphicOutputStreamVector maGrfStms
Definition: xmlgrhlp.hxx:57
OUString maCurStorageName
Definition: xmlgrhlp.hxx:56
css::uno::Reference< css::embed::XStorage > mxRootStorage
Definition: xmlgrhlp.hxx:55
Reference< io::XInputStream > createInputStream(std::vector< sal_Int8 > const &rInData)
std::unordered_map< OUString, css::uno::Reference< css::graphic::XGraphic > > maGraphicObjects
Definition: xmlgrhlp.hxx:59
::osl::Mutex maMutex
Definition: xmlgrhlp.hxx:54
SvXMLGraphicHelperMode meCreateMode
Definition: xmlgrhlp.hxx:62
#define SVXCORE_DLLPUBLIC
Definition: svxdllapi.h:35
SvXMLGraphicHelperMode
Definition: xmlgrhlp.hxx:36
css::uno::Reference< css::io::XStream > xStream
Definition: xmlgrhlp.hxx:44
Reference< io::XOutputStream > createOutputStream(std::vector< sal_Int8 > *pOutData)
::std::vector< css::uno::Reference< css::io::XOutputStream > > GraphicOutputStreamVector
Definition: xmlgrhlp.hxx:52
#define SVX_DLLPRIVATE
Definition: svxdllapi.h:30
std::unordered_map< Graphic, std::pair< OUString, OUString > > maExportGraphics
Definition: xmlgrhlp.hxx:60