summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-25 21:17:49 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-25 21:17:49 +0000
commit0d86f765b8361b7f9f3a5fcc659de2f52c806bd0 (patch)
tree5f59c428d1bed3269292625d7e26ab4462510b85
parent2d3a78547ae2a0c084dc312ca4b3e03ff3427a9f (diff)
downloadpdfium-0d86f765b8361b7f9f3a5fcc659de2f52c806bd0.tar.xz
Add proper const/non-const versions of CPDF_Dictionary::GetStreamFor().chromium/3441
BUG=pdfium:234 Change-Id: Ia3e758bbe5c445c3856f5215e900e02a16b4d7d7 Reviewed-on: https://pdfium-review.googlesource.com/32910 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fpdfapi/font/cpdf_font.cpp2
-rw-r--r--core/fpdfapi/font/cpdf_tounicodemap.cpp2
-rw-r--r--core/fpdfapi/font/cpdf_tounicodemap.h2
-rw-r--r--core/fpdfapi/parser/cpdf_dictionary.cpp6
-rw-r--r--core/fpdfapi/parser/cpdf_dictionary.h3
-rw-r--r--core/fpdfapi/render/cpdf_dibsource.cpp36
-rw-r--r--core/fpdfapi/render/cpdf_dibsource.h2
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp4
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.h2
-rw-r--r--fpdfsdk/cpdfsdk_helpers.cpp2
10 files changed, 34 insertions, 27 deletions
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 2201e390ff..35fed75c87 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -277,7 +277,7 @@ void CPDF_Font::CheckFontMetrics() {
void CPDF_Font::LoadUnicodeMap() const {
m_bToUnicodeLoaded = true;
- CPDF_Stream* pStream = m_pFontDict->GetStreamFor("ToUnicode");
+ const CPDF_Stream* pStream = m_pFontDict->GetStreamFor("ToUnicode");
if (!pStream)
return;
diff --git a/core/fpdfapi/font/cpdf_tounicodemap.cpp b/core/fpdfapi/font/cpdf_tounicodemap.cpp
index f21c4a31f4..7b5936c31e 100644
--- a/core/fpdfapi/font/cpdf_tounicodemap.cpp
+++ b/core/fpdfapi/font/cpdf_tounicodemap.cpp
@@ -122,7 +122,7 @@ uint32_t CPDF_ToUnicodeMap::GetUnicode() {
return uni.ValueOrDefault(0);
}
-void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {
+void CPDF_ToUnicodeMap::Load(const CPDF_Stream* pStream) {
CIDSet cid_set = CIDSET_UNKNOWN;
auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
pAcc->LoadAllDataFiltered();
diff --git a/core/fpdfapi/font/cpdf_tounicodemap.h b/core/fpdfapi/font/cpdf_tounicodemap.h
index 62fc470c98..8f70791f97 100644
--- a/core/fpdfapi/font/cpdf_tounicodemap.h
+++ b/core/fpdfapi/font/cpdf_tounicodemap.h
@@ -20,7 +20,7 @@ class CPDF_ToUnicodeMap {
CPDF_ToUnicodeMap();
~CPDF_ToUnicodeMap();
- void Load(CPDF_Stream* pStream);
+ void Load(const CPDF_Stream* pStream);
WideString Lookup(uint32_t charcode) const;
uint32_t ReverseLookup(wchar_t unicode) const;
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp
index 29571d6c51..0bdb8a8b16 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/parser/cpdf_dictionary.cpp
@@ -145,7 +145,11 @@ CPDF_Array* CPDF_Dictionary::GetArrayFor(const ByteString& key) const {
return ToArray(GetDirectObjectFor(key));
}
-CPDF_Stream* CPDF_Dictionary::GetStreamFor(const ByteString& key) const {
+const CPDF_Stream* CPDF_Dictionary::GetStreamFor(const ByteString& key) const {
+ return ToStream(GetDirectObjectFor(key));
+}
+
+CPDF_Stream* CPDF_Dictionary::GetStreamFor(const ByteString& key) {
return ToStream(GetDirectObjectFor(key));
}
diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h
index 8ecbe2d6fc..f2ee588dab 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.h
+++ b/core/fpdfapi/parser/cpdf_dictionary.h
@@ -52,7 +52,8 @@ class CPDF_Dictionary : public CPDF_Object {
bool GetBooleanFor(const ByteString& key, bool bDefault = false) const;
float GetNumberFor(const ByteString& key) const;
CPDF_Dictionary* GetDictFor(const ByteString& key) const;
- CPDF_Stream* GetStreamFor(const ByteString& key) const;
+ const CPDF_Stream* GetStreamFor(const ByteString& key) const;
+ CPDF_Stream* GetStreamFor(const ByteString& key);
CPDF_Array* GetArrayFor(const ByteString& key) const;
CFX_FloatRect GetRectFor(const ByteString& key) const;
CFX_Matrix GetMatrixFor(const ByteString& key) const;
diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp
index 3732edaed4..b2ebc74279 100644
--- a/core/fpdfapi/render/cpdf_dibsource.cpp
+++ b/core/fpdfapi/render/cpdf_dibsource.cpp
@@ -297,7 +297,7 @@ CPDF_DIBSource::LoadState CPDF_DIBSource::ContinueLoadDIBSource(
if (!m_pJbig2Context) {
m_pJbig2Context = pdfium::MakeUnique<CCodec_Jbig2Context>();
if (m_pStreamAcc->GetImageParam()) {
- CPDF_Stream* pGlobals =
+ const CPDF_Stream* pGlobals =
m_pStreamAcc->GetImageParam()->GetStreamFor("JBIG2Globals");
if (pGlobals) {
m_pGlobalStream = pdfium::MakeRetain<CPDF_StreamAcc>(pGlobals);
@@ -653,24 +653,26 @@ RetainPtr<CFX_DIBitmap> CPDF_DIBSource::LoadJpxBitmap() {
CPDF_DIBSource::LoadState CPDF_DIBSource::StartLoadMask() {
m_MatteColor = 0XFFFFFFFF;
m_pMaskStream = m_pDict->GetStreamFor("SMask");
- if (m_pMaskStream) {
- CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArrayFor("Matte");
- if (pMatte && m_pColorSpace && m_Family != PDFCS_PATTERN &&
- m_pColorSpace->CountComponents() <= m_nComponents) {
- float R, G, B;
- std::vector<float> colors(m_nComponents);
- for (uint32_t i = 0; i < m_nComponents; i++)
- colors[i] = pMatte->GetFloatAt(i);
-
- m_pColorSpace->GetRGB(colors.data(), &R, &G, &B);
- m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255),
- FXSYS_round(B * 255));
- }
- return StartLoadMaskDIB();
+ if (!m_pMaskStream) {
+ m_pMaskStream = ToStream(m_pDict->GetDirectObjectFor("Mask"));
+ return m_pMaskStream ? StartLoadMaskDIB() : LoadState::kSuccess;
}
- m_pMaskStream = ToStream(m_pDict->GetDirectObjectFor("Mask"));
- return m_pMaskStream ? StartLoadMaskDIB() : LoadState::kSuccess;
+ CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArrayFor("Matte");
+ if (pMatte && m_pColorSpace && m_Family != PDFCS_PATTERN &&
+ m_pColorSpace->CountComponents() <= m_nComponents) {
+ std::vector<float> colors(m_nComponents);
+ for (uint32_t i = 0; i < m_nComponents; i++)
+ colors[i] = pMatte->GetFloatAt(i);
+
+ float R;
+ float G;
+ float B;
+ m_pColorSpace->GetRGB(colors.data(), &R, &G, &B);
+ m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255),
+ FXSYS_round(B * 255));
+ }
+ return StartLoadMaskDIB();
}
CPDF_DIBSource::LoadState CPDF_DIBSource::ContinueLoadMaskDIB(
diff --git a/core/fpdfapi/render/cpdf_dibsource.h b/core/fpdfapi/render/cpdf_dibsource.h
index 50d9c6ef9c..fc390c2f6f 100644
--- a/core/fpdfapi/render/cpdf_dibsource.h
+++ b/core/fpdfapi/render/cpdf_dibsource.h
@@ -156,7 +156,7 @@ class CPDF_DIBSource : public CFX_DIBSource {
// Must come after |m_pCachedBitmap|.
std::unique_ptr<CCodec_Jbig2Context> m_pJbig2Context;
- UnownedPtr<CPDF_Stream> m_pMaskStream;
+ UnownedPtr<const CPDF_Stream> m_pMaskStream;
LoadState m_Status = LoadState::kFail;
};
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 89cddbaa25..8c3c8796e4 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1467,7 +1467,7 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
if (blend_type == FXDIB_BLEND_UNSUPPORTED)
return true;
- const CPDF_Dictionary* pSMaskDict =
+ CPDF_Dictionary* pSMaskDict =
ToDictionary(pPageObj->m_GeneralState.GetSoftMask());
if (pSMaskDict) {
if (pPageObj->IsImage() &&
@@ -2525,7 +2525,7 @@ void CPDF_RenderStatus::CompositeDIBitmap(
}
RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
- const CPDF_Dictionary* pSMaskDict,
+ CPDF_Dictionary* pSMaskDict,
FX_RECT* pClipRect,
const CFX_Matrix* pMatrix) {
if (!pSMaskDict)
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index 19d613c02e..7dee8142c4 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -149,7 +149,7 @@ class CPDF_RenderStatus {
bool bBackAlphaRequired,
int* left,
int* top);
- RetainPtr<CFX_DIBitmap> LoadSMask(const CPDF_Dictionary* pSMaskDict,
+ RetainPtr<CFX_DIBitmap> LoadSMask(CPDF_Dictionary* pSMaskDict,
FX_RECT* pClipRect,
const CFX_Matrix* pMatrix);
// Optionally write the colorspace family value into |pCSFamily|.
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index 0836325263..87ba9e2ec2 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -248,7 +248,7 @@ void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code) {
// SharedForm
const CPDF_Dictionary* pRoot = pDoc->GetRoot();
if (pRoot) {
- CPDF_Stream* pStream = pRoot->GetStreamFor("Metadata");
+ const CPDF_Stream* pStream = pRoot->GetStreamFor("Metadata");
if (pStream) {
CPDF_Metadata metaData(pStream);
for (const auto& err : metaData.CheckForSharedForm())