summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_page
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-05-23 14:56:02 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-23 14:56:02 -0700
commit490d6128e6faef423fa6f965f792513e138bc04a (patch)
treec9e3ea73ae672b0861c92a188a9b84e808d827ea /core/fpdfapi/fpdf_page
parent109975b30dbb2b047001a840b8a1e77434fce7b3 (diff)
downloadpdfium-490d6128e6faef423fa6f965f792513e138bc04a.tar.xz
Make CPDF_Function::Load() return an unique_ptr.chromium/2750chromium/2749chromium/2748
Review-Url: https://codereview.chromium.org/2000973002
Diffstat (limited to 'core/fpdfapi/fpdf_page')
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorspace.cpp105
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_meshstream.cpp51
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_meshstream.h22
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp2
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp25
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_shadingpattern.h20
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_doc.cpp3
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_func.cpp10
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser.cpp58
-rw-r--r--core/fpdfapi/fpdf_page/pageint.h2
10 files changed, 144 insertions, 154 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp b/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp
index 77e8c00d20..d66b920f07 100644
--- a/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/fpdf_page/include/cpdf_colorspace.h"
+#include <memory>
+
#include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h"
#include "core/fpdfapi/fpdf_page/pageint.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
@@ -220,7 +222,7 @@ class CPDF_SeparationCS : public CPDF_ColorSpace {
void EnableStdConversion(FX_BOOL bEnabled) override;
CPDF_ColorSpace* m_pAltCS;
- CPDF_Function* m_pFunc;
+ std::unique_ptr<CPDF_Function> m_pFunc;
enum { None, All, Colorant } m_Type;
};
@@ -242,7 +244,7 @@ class CPDF_DeviceNCS : public CPDF_ColorSpace {
void EnableStdConversion(FX_BOOL bEnabled) override;
CPDF_ColorSpace* m_pAltCS;
- CPDF_Function* m_pFunc;
+ std::unique_ptr<CPDF_Function> m_pFunc;
};
FX_FLOAT RGB_Conversion(FX_FLOAT colorComponent) {
@@ -1098,15 +1100,11 @@ CPDF_ColorSpace* CPDF_PatternCS::GetBaseCS() const {
}
CPDF_SeparationCS::CPDF_SeparationCS(CPDF_Document* pDoc)
- : CPDF_ColorSpace(pDoc, PDFCS_SEPARATION, 1),
- m_pAltCS(nullptr),
- m_pFunc(nullptr) {}
+ : CPDF_ColorSpace(pDoc, PDFCS_SEPARATION, 1), m_pAltCS(nullptr) {}
CPDF_SeparationCS::~CPDF_SeparationCS() {
- if (m_pAltCS) {
+ if (m_pAltCS)
m_pAltCS->ReleaseCS();
- }
- delete m_pFunc;
}
void CPDF_SeparationCS::GetDefaultValue(int iComponent,
@@ -1122,25 +1120,24 @@ FX_BOOL CPDF_SeparationCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) {
CFX_ByteString name = pArray->GetStringAt(1);
if (name == "None") {
m_Type = None;
- } else {
- m_Type = Colorant;
- CPDF_Object* pAltCS = pArray->GetDirectObjectAt(2);
- if (pAltCS == m_pArray) {
- return FALSE;
- }
- m_pAltCS = Load(pDoc, pAltCS);
- if (!m_pAltCS) {
- return FALSE;
- }
- CPDF_Object* pFuncObj = pArray->GetDirectObjectAt(3);
- if (pFuncObj && !pFuncObj->IsName())
- m_pFunc = CPDF_Function::Load(pFuncObj);
-
- if (m_pFunc && m_pFunc->CountOutputs() < m_pAltCS->CountComponents()) {
- delete m_pFunc;
- m_pFunc = NULL;
- }
+ return TRUE;
}
+
+ m_Type = Colorant;
+ CPDF_Object* pAltCS = pArray->GetDirectObjectAt(2);
+ if (pAltCS == m_pArray)
+ return FALSE;
+
+ m_pAltCS = Load(pDoc, pAltCS);
+ if (!m_pAltCS)
+ return FALSE;
+
+ CPDF_Object* pFuncObj = pArray->GetDirectObjectAt(3);
+ if (pFuncObj && !pFuncObj->IsName())
+ m_pFunc = CPDF_Function::Load(pFuncObj);
+
+ if (m_pFunc && m_pFunc->CountOutputs() < m_pAltCS->CountComponents())
+ m_pFunc.reset();
return TRUE;
}
@@ -1148,50 +1145,47 @@ FX_BOOL CPDF_SeparationCS::GetRGB(FX_FLOAT* pBuf,
FX_FLOAT& R,
FX_FLOAT& G,
FX_FLOAT& B) const {
- if (m_Type == None) {
+ if (m_Type == None)
return FALSE;
- }
+
if (!m_pFunc) {
- if (!m_pAltCS) {
+ if (!m_pAltCS)
return FALSE;
- }
+
int nComps = m_pAltCS->CountComponents();
CFX_FixedBufGrow<FX_FLOAT, 16> results(nComps);
- for (int i = 0; i < nComps; i++) {
+ for (int i = 0; i < nComps; i++)
results[i] = *pBuf;
- }
return m_pAltCS->GetRGB(results, R, G, B);
}
+
CFX_FixedBufGrow<FX_FLOAT, 16> results(m_pFunc->CountOutputs());
int nresults = 0;
m_pFunc->Call(pBuf, 1, results, nresults);
- if (nresults == 0) {
+ if (nresults == 0)
return FALSE;
- }
- if (m_pAltCS) {
+
+ if (m_pAltCS)
return m_pAltCS->GetRGB(results, R, G, B);
- }
- R = G = B = 0;
+
+ R = 0;
+ G = 0;
+ B = 0;
return FALSE;
}
void CPDF_SeparationCS::EnableStdConversion(FX_BOOL bEnabled) {
CPDF_ColorSpace::EnableStdConversion(bEnabled);
- if (m_pAltCS) {
+ if (m_pAltCS)
m_pAltCS->EnableStdConversion(bEnabled);
- }
}
CPDF_DeviceNCS::CPDF_DeviceNCS(CPDF_Document* pDoc)
- : CPDF_ColorSpace(pDoc, PDFCS_DEVICEN, 0),
- m_pAltCS(nullptr),
- m_pFunc(nullptr) {}
+ : CPDF_ColorSpace(pDoc, PDFCS_DEVICEN, 0), m_pAltCS(nullptr) {}
CPDF_DeviceNCS::~CPDF_DeviceNCS() {
- delete m_pFunc;
- if (m_pAltCS) {
+ if (m_pAltCS)
m_pAltCS->ReleaseCS();
- }
}
void CPDF_DeviceNCS::GetDefaultValue(int iComponent,
@@ -1210,33 +1204,30 @@ FX_BOOL CPDF_DeviceNCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) {
m_nComponents = pObj->GetCount();
CPDF_Object* pAltCS = pArray->GetDirectObjectAt(2);
- if (!pAltCS || pAltCS == m_pArray) {
+ if (!pAltCS || pAltCS == m_pArray)
return FALSE;
- }
+
m_pAltCS = Load(pDoc, pAltCS);
m_pFunc = CPDF_Function::Load(pArray->GetDirectObjectAt(3));
- if (!m_pAltCS || !m_pFunc) {
- return FALSE;
- }
- if (m_pFunc->CountOutputs() < m_pAltCS->CountComponents()) {
+ if (!m_pAltCS || !m_pFunc)
return FALSE;
- }
- return TRUE;
+
+ return m_pFunc->CountOutputs() >= m_pAltCS->CountComponents();
}
FX_BOOL CPDF_DeviceNCS::GetRGB(FX_FLOAT* pBuf,
FX_FLOAT& R,
FX_FLOAT& G,
FX_FLOAT& B) const {
- if (!m_pFunc) {
+ if (!m_pFunc)
return FALSE;
- }
+
CFX_FixedBufGrow<FX_FLOAT, 16> results(m_pFunc->CountOutputs());
int nresults = 0;
m_pFunc->Call(pBuf, m_nComponents, results, nresults);
- if (nresults == 0) {
+ if (nresults == 0)
return FALSE;
- }
+
return m_pAltCS->GetRGB(results, R, G, B);
}
diff --git a/core/fpdfapi/fpdf_page/cpdf_meshstream.cpp b/core/fpdfapi/fpdf_page/cpdf_meshstream.cpp
index f4a1c16754..491a48052a 100644
--- a/core/fpdfapi/fpdf_page/cpdf_meshstream.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_meshstream.cpp
@@ -10,15 +10,14 @@
#include "core/fpdfapi/fpdf_page/pageint.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
-FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream,
- CPDF_Function** pFuncs,
- int nFuncs,
- CPDF_ColorSpace* pCS) {
+CPDF_MeshStream::CPDF_MeshStream(
+ const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
+ CPDF_ColorSpace* pCS)
+ : m_funcs(funcs), m_pCS(pCS) {}
+
+bool CPDF_MeshStream::Load(CPDF_Stream* pShadingStream) {
m_Stream.LoadAllData(pShadingStream);
m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize());
- m_pFuncs = pFuncs;
- m_nFuncs = nFuncs;
- m_pCS = pCS;
CPDF_Dictionary* pDict = pShadingStream->GetDict();
m_nCoordBits = pDict->GetIntegerBy("BitsPerCoordinate");
m_nCompBits = pDict->GetIntegerBy("BitsPerComponent");
@@ -26,14 +25,11 @@ FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream,
if (!m_nCoordBits || !m_nCompBits)
return FALSE;
- uint32_t nComps = pCS->CountComponents();
+ uint32_t nComps = m_pCS->CountComponents();
if (nComps > 8)
return FALSE;
- m_nComps = nFuncs ? 1 : nComps;
- if (((int)m_nComps < 0) || m_nComps > 8)
- return FALSE;
-
+ m_nComps = m_funcs.empty() ? nComps : 1;
m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1;
m_CompMax = (1 << m_nCompBits) - 1;
CPDF_Array* pDecode = pDict->GetArrayBy("Decode");
@@ -44,7 +40,7 @@ FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream,
m_xmax = pDecode->GetNumberAt(1);
m_ymin = pDecode->GetNumberAt(2);
m_ymax = pDecode->GetNumberAt(3);
- for (uint32_t i = 0; i < m_nComps; i++) {
+ for (uint32_t i = 0; i < m_nComps; ++i) {
m_ColorMin[i] = pDecode->GetNumberAt(i * 2 + 4);
m_ColorMax[i] = pDecode->GetNumberAt(i * 2 + 5);
}
@@ -70,27 +66,26 @@ void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y) {
}
void CPDF_MeshStream::GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b) {
- uint32_t i;
- FX_FLOAT color_value[8];
- for (i = 0; i < m_nComps; i++) {
+ static const int kMaxResults = 8;
+ FX_FLOAT color_value[kMaxResults];
+ for (uint32_t i = 0; i < m_nComps; ++i) {
color_value[i] = m_ColorMin[i] +
m_BitStream.GetBits(m_nCompBits) *
(m_ColorMax[i] - m_ColorMin[i]) / m_CompMax;
}
- if (m_nFuncs) {
- static const int kMaxResults = 8;
- FX_FLOAT result[kMaxResults];
- int nResults;
- FXSYS_memset(result, 0, sizeof(result));
- for (uint32_t i = 0; i < m_nFuncs; i++) {
- if (m_pFuncs[i] && m_pFuncs[i]->CountOutputs() <= kMaxResults) {
- m_pFuncs[i]->Call(color_value, 1, result, nResults);
- }
- }
- m_pCS->GetRGB(result, r, g, b);
- } else {
+ if (m_funcs.empty()) {
m_pCS->GetRGB(color_value, r, g, b);
+ return;
+ }
+
+ FX_FLOAT result[kMaxResults];
+ FXSYS_memset(result, 0, sizeof(result));
+ int nResults;
+ for (const auto& func : m_funcs) {
+ if (func && func->CountOutputs() <= kMaxResults)
+ func->Call(color_value, 1, result, nResults);
}
+ m_pCS->GetRGB(result, r, g, b);
}
uint32_t CPDF_MeshStream::GetVertex(CPDF_MeshVertex& vertex,
diff --git a/core/fpdfapi/fpdf_page/cpdf_meshstream.h b/core/fpdfapi/fpdf_page/cpdf_meshstream.h
index 462dcf09c7..e5d37fe36b 100644
--- a/core/fpdfapi/fpdf_page/cpdf_meshstream.h
+++ b/core/fpdfapi/fpdf_page/cpdf_meshstream.h
@@ -7,6 +7,9 @@
#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_MESHSTREAM_H_
#define CORE_FPDFAPI_FPDF_PAGE_CPDF_MESHSTREAM_H_
+#include <memory>
+#include <vector>
+
#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
#include "core/fxcrt/include/fx_basic.h"
#include "core/fxcrt/include/fx_system.h"
@@ -26,11 +29,10 @@ class CPDF_Stream;
class CPDF_MeshStream {
public:
- FX_BOOL Load(CPDF_Stream* pShadingStream,
- CPDF_Function** pFuncs,
- int nFuncs,
- CPDF_ColorSpace* pCS);
+ CPDF_MeshStream(const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
+ CPDF_ColorSpace* pCS);
+ bool Load(CPDF_Stream* pShadingStream);
uint32_t GetFlag();
void GetCoords(FX_FLOAT& x, FX_FLOAT& y);
@@ -41,9 +43,15 @@ class CPDF_MeshStream {
int count,
CFX_Matrix* pObject2Bitmap);
- CPDF_Function** m_pFuncs;
- CPDF_ColorSpace* m_pCS;
- uint32_t m_nFuncs;
+ CFX_BitStream* BitStream() { return &m_BitStream; }
+ uint32_t CoordBits() const { return m_nCoordBits; }
+ uint32_t CompBits() const { return m_nCompBits; }
+ uint32_t FlagBits() const { return m_nFlagBits; }
+ uint32_t comps() const { return m_nComps; }
+
+ private:
+ const std::vector<std::unique_ptr<CPDF_Function>>& m_funcs;
+ CPDF_ColorSpace* const m_pCS;
uint32_t m_nCoordBits;
uint32_t m_nCompBits;
uint32_t m_nFlagBits;
diff --git a/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp b/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp
index 0858132291..de84f29865 100644
--- a/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp
@@ -22,7 +22,7 @@ CPDF_ShadingObject* CPDF_ShadingObject::Clone() const {
if (obj->m_pShading && obj->m_pShading->document()) {
CPDF_DocPageData* pDocPageData = obj->m_pShading->document()->GetPageData();
CPDF_Pattern* pattern = pDocPageData->GetPattern(
- obj->m_pShading->m_pShadingObj, m_pShading->m_bShadingObj,
+ obj->m_pShading->GetShadingObject(), m_pShading->IsShadingObject(),
obj->m_pShading->parent_matrix());
obj->m_pShading = pattern ? pattern->AsShadingPattern() : nullptr;
}
diff --git a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp
index b7174b4451..1636e17f4f 100644
--- a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp
@@ -6,6 +6,7 @@
#include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h"
+#include "core/fpdfapi/fpdf_page/pageint.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
@@ -34,28 +35,22 @@ CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc,
m_bShadingObj(bShading),
m_pShadingObj(pPatternObj),
m_pCS(nullptr),
- m_pCountedCS(nullptr),
- m_nFuncs(0) {
+ m_pCountedCS(nullptr) {
if (!bShading) {
CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
m_Pattern2Form = pDict->GetMatrixBy("Matrix");
m_pShadingObj = pDict->GetDirectObjectBy("Shading");
m_Pattern2Form.Concat(parentMatrix);
}
- for (size_t i = 0; i < FX_ArraySize(m_pFunctions); ++i)
- m_pFunctions[i] = nullptr;
}
CPDF_ShadingPattern::~CPDF_ShadingPattern() {
- for (size_t i = 0; i < m_nFuncs; ++i)
- delete m_pFunctions[i];
-
CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : nullptr;
if (pCS && m_pDocument)
m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
}
-FX_BOOL CPDF_ShadingPattern::Load() {
+bool CPDF_ShadingPattern::Load() {
if (m_ShadingType != kInvalidShading)
return TRUE;
@@ -64,21 +59,15 @@ FX_BOOL CPDF_ShadingPattern::Load() {
if (!pShadingDict)
return FALSE;
- if (m_nFuncs) {
- for (size_t i = 0; i < m_nFuncs; i++)
- delete m_pFunctions[i];
- m_nFuncs = 0;
- }
+ m_pFunctions.clear();
CPDF_Object* pFunc = pShadingDict->GetDirectObjectBy("Function");
if (pFunc) {
if (CPDF_Array* pArray = pFunc->AsArray()) {
- m_nFuncs = std::min<size_t>(pArray->GetCount(), 4);
-
- for (size_t i = 0; i < m_nFuncs; i++)
+ m_pFunctions.resize(std::min<size_t>(pArray->GetCount(), 4));
+ for (size_t i = 0; i < m_pFunctions.size(); ++i)
m_pFunctions[i] = CPDF_Function::Load(pArray->GetDirectObjectAt(i));
} else {
- m_pFunctions[0] = CPDF_Function::Load(pFunc);
- m_nFuncs = 1;
+ m_pFunctions.push_back(CPDF_Function::Load(pFunc));
}
}
CPDF_Object* pCSObj = pShadingDict->GetDirectObjectBy("ColorSpace");
diff --git a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h
index 1872764a61..0ff258b308 100644
--- a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h
+++ b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h
@@ -7,9 +7,11 @@
#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_SHADINGPATTERN_H_
#define CORE_FPDFAPI_FPDF_PAGE_CPDF_SHADINGPATTERN_H_
+#include <memory>
+#include <vector>
+
#include "core/fpdfapi/fpdf_page/cpdf_countedobject.h"
#include "core/fpdfapi/fpdf_page/cpdf_pattern.h"
-#include "core/fpdfapi/fpdf_page/pageint.h"
#include "core/fxcrt/include/fx_system.h"
enum ShadingType {
@@ -27,6 +29,7 @@ enum ShadingType {
class CFX_Matrix;
class CPDF_ColorSpace;
class CPDF_Document;
+class CPDF_Function;
class CPDF_Object;
class CPDF_ShadingPattern : public CPDF_Pattern {
@@ -35,7 +38,6 @@ class CPDF_ShadingPattern : public CPDF_Pattern {
CPDF_Object* pPatternObj,
FX_BOOL bShading,
const CFX_Matrix& parentMatrix);
-
~CPDF_ShadingPattern() override;
CPDF_TilingPattern* AsTilingPattern() override { return nullptr; }
@@ -47,8 +49,17 @@ class CPDF_ShadingPattern : public CPDF_Pattern {
m_ShadingType == kCoonsPatchMeshShading ||
m_ShadingType == kTensorProductPatchMeshShading;
}
- FX_BOOL Load();
+ bool Load();
+
+ ShadingType GetShadingType() const { return m_ShadingType; }
+ FX_BOOL IsShadingObject() const { return m_bShadingObj; }
+ CPDF_Object* GetShadingObject() const { return m_pShadingObj; }
+ CPDF_ColorSpace* GetCS() const { return m_pCS; }
+ const std::vector<std::unique_ptr<CPDF_Function>>& GetFuncs() {
+ return m_pFunctions;
+ }
+ private:
ShadingType m_ShadingType;
FX_BOOL m_bShadingObj;
CPDF_Object* m_pShadingObj;
@@ -58,8 +69,7 @@ class CPDF_ShadingPattern : public CPDF_Pattern {
CPDF_ColorSpace* m_pCS;
CPDF_CountedColorSpace* m_pCountedCS;
- CPDF_Function* m_pFunctions[4];
- size_t m_nFuncs;
+ std::vector<std::unique_ptr<CPDF_Function>> m_pFunctions;
};
#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_SHADINGPATTERN_H_
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index f0c5302b95..ae02cfb4a7 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -351,8 +351,7 @@ CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj,
}
CPDF_Pattern* pPattern = nullptr;
if (bShading) {
- pPattern =
- new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, bShading, matrix);
+ pPattern = new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, TRUE, matrix);
} else {
CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : nullptr;
if (pDict) {
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_func.cpp b/core/fpdfapi/fpdf_page/fpdf_page_func.cpp
index bb1d631576..ed8e6093d5 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_func.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_func.cpp
@@ -792,9 +792,10 @@ FX_BOOL CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const {
}
// static
-CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) {
+std::unique_ptr<CPDF_Function> CPDF_Function::Load(CPDF_Object* pFuncObj) {
+ std::unique_ptr<CPDF_Function> pFunc;
if (!pFuncObj)
- return nullptr;
+ return pFunc;
int iType = -1;
if (CPDF_Stream* pStream = pFuncObj->AsStream())
@@ -803,7 +804,6 @@ CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) {
iType = pDict->GetIntegerBy("FunctionType");
Type type = IntegerToFunctionType(iType);
- std::unique_ptr<CPDF_Function> pFunc;
if (type == Type::kType0Sampled)
pFunc.reset(new CPDF_SampledFunc());
else if (type == Type::kType2ExpotentialInterpolation)
@@ -814,8 +814,8 @@ CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) {
pFunc.reset(new CPDF_PSFunc());
if (!pFunc || !pFunc->Init(pFuncObj))
- return nullptr;
- return pFunc.release();
+ return std::unique_ptr<CPDF_Function>();
+ return pFunc;
}
// static
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index b30006bf35..ddea2e653d 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -31,6 +31,7 @@
#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
+#include "core/fxcrt/include/fx_safe_types.h"
namespace {
@@ -97,17 +98,16 @@ CFX_ByteStringC PDF_FindFullName(const PDF_AbbrPair* table,
: CFX_ByteStringC();
}
-CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream,
- ShadingType type,
- const CFX_Matrix& matrix,
- CPDF_Function** pFuncs,
- int nFuncs,
- CPDF_ColorSpace* pCS) {
- if (!pStream || !pFuncs || !pCS)
+CFX_FloatRect GetShadingBBox(CPDF_ShadingPattern* pShading,
+ const CFX_Matrix& matrix) {
+ ShadingType type = pShading->GetShadingType();
+ CPDF_Stream* pStream = ToStream(pShading->GetShadingObject());
+ CPDF_ColorSpace* pCS = pShading->GetCS();
+ if (!pStream || !pCS)
return CFX_FloatRect(0, 0, 0, 0);
- CPDF_MeshStream stream;
- if (!stream.Load(pStream, pFuncs, nFuncs, pCS))
+ CPDF_MeshStream stream(pShading->GetFuncs(), pCS);
+ if (!stream.Load(pStream))
return CFX_FloatRect(0, 0, 0, 0);
CFX_FloatRect rect;
@@ -125,7 +125,7 @@ CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream,
if (type == kCoonsPatchMeshShading || type == kTensorProductPatchMeshShading)
color_count = kQuadColorsPerPatch;
- while (!stream.m_BitStream.IsEOF()) {
+ while (!stream.BitStream()->IsEOF()) {
uint32_t flag = 0;
if (type != kLatticeFormGouraudTriangleMeshShading)
flag = stream.GetFlag();
@@ -146,10 +146,15 @@ CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream,
bStarted = true;
}
}
- stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits *
- color_count);
+ FX_SAFE_UINT32 nBits = stream.comps();
+ nBits *= stream.CompBits();
+ nBits *= color_count;
+ if (!nBits.IsValid())
+ break;
+
+ stream.BitStream()->SkipBits(nBits.ValueOrDie());
if (bGouraud)
- stream.m_BitStream.ByteAlign();
+ stream.BitStream()->ByteAlign();
}
rect.Transform(&matrix);
return rect;
@@ -171,16 +176,13 @@ CFX_ByteStringC PDF_FindValueAbbreviationForTesting(
bool IsPathOperator(const uint8_t* buf, size_t len) {
if (len == 1) {
uint8_t op = buf[0];
- if (op == kPathOperatorSubpath || op == kPathOperatorLine ||
- op == kPathOperatorCubicBezier1 || op == kPathOperatorCubicBezier2 ||
- op == kPathOperatorCubicBezier3) {
- return true;
- }
- } else if (len == 2) {
- if (buf[0] == kPathOperatorRectangle[0] &&
- buf[1] == kPathOperatorRectangle[1]) {
- return true;
- }
+ return op == kPathOperatorSubpath || op == kPathOperatorLine ||
+ op == kPathOperatorCubicBezier1 || op == kPathOperatorCubicBezier2 ||
+ op == kPathOperatorCubicBezier3;
+ }
+ if (len == 2) {
+ return buf[0] == kPathOperatorRectangle[0] &&
+ buf[1] == kPathOperatorRectangle[1];
}
return false;
}
@@ -1087,7 +1089,7 @@ void CPDF_StreamContentParser::Handle_ShadeFill() {
if (!pShading)
return;
- if (!pShading->m_bShadingObj || !pShading->Load())
+ if (!pShading->IsShadingObject() || !pShading->Load())
return;
std::unique_ptr<CPDF_ShadingObject> pObj(new CPDF_ShadingObject);
@@ -1097,12 +1099,8 @@ void CPDF_StreamContentParser::Handle_ShadeFill() {
pObj->m_Matrix.Concat(m_mtContentToUser);
CFX_FloatRect bbox =
pObj->m_ClipPath.IsNull() ? m_BBox : pObj->m_ClipPath.GetClipBox();
- if (pShading->IsMeshShading()) {
- bbox.Intersect(GetShadingBBox(ToStream(pShading->m_pShadingObj),
- pShading->m_ShadingType, pObj->m_Matrix,
- pShading->m_pFunctions, pShading->m_nFuncs,
- pShading->m_pCS));
- }
+ if (pShading->IsMeshShading())
+ bbox.Intersect(GetShadingBBox(pShading, pObj->m_Matrix));
pObj->m_Left = bbox.left;
pObj->m_Right = bbox.right;
pObj->m_Top = bbox.top;
diff --git a/core/fpdfapi/fpdf_page/pageint.h b/core/fpdfapi/fpdf_page/pageint.h
index b884338f76..b2204d8dbf 100644
--- a/core/fpdfapi/fpdf_page/pageint.h
+++ b/core/fpdfapi/fpdf_page/pageint.h
@@ -382,7 +382,7 @@ class CPDF_Function {
kType4PostScript = 4,
};
- static CPDF_Function* Load(CPDF_Object* pFuncObj);
+ static std::unique_ptr<CPDF_Function> Load(CPDF_Object* pFuncObj);
static Type IntegerToFunctionType(int iType);
virtual ~CPDF_Function();