diff options
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/edit/cpdf_creator.cpp | 1 | ||||
-rw-r--r-- | core/fpdfapi/edit/cpdf_creator.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_cidfont.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_docpagedata.cpp | 2 | ||||
-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 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_dibsource.cpp | 12 |
12 files changed, 53 insertions, 40 deletions
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp index 5e3f9ee592..24c4c2c29a 100644 --- a/core/fpdfapi/edit/cpdf_creator.cpp +++ b/core/fpdfapi/edit/cpdf_creator.cpp @@ -148,7 +148,6 @@ CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc, m_pEncryptDict(m_pParser ? m_pParser->GetEncryptDict() : nullptr), m_dwEncryptObjNum(0), m_pSecurityHandler(m_pParser ? m_pParser->GetSecurityHandler() : nullptr), - m_pMetadata(nullptr), m_dwLastObjNum(m_pDocument->GetLastObjNum()), m_Archive(pdfium::MakeUnique<CFX_FileBufferArchive>(archive)), m_SavedOffset(0), diff --git a/core/fpdfapi/edit/cpdf_creator.h b/core/fpdfapi/edit/cpdf_creator.h index 4c1d0f1800..f95cab44eb 100644 --- a/core/fpdfapi/edit/cpdf_creator.h +++ b/core/fpdfapi/edit/cpdf_creator.h @@ -88,7 +88,7 @@ class CPDF_Creator { UnownedPtr<CPDF_Dictionary> m_pEncryptDict; uint32_t m_dwEncryptObjNum; fxcrt::MaybeOwned<CPDF_SecurityHandler> m_pSecurityHandler; - UnownedPtr<CPDF_Object> m_pMetadata; + UnownedPtr<const CPDF_Object> m_pMetadata; uint32_t m_dwLastObjNum; std::unique_ptr<IFX_ArchiveStream> m_Archive; FX_FILESIZE m_SavedOffset; diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index 38a4d65423..4b4f04ba5f 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp @@ -407,9 +407,9 @@ bool CPDF_CIDFont::Load() { if (!IsEmbedded()) LoadSubstFont(); - CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap"); + const CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap"); if (pmap) { - if (CPDF_Stream* pStream = pmap->AsStream()) { + if (const CPDF_Stream* pStream = pmap->AsStream()) { m_pStreamAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream); m_pStreamAcc->LoadAllDataFiltered(); } else if (m_pFontFile && pmap->GetString() == "Identity") { diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp index 37283b9d64..49d44b3368 100644 --- a/core/fpdfapi/page/cpdf_docpagedata.cpp +++ b/core/fpdfapi/page/cpdf_docpagedata.cpp @@ -254,7 +254,7 @@ CPDF_ColorSpace* CPDF_DocPageData::GetColorSpaceInternal( if (!pColorSpaces) return pCS; - CPDF_Object* pDefaultCS = nullptr; + const CPDF_Object* pDefaultCS = nullptr; switch (pCS->GetFamily()) { case PDFCS_DEVICERGB: pDefaultCS = pColorSpaces->GetDirectObjectFor("DefaultRGB"); 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_ diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp index e9de5289a4..ad828f2372 100644 --- a/core/fpdfapi/render/cpdf_dibsource.cpp +++ b/core/fpdfapi/render/cpdf_dibsource.cpp @@ -342,12 +342,12 @@ bool CPDF_DIBSource::LoadColorInfo(const CPDF_Dictionary* pFormResources, if (m_bImageMask || !m_pDict->KeyExist("ColorSpace")) { if (!m_bImageMask) { - CPDF_Object* pFilter = m_pDict->GetDirectObjectFor("Filter"); + const CPDF_Object* pFilter = m_pDict->GetDirectObjectFor("Filter"); if (pFilter) { ByteString filter; if (pFilter->IsName()) { filter = pFilter->GetString(); - } else if (CPDF_Array* pArray = pFilter->AsArray()) { + } else if (const CPDF_Array* pArray = pFilter->AsArray()) { filter = pArray->GetStringAt(pArray->GetCount() - 1); } @@ -427,11 +427,11 @@ bool CPDF_DIBSource::GetDecodeAndMaskArray(bool* bDefaultDecode, if (m_pDict->KeyExist("SMask")) return true; - CPDF_Object* pMask = m_pDict->GetDirectObjectFor("Mask"); + const CPDF_Object* pMask = m_pDict->GetDirectObjectFor("Mask"); if (!pMask) return true; - if (CPDF_Array* pArray = pMask->AsArray()) { + if (const CPDF_Array* pArray = pMask->AsArray()) { if (pArray->GetCount() >= m_nComponents * 2) { for (uint32_t i = 0; i < m_nComponents; i++) { int min_num = pArray->GetIntegerAt(i * 2); @@ -791,7 +791,7 @@ void CPDF_DIBSource::LoadPalette() { void CPDF_DIBSource::ValidateDictParam() { m_bpc = m_bpc_orig; - CPDF_Object* pFilter = m_pDict->GetDirectObjectFor("Filter"); + const CPDF_Object* pFilter = m_pDict->GetDirectObjectFor("Filter"); if (pFilter) { if (pFilter->IsName()) { ByteString filter = pFilter->GetString(); @@ -805,7 +805,7 @@ void CPDF_DIBSource::ValidateDictParam() { } else if (filter == "DCTDecode") { m_bpc = 8; } - } else if (CPDF_Array* pArray = pFilter->AsArray()) { + } else if (const CPDF_Array* pArray = pFilter->AsArray()) { ByteString filter = pArray->GetStringAt(pArray->GetCount() - 1); if (filter == "CCITTFaxDecode" || filter == "JBIG2Decode") { m_bpc = 1; |