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 <memory>
11 
12 #include "core/fxcrt/fx_memory_wrappers.h"
13 #include "core/fxcrt/maybe_owned.h"
14 #include "core/fxcrt/retain_ptr.h"
15 #include "third_party/base/span.h"
16 
17 class CPDF_Dictionary;
18 class CPDF_Stream;
19 class CPDF_StreamAcc;
20 
21 class CPDF_FlateEncoder {
22  public:
23   CPDF_FlateEncoder(const CPDF_Stream* pStream, bool bFlateEncode);
24   ~CPDF_FlateEncoder();
25 
26   void CloneDict();
27   CPDF_Dictionary* GetClonedDict();
28 
29   // Returns |m_pClonedDict| if it is valid. Otherwise returns |m_pDict|.
30   const CPDF_Dictionary* GetDict() const;
31 
GetSpan()32   pdfium::span<const uint8_t> GetSpan() const {
33     return pdfium::make_span(m_pData.Get(), m_dwSize);
34   }
35 
36  private:
37   RetainPtr<CPDF_StreamAcc> m_pAcc;
38 
39   uint32_t m_dwSize;
40   MaybeOwned<uint8_t, FxFreeDeleter> m_pData;
41 
42   // Only one of these two pointers is valid at any time.
43   RetainPtr<const CPDF_Dictionary> m_pDict;
44   RetainPtr<CPDF_Dictionary> m_pClonedDict;
45 };
46 
47 #endif  // CORE_FPDFAPI_PARSER_CPDF_FLATEENCODER_H_
48