summaryrefslogtreecommitdiff
path: root/core/fpdfapi/edit/cpdf_flateencoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/edit/cpdf_flateencoder.cpp')
-rw-r--r--core/fpdfapi/edit/cpdf_flateencoder.cpp38
1 files changed, 29 insertions, 9 deletions
diff --git a/core/fpdfapi/edit/cpdf_flateencoder.cpp b/core/fpdfapi/edit/cpdf_flateencoder.cpp
index f6125b8847..a290da6dac 100644
--- a/core/fpdfapi/edit/cpdf_flateencoder.cpp
+++ b/core/fpdfapi/edit/cpdf_flateencoder.cpp
@@ -25,14 +25,16 @@ CPDF_FlateEncoder::CPDF_FlateEncoder(const CPDF_Stream* pStream,
m_dwSize = pDestAcc->GetSize();
m_pData = pDestAcc->DetachData();
- m_pDict = ToDictionary(pStream->GetDict()->Clone());
- m_pDict->RemoveFor("Filter");
+ m_pClonedDict = ToDictionary(pStream->GetDict()->Clone());
+ m_pClonedDict->RemoveFor("Filter");
+ ASSERT(!m_pDict);
return;
}
if (bHasFilter || !bFlateEncode) {
m_pData = m_pAcc->GetData();
m_dwSize = m_pAcc->GetSize();
m_pDict = pStream->GetDict();
+ ASSERT(!m_pClonedDict);
return;
}
@@ -41,18 +43,36 @@ CPDF_FlateEncoder::CPDF_FlateEncoder(const CPDF_Stream* pStream,
::FlateEncode(m_pAcc->GetData(), m_pAcc->GetSize(), &buffer, &m_dwSize);
m_pData = std::unique_ptr<uint8_t, FxFreeDeleter>(buffer);
- m_pDict = ToDictionary(pStream->GetDict()->Clone());
- m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(m_dwSize));
- m_pDict->SetNewFor<CPDF_Name>("Filter", "FlateDecode");
- m_pDict->RemoveFor(pdfium::stream::kDecodeParms);
+ m_pClonedDict = ToDictionary(pStream->GetDict()->Clone());
+ m_pClonedDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(m_dwSize));
+ m_pClonedDict->SetNewFor<CPDF_Name>("Filter", "FlateDecode");
+ m_pClonedDict->RemoveFor(pdfium::stream::kDecodeParms);
+ ASSERT(!m_pDict);
}
CPDF_FlateEncoder::~CPDF_FlateEncoder() {}
void CPDF_FlateEncoder::CloneDict() {
- if (m_pDict.IsOwned())
+ if (m_pClonedDict) {
+ ASSERT(!m_pDict);
return;
+ }
+
+ m_pClonedDict = ToDictionary(m_pDict->Clone());
+ ASSERT(m_pClonedDict);
+ m_pDict.Release();
+}
+
+CPDF_Dictionary* CPDF_FlateEncoder::GetClonedDict() {
+ ASSERT(!m_pDict);
+ return m_pClonedDict.get();
+}
+
+const CPDF_Dictionary* CPDF_FlateEncoder::GetDict() const {
+ if (m_pClonedDict) {
+ ASSERT(!m_pDict);
+ return m_pClonedDict.get();
+ }
- m_pDict = ToDictionary(m_pDict->Clone());
- ASSERT(m_pDict.IsOwned());
+ return m_pDict.Get();
}