Dan Sinclair | a0b1954 | 2017-05-09 12:36:08 -0400 | [diff] [blame] | 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_EDIT_CPDF_FLATEENCODER_H_ |
| 8 | #define CORE_FPDFAPI_EDIT_CPDF_FLATEENCODER_H_ |
| 9 | |
Lei Zhang | 8198130 | 2018-05-09 21:28:32 +0000 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
Dan Sinclair | a0b1954 | 2017-05-09 12:36:08 -0400 | [diff] [blame] | 12 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 13 | #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
Dan Sinclair | a0b1954 | 2017-05-09 12:36:08 -0400 | [diff] [blame] | 14 | #include "core/fxcrt/fx_memory.h" |
Dan Sinclair | de44d15 | 2017-09-21 14:52:41 -0400 | [diff] [blame] | 15 | #include "core/fxcrt/maybe_owned.h" |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 16 | #include "core/fxcrt/retain_ptr.h" |
Tom Sepez | 6facd15 | 2018-05-16 17:07:02 +0000 | [diff] [blame] | 17 | #include "third_party/base/span.h" |
Dan Sinclair | a0b1954 | 2017-05-09 12:36:08 -0400 | [diff] [blame] | 18 | |
| 19 | class CPDF_Stream; |
| 20 | |
| 21 | class CPDF_FlateEncoder { |
| 22 | public: |
Lei Zhang | 4a8478e | 2018-04-05 19:08:20 +0000 | [diff] [blame] | 23 | CPDF_FlateEncoder(const CPDF_Stream* pStream, bool bFlateEncode); |
Dan Sinclair | a0b1954 | 2017-05-09 12:36:08 -0400 | [diff] [blame] | 24 | ~CPDF_FlateEncoder(); |
| 25 | |
| 26 | void CloneDict(); |
Lei Zhang | 8198130 | 2018-05-09 21:28:32 +0000 | [diff] [blame] | 27 | CPDF_Dictionary* GetClonedDict(); |
| 28 | |
| 29 | // Returns |m_pClonedDict| if it is valid. Otherwise returns |m_pDict|. |
| 30 | const CPDF_Dictionary* GetDict() const; |
Dan Sinclair | a0b1954 | 2017-05-09 12:36:08 -0400 | [diff] [blame] | 31 | |
Tom Sepez | 6facd15 | 2018-05-16 17:07:02 +0000 | [diff] [blame] | 32 | pdfium::span<const uint8_t> GetSpan() const { |
| 33 | return pdfium::make_span(m_pData.Get(), m_dwSize); |
| 34 | } |
Dan Sinclair | a0b1954 | 2017-05-09 12:36:08 -0400 | [diff] [blame] | 35 | |
Dan Sinclair | a0b1954 | 2017-05-09 12:36:08 -0400 | [diff] [blame] | 36 | private: |
Artem Strygin | 68d04f2 | 2018-07-12 09:18:19 +0000 | [diff] [blame] | 37 | RetainPtr<CPDF_StreamAcc> m_pAcc; |
| 38 | |
Dan Sinclair | a0b1954 | 2017-05-09 12:36:08 -0400 | [diff] [blame] | 39 | uint32_t m_dwSize; |
Dan Sinclair | de44d15 | 2017-09-21 14:52:41 -0400 | [diff] [blame] | 40 | MaybeOwned<uint8_t, FxFreeDeleter> m_pData; |
Lei Zhang | 8198130 | 2018-05-09 21:28:32 +0000 | [diff] [blame] | 41 | |
| 42 | // Only one of these two pointers is valid at any time. |
| 43 | UnownedPtr<const CPDF_Dictionary> m_pDict; |
| 44 | std::unique_ptr<CPDF_Dictionary> m_pClonedDict; |
Dan Sinclair | a0b1954 | 2017-05-09 12:36:08 -0400 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | #endif // CORE_FPDFAPI_EDIT_CPDF_FLATEENCODER_H_ |