1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FPDFAPI_PARSER_CPDF_FLATEENCODER_H_
8 #define CORE_FPDFAPI_PARSER_CPDF_FLATEENCODER_H_
9 
10 #include "core/fxcrt/fx_memory_wrappers.h"
11 #include "core/fxcrt/maybe_owned.h"
12 #include "core/fxcrt/retain_ptr.h"
13 #include "third_party/base/span.h"
14 
15 class CPDF_Dictionary;
16 class CPDF_Stream;
17 class CPDF_StreamAcc;
18 
19 class CPDF_FlateEncoder {
20  public:
21   CPDF_FlateEncoder(const CPDF_Stream* pStream, bool bFlateEncode);
22   ~CPDF_FlateEncoder();
23 
24   void CloneDict();
25   CPDF_Dictionary* GetClonedDict();
26 
27   // Returns |m_pClonedDict| if it is valid. Otherwise returns |m_pDict|.
28   const CPDF_Dictionary* GetDict() const;
29 
GetSpan()30   pdfium::span<const uint8_t> GetSpan() const {
31     return pdfium::make_span(m_pData.Get(), m_dwSize);
32   }
33 
34  private:
35   RetainPtr<CPDF_StreamAcc> m_pAcc;
36 
37   uint32_t m_dwSize;
38   MaybeOwned<uint8_t, FxFreeDeleter> m_pData;
39 
40   // Only one of these two pointers is valid at any time.
41   RetainPtr<const CPDF_Dictionary> m_pDict;
42   RetainPtr<CPDF_Dictionary> m_pClonedDict;
43 };
44 
45 #endif  // CORE_FPDFAPI_PARSER_CPDF_FLATEENCODER_H_
46