1 // Copyright 2017 The PDFium Authors 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 <stdint.h> 11 12 #include "core/fxcrt/data_vector.h" 13 #include "core/fxcrt/raw_span.h" 14 #include "core/fxcrt/retain_ptr.h" 15 #include "core/fxcrt/span.h" 16 #include "third_party/abseil-cpp/absl/types/variant.h" 17 18 class CPDF_Dictionary; 19 class CPDF_Encryptor; 20 class CPDF_Stream; 21 class CPDF_StreamAcc; 22 class IFX_ArchiveStream; 23 24 class CPDF_FlateEncoder { 25 public: 26 CPDF_FlateEncoder(RetainPtr<const CPDF_Stream> pStream, bool bFlateEncode); 27 ~CPDF_FlateEncoder(); 28 29 void UpdateLength(size_t size); 30 bool WriteDictTo(IFX_ArchiveStream* archive, 31 const CPDF_Encryptor* encryptor) const; 32 33 pdfium::span<const uint8_t> GetSpan() const; 34 35 private: is_owned()36 bool is_owned() const { 37 return absl::holds_alternative<DataVector<uint8_t>>(m_Data); 38 } 39 40 // Returns |m_pClonedDict| if it is valid. Otherwise returns |m_pDict|. 41 const CPDF_Dictionary* GetDict() const; 42 43 // Must outlive `m_Data`. 44 RetainPtr<CPDF_StreamAcc> const m_pAcc; 45 46 absl::variant<pdfium::raw_span<const uint8_t>, DataVector<uint8_t>> m_Data; 47 48 // Only one of these two pointers is valid at any time. 49 RetainPtr<const CPDF_Dictionary> m_pDict; 50 RetainPtr<CPDF_Dictionary> m_pClonedDict; 51 }; 52 53 #endif // CORE_FPDFAPI_PARSER_CPDF_FLATEENCODER_H_ 54