diff options
author | Lei Zhang <thestig@chromium.org> | 2018-05-28 17:51:28 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-28 17:51:28 +0000 |
commit | fffdeebfd0ed9806d32eb5609e0fdd015c25c5ac (patch) | |
tree | 7461043e508179a7d33b850486f312c58048e4a8 /core/fpdfapi/parser | |
parent | 45a55241d315d25067582d29fcdc1ff8b818965f (diff) | |
download | pdfium-fffdeebfd0ed9806d32eb5609e0fdd015c25c5ac.tar.xz |
Add const/non-const versions of remaining CPDF_Dictionary methods.
GetObjectFor() and GetDirectObjectFor().
Change-Id: I588cd994dfccf0ffd4c8f91362a4806dc109251e
Reviewed-on: https://pdfium-review.googlesource.com/32991
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/cpdf_cross_ref_avail.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_dictionary.cpp | 37 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_dictionary.h | 6 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_stream_acc.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode.cpp | 17 | ||||
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode.h | 4 |
7 files changed, 43 insertions, 29 deletions
diff --git a/core/fpdfapi/parser/cpdf_cross_ref_avail.cpp b/core/fpdfapi/parser/cpdf_cross_ref_avail.cpp index be9818ae21..2ab530e00a 100644 --- a/core/fpdfapi/parser/cpdf_cross_ref_avail.cpp +++ b/core/fpdfapi/parser/cpdf_cross_ref_avail.cpp @@ -186,7 +186,7 @@ bool CPDF_CrossRefAvail::CheckCrossRefStream() { return false; } - CPDF_Name* type_name = ToName(trailer->GetObjectFor(kTypeFieldKey)); + const CPDF_Name* type_name = ToName(trailer->GetObjectFor(kTypeFieldKey)); if (type_name && type_name->GetString() == kXRefKeyword) { const int32_t xrefpos = trailer->GetIntegerFor(kPrevCrossRefFieldKey); if (xrefpos && diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 1296b2320b..719169af72 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -279,7 +279,7 @@ bool CPDF_DataAvail::CheckRoot() { bool CPDF_DataAvail::PreparePageItem() { const CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); - CPDF_Reference* pRef = + const CPDF_Reference* pRef = ToReference(pRoot ? pRoot->GetObjectFor("Pages") : nullptr); if (!pRef) { m_docStatus = PDF_DATAAVAIL_ERROR; @@ -996,7 +996,7 @@ CPDF_DataAvail::DocFormStatus CPDF_DataAvail::CheckAcroForm() { if (!pRoot) return FormAvailable; - CPDF_Object* pAcroForm = pRoot->GetObjectFor("AcroForm"); + const CPDF_Object* pAcroForm = pRoot->GetObjectFor("AcroForm"); if (!pAcroForm) return FormNotExist; diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp index 5257a20586..ae7239efdf 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.cpp +++ b/core/fpdfapi/parser/cpdf_dictionary.cpp @@ -81,63 +81,74 @@ std::unique_ptr<CPDF_Object> CPDF_Dictionary::CloneNonCyclic( return std::move(pCopy); } -CPDF_Object* CPDF_Dictionary::GetObjectFor(const ByteString& key) const { +const CPDF_Object* CPDF_Dictionary::GetObjectFor(const ByteString& key) const { auto it = m_Map.find(key); return it != m_Map.end() ? it->second.get() : nullptr; } -CPDF_Object* CPDF_Dictionary::GetDirectObjectFor(const ByteString& key) const { +CPDF_Object* CPDF_Dictionary::GetObjectFor(const ByteString& key) { + auto it = m_Map.find(key); + return it != m_Map.end() ? it->second.get() : nullptr; +} + +const CPDF_Object* CPDF_Dictionary::GetDirectObjectFor( + const ByteString& key) const { + const CPDF_Object* p = GetObjectFor(key); + return p ? p->GetDirect() : nullptr; +} + +CPDF_Object* CPDF_Dictionary::GetDirectObjectFor(const ByteString& key) { CPDF_Object* p = GetObjectFor(key); return p ? p->GetDirect() : nullptr; } ByteString CPDF_Dictionary::GetStringFor(const ByteString& key) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return p ? p->GetString() : ByteString(); } WideString CPDF_Dictionary::GetUnicodeTextFor(const ByteString& key) const { - CPDF_Object* p = GetObjectFor(key); - if (CPDF_Reference* pRef = ToReference(p)) + const CPDF_Object* p = GetObjectFor(key); + if (const CPDF_Reference* pRef = ToReference(p)) p = pRef->GetDirect(); return p ? p->GetUnicodeText() : WideString(); } ByteString CPDF_Dictionary::GetStringFor(const ByteString& key, const ByteString& def) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return p ? p->GetString() : ByteString(def); } int CPDF_Dictionary::GetIntegerFor(const ByteString& key) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return p ? p->GetInteger() : 0; } int CPDF_Dictionary::GetIntegerFor(const ByteString& key, int def) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return p ? p->GetInteger() : def; } float CPDF_Dictionary::GetNumberFor(const ByteString& key) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return p ? p->GetNumber() : 0; } bool CPDF_Dictionary::GetBooleanFor(const ByteString& key, bool bDefault) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return ToBoolean(p) ? p->GetInteger() != 0 : bDefault; } const CPDF_Dictionary* CPDF_Dictionary::GetDictFor( const ByteString& key) const { - CPDF_Object* p = GetDirectObjectFor(key); + const CPDF_Object* p = GetDirectObjectFor(key); if (!p) return nullptr; - if (CPDF_Dictionary* pDict = p->AsDictionary()) + if (const CPDF_Dictionary* pDict = p->AsDictionary()) return pDict; - if (CPDF_Stream* pStream = p->AsStream()) + if (const CPDF_Stream* pStream = p->AsStream()) return pStream->GetDict(); return nullptr; } diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h index 5240ab3b5c..569baedb0b 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.h +++ b/core/fpdfapi/parser/cpdf_dictionary.h @@ -41,8 +41,10 @@ class CPDF_Dictionary : public CPDF_Object { bool WriteTo(IFX_ArchiveStream* archive) const override; size_t GetCount() const { return m_Map.size(); } - CPDF_Object* GetObjectFor(const ByteString& key) const; - CPDF_Object* GetDirectObjectFor(const ByteString& key) const; + const CPDF_Object* GetObjectFor(const ByteString& key) const; + CPDF_Object* GetObjectFor(const ByteString& key); + const CPDF_Object* GetDirectObjectFor(const ByteString& key) const; + CPDF_Object* GetDirectObjectFor(const ByteString& key); ByteString GetStringFor(const ByteString& key) const; ByteString GetStringFor(const ByteString& key, const ByteString& default_str) const; diff --git a/core/fpdfapi/parser/cpdf_stream_acc.h b/core/fpdfapi/parser/cpdf_stream_acc.h index 1c9d5ef096..cd836340fd 100644 --- a/core/fpdfapi/parser/cpdf_stream_acc.h +++ b/core/fpdfapi/parser/cpdf_stream_acc.h @@ -49,7 +49,7 @@ class CPDF_StreamAcc : public Retainable { uint32_t m_dwSize = 0; bool m_bNewBuf = false; ByteString m_ImageDecoder; - CPDF_Dictionary* m_pImageParam = nullptr; + const CPDF_Dictionary* m_pImageParam = nullptr; UnownedPtr<const CPDF_Stream> const m_pStream; uint8_t* m_pSrcData = nullptr; }; diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp index e734183b2b..aafb812234 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp @@ -308,7 +308,7 @@ std::unique_ptr<CCodec_ScanlineDecoder> FPDFAPI_CreateFlateDecoder( uint32_t FPDFAPI_FlateOrLZWDecode(bool bLZW, const uint8_t* src_buf, uint32_t src_size, - CPDF_Dictionary* pParams, + const CPDF_Dictionary* pParams, uint32_t estimated_size, uint8_t** dest_buf, uint32_t* dest_size) { @@ -339,17 +339,18 @@ bool PDF_DataDecode(const uint8_t* src_buf, uint8_t** dest_buf, uint32_t* dest_size, ByteString* ImageEncoding, - CPDF_Dictionary** pImageParms) { - CPDF_Object* pDecoder = pDict ? pDict->GetDirectObjectFor("Filter") : nullptr; + const CPDF_Dictionary** pImageParms) { + const CPDF_Object* pDecoder = + pDict ? pDict->GetDirectObjectFor("Filter") : nullptr; if (!pDecoder || (!pDecoder->IsArray() && !pDecoder->IsName())) return false; - CPDF_Object* pParams = + const CPDF_Object* pParams = pDict ? pDict->GetDirectObjectFor(pdfium::stream::kDecodeParms) : nullptr; - std::vector<std::pair<ByteString, CPDF_Object*>> DecoderArray; - if (CPDF_Array* pDecoders = pDecoder->AsArray()) { - CPDF_Array* pParamsArray = ToArray(pParams); + std::vector<std::pair<ByteString, const CPDF_Object*>> DecoderArray; + if (const CPDF_Array* pDecoders = pDecoder->AsArray()) { + const CPDF_Array* pParamsArray = ToArray(pParams); for (size_t i = 0; i < pDecoders->GetCount(); ++i) { DecoderArray.push_back( {pDecoders->GetStringAt(i), @@ -365,7 +366,7 @@ bool PDF_DataDecode(const uint8_t* src_buf, for (size_t i = 0; i < nSize; ++i) { int estimated_size = i == nSize - 1 ? last_estimated_size : 0; ByteString decoder = DecoderArray[i].first; - CPDF_Dictionary* pParam = ToDictionary(DecoderArray[i].second); + const CPDF_Dictionary* pParam = ToDictionary(DecoderArray[i].second); uint8_t* new_buf = nullptr; uint32_t new_size = 0xFFFFFFFF; uint32_t offset = FX_INVALID_OFFSET; diff --git a/core/fpdfapi/parser/fpdf_parser_decode.h b/core/fpdfapi/parser/fpdf_parser_decode.h index 825d431019..c0f636a231 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.h +++ b/core/fpdfapi/parser/fpdf_parser_decode.h @@ -67,7 +67,7 @@ uint32_t HexDecode(const uint8_t* src_buf, uint32_t FPDFAPI_FlateOrLZWDecode(bool bLZW, const uint8_t* src_buf, uint32_t src_size, - CPDF_Dictionary* pParams, + const CPDF_Dictionary* pParams, uint32_t estimated_size, uint8_t** dest_buf, uint32_t* dest_size); @@ -80,6 +80,6 @@ bool PDF_DataDecode(const uint8_t* src_buf, uint8_t** dest_buf, uint32_t* dest_size, ByteString* ImageEncoding, - CPDF_Dictionary** pImageParms); + const CPDF_Dictionary** pImageParms); #endif // CORE_FPDFAPI_PARSER_FPDF_PARSER_DECODE_H_ |