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 
28 #include <string_view>
29 #include <vector>
30 #include <unordered_map>
31 #include <utility>
32 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
33 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
34 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
35 #include <com/sun/star/embed/XStorage.hpp>
36 #include <svx/svxdllapi.h>
37 
39 {
40  Read, Write
41 };
42 
44 {
45  css::uno::Reference < css::embed::XStorage > xStorage;
46  css::uno::Reference < css::io::XStream > xStream;
47 };
48 
49 class SVXCORE_DLLPUBLIC SvXMLGraphicHelper final : public cppu::WeakComponentImplHelper<css::document::XGraphicObjectResolver,
50  css::document::XGraphicStorageHandler,
51  css::document::XBinaryStreamResolver>
52 {
53 private:
54  ::osl::Mutex maMutex;
55  css::uno::Reference < css::embed::XStorage > mxRootStorage;
56  OUString maCurStorageName;
57  std::vector< css::uno::Reference< css::io::XOutputStream > >
59 
60  std::unordered_map<OUString, css::uno::Reference<css::graphic::XGraphic>> maGraphicObjects;
61  std::unordered_map<Graphic, std::pair<OUString, OUString>> maExportGraphics;
62 
64  OUString maOutputMimeType;
65 
66  SVX_DLLPRIVATE static bool ImplGetStreamNames( const OUString& rURLStr,
67  OUString& rPictureStorageName,
68  OUString& rPictureStreamName );
69  SVX_DLLPRIVATE css::uno::Reference < css::embed::XStorage >
70  ImplGetGraphicStorage( const OUString& rPictureStorageName );
72  ImplGetGraphicStream( const OUString& rPictureStorageName,
73  const OUString& rPictureStreamName );
74  SVX_DLLPRIVATE static OUString ImplGetGraphicMimeType( const OUString& rFileName );
75  SVX_DLLPRIVATE Graphic ImplReadGraphic( const OUString& rPictureStorageName,
76  const OUString& rPictureStreamName );
77 
79  virtual ~SvXMLGraphicHelper() override;
80  void Init( const css::uno::Reference < css::embed::XStorage >& xXMLStorage,
81  SvXMLGraphicHelperMode eCreateMode,
82  const OUString& rGraphicMimeType = OUString() );
83 
84  virtual void SAL_CALL disposing() override;
85 
86  SVX_DLLPRIVATE OUString implSaveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic,
87  OUString & rOutMimeType,
88  std::u16string_view rRequestName);
89 
90 public:
92 
93  static rtl::Reference<SvXMLGraphicHelper> Create( const css::uno::Reference < css::embed::XStorage >& rXMLStorage,
94  SvXMLGraphicHelperMode eCreateMode );
96  const OUString& rMimeType = OUString() );
97 
98 public:
99 
100  // XGraphicObjectResolver
101  virtual OUString SAL_CALL resolveGraphicObjectURL( const OUString& aURL ) override;
102 
103  // XGraphicStorageHandler
104  virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL
105  loadGraphic(OUString const & aURL) override;
106 
107  virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL
108  loadGraphicFromOutputStream(css::uno::Reference<css::io::XOutputStream> const & rxOutputStream) override;
109 
110  virtual OUString SAL_CALL
111  saveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override;
112 
113  virtual OUString SAL_CALL
114  saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString & rOutSavedMimeType, OUString const & rRequestName) override;
115 
116  virtual css::uno::Reference<css::io::XInputStream> SAL_CALL
117  createInputStream(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override;
118 
119  // XBinaryStreamResolver
120  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( const OUString& rURL ) override;
121  virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL createOutputStream( ) override;
122  virtual OUString SAL_CALL resolveOutputStream( const css::uno::Reference< css::io::XOutputStream >& rxBinaryStream ) override;
123 };
124 
125 namespace svx {
126  SVXCORE_DLLPUBLIC void DropUnusedNamedItems(css::uno::Reference<css::uno::XInterface> const& xModel);
127 }
128 
129 #endif
130 
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString maOutputMimeType
Definition: xmlgrhlp.hxx:64
void Init()
css::uno::Reference< css::embed::XStorage > xStorage
Definition: xmlgrhlp.hxx:45
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
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:60
::osl::Mutex maMutex
Definition: xmlgrhlp.hxx:54
SvXMLGraphicHelperMode meCreateMode
Definition: xmlgrhlp.hxx:63
std::vector< css::uno::Reference< css::io::XOutputStream > > maGrfStms
Definition: xmlgrhlp.hxx:58
void DropUnusedNamedItems(css::uno::Reference< css::uno::XInterface > const &xModel)
Definition: xmlgrhlp.cxx:1154
#define SVXCORE_DLLPUBLIC
Definition: svxdllapi.h:35
SvXMLGraphicHelperMode
Definition: xmlgrhlp.hxx:38
css::uno::Reference< css::io::XStream > xStream
Definition: xmlgrhlp.hxx:46
Reference< io::XOutputStream > createOutputStream(std::vector< sal_Int8 > *pOutData)
#define SVX_DLLPRIVATE
Definition: svxdllapi.h:30
std::unordered_map< Graphic, std::pair< OUString, OUString > > maExportGraphics
Definition: xmlgrhlp.hxx:61