PoDoFo  1.0.0-dev
PdfObjectStream.h
1 
7 #ifndef PDF_OBJECT_STREAM_H
8 #define PDF_OBJECT_STREAM_H
9 
10 #include "PdfDeclarations.h"
11 
12 #include "PdfEncrypt.h"
13 #include <podofo/auxiliary/OutputStream.h>
14 #include <podofo/auxiliary/InputStream.h>
15 #include "PdfObjectStreamProvider.h"
16 
17 namespace PoDoFo {
18 
19 class PdfObject;
20 class PdfObjectStream;
21 
22 class PODOFO_API PdfObjectInputStream final : public InputStream
23 {
24  friend class PdfObjectStream;
25 public:
26  PdfObjectInputStream();
27  ~PdfObjectInputStream();
28  PdfObjectInputStream(PdfObjectInputStream&& rhs) noexcept;
29 private:
30  PdfObjectInputStream(PdfObjectStream& stream, bool raw);
31 public:
32  const PdfFilterList& GetMediaFilters() const { return m_MediaFilters; }
33  const std::vector<const PdfDictionary*>& GetMediaDecodeParms() const { return m_MediaDecodeParms; }
34 protected:
35  size_t readBuffer(char* buffer, size_t size, bool& eof) override;
36  bool readChar(char& ch) override;
37 public:
38  PdfObjectInputStream& operator=(PdfObjectInputStream&& rhs) noexcept;
39 private:
40  PdfObjectStream* m_stream;
41  std::unique_ptr<InputStream> m_input;
42  PdfFilterList m_MediaFilters;
43  std::vector<const PdfDictionary*> m_MediaDecodeParms;
44 };
45 
46 class PODOFO_API PdfObjectOutputStream final : public OutputStream
47 {
48  friend class PdfObjectStream;
49 public:
50  PdfObjectOutputStream();
51  ~PdfObjectOutputStream();
52  PdfObjectOutputStream(PdfObjectOutputStream&& rhs) noexcept;
53 private:
58  PdfObjectOutputStream(PdfObjectStream& stream, PdfFilterList&& filters,
59  bool raw, bool append);
60  PdfObjectOutputStream(PdfObjectStream& stream);
61 private:
62  PdfObjectOutputStream(PdfObjectStream& stream, nullable<PdfFilterList> filters,
63  bool raw, bool append, bool skipSetDirty);
64 protected:
65  void writeBuffer(const char* buffer, size_t size) override;
66  void flush() override;
67 public:
68  PdfObjectOutputStream& operator=(PdfObjectOutputStream&& rhs) noexcept;
69 private:
70  PdfObjectStream* m_stream;
71  std::unique_ptr<OutputStream> m_output;
72 };
73 
86 class PODOFO_API PdfObjectStream final
87 {
88  friend class PdfObject;
89  friend class PdfObjectInputStream;
90  friend class PdfObjectOutputStream;
91  PODOFO_PRIVATE_FRIEND(class PdfParserObject);
92  PODOFO_PRIVATE_FRIEND(class PdfImmediateWriter);
93 
94 private:
100  PdfObjectStream(PdfObject& parent, std::unique_ptr<PdfObjectStreamProvider>&& provider);
101 
102 public:
103  virtual ~PdfObjectStream();
104 
105  PdfObjectOutputStream GetOutputStreamRaw(bool append = false);
106 
107  PdfObjectOutputStream GetOutputStreamRaw(const PdfFilterList& filters, bool append = false);
108 
109  PdfObjectOutputStream GetOutputStream(bool append = false);
110 
111  PdfObjectOutputStream GetOutputStream(const PdfFilterList& filters, bool append = false);
112 
113  PdfObjectInputStream GetInputStream(bool raw = false) const;
114 
122  void SetData(const bufferview& buffer, bool raw = false);
123 
134  void SetData(const bufferview& buffer, const PdfFilterList& filters, bool raw = false);
135 
143  void SetData(InputStream& stream, bool raw = false);
144 
155  void SetData(InputStream& stream, const PdfFilterList& filters, bool raw = false);
156 
160  charbuff GetCopy(bool raw = false) const;
161 
164  charbuff GetCopySafe() const;
165 
170  void CopyTo(charbuff& buffer, bool raw = false) const;
171 
174  void CopyToSafe(charbuff& buffer) const;
175 
180  void CopyTo(OutputStream& stream, bool raw = false) const;
181 
184  void CopyToSafe(OutputStream& stream) const;
185 
188  void Unwrap();
189 
192  void Clear();
193 
199  size_t GetLength() const;
200 
201  const PdfFilterList& GetFilters() { return m_Filters; }
202 
207  PdfObjectStream& operator=(const PdfObjectStream& rhs);
208 
209  PdfObjectStream& operator=(PdfObjectStream&& rhs) noexcept;
210 
211  const PdfObjectStreamProvider& GetProvider() const { return *m_Provider; }
212 
213  const PdfObject& GetParent() const { return *m_Parent; }
214 
215  PdfObject& GetParent() { return *m_Parent; }
216 
217 private:
222  void Write(OutputStream& stream, const PdfStatefulEncrypt* encrypt);
223 
224  void SetParent(PdfObject& parent) { m_Parent = &parent; }
225 
226  void InitData(InputStream& stream, size_t len, PdfFilterList&& filterList);
227 
230  void CopyFrom(const PdfObjectStream& rhs);
231 
234  void MoveFrom(PdfObjectStream& rhs);
235 
236  PdfObjectStreamProvider& GetProvider() { return *m_Provider; }
237 
238 private:
239  void ensureClosed() const;
240 
241  std::unique_ptr<InputStream> getInputStream(bool raw, PdfFilterList& mediaFilters,
242  std::vector<const PdfDictionary*>& decodeParms);
243 
244  void setData(InputStream& stream, PdfFilterList filters, bool raw,
245  ssize_t size, bool markObjectDirty);
246 
247 private:
248  PdfObjectStream(const PdfObjectStream& rhs) = delete;
249 
250 private:
251  PdfObject* m_Parent;
252  std::unique_ptr<PdfObjectStreamProvider> m_Provider;
253  PdfFilterList m_Filters;
254  bool m_locked;
255 };
256 
257 };
258 
259 #endif // PDF_OBJECT_STREAM_H
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
An interface for reading blocks of data from a data source.
Definition: InputStream.h:20
An interface for writing blocks of data to a data source.
Definition: OutputStream.h:18
A PDF stream can be appended to any PdfObject and can contain arbitrary data.
Definition: PdfObjectStream.h:87
This class represents a PDF indirect Object in memory.
Definition: PdfObject.h:35
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition: basetypes.h:38
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition: basetypes.h:16
cspan< char > bufferview
Convenient read-only char buffer span.
Definition: basetypes.h:19