summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/page/cpdf_shadingpattern.cpp42
-rw-r--r--core/fpdfapi/page/cpdf_shadingpattern.h4
2 files changed, 15 insertions, 31 deletions
diff --git a/core/fpdfapi/page/cpdf_shadingpattern.cpp b/core/fpdfapi/page/cpdf_shadingpattern.cpp
index 628155c575..76f201f767 100644
--- a/core/fpdfapi/page/cpdf_shadingpattern.cpp
+++ b/core/fpdfapi/page/cpdf_shadingpattern.cpp
@@ -19,8 +19,7 @@
namespace {
ShadingType ToShadingType(int type) {
- return (type > static_cast<int>(kInvalidShading) &&
- type < static_cast<int>(kMaxShading))
+ return (type > kInvalidShading && type < kMaxShading)
? static_cast<ShadingType>(type)
: kInvalidShading;
}
@@ -32,11 +31,8 @@ CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc,
bool bShading,
const CFX_Matrix& parentMatrix)
: CPDF_Pattern(pDoc, bShading ? nullptr : pPatternObj, parentMatrix),
- m_ShadingType(kInvalidShading),
m_bShadingObj(bShading),
- m_pShadingObj(pPatternObj),
- m_pCS(nullptr),
- m_pCountedCS(nullptr) {
+ m_pShadingObj(pPatternObj) {
assert(document());
if (!bShading) {
m_pShadingObj = pattern_obj()->GetDict()->GetDirectObjectFor("Shading");
@@ -96,9 +92,7 @@ bool CPDF_ShadingPattern::Load() {
return false;
m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray());
-
m_ShadingType = ToShadingType(pShadingDict->GetIntegerFor("ShadingType"));
-
return Validate();
}
@@ -137,39 +131,29 @@ bool CPDF_ShadingPattern::Validate() const {
switch (m_ShadingType) {
case kFunctionBasedShading: {
// Either one 2-to-N function or N 2-to-1 functions.
- if (!ValidateFunctions(1, 2, nNumColorSpaceComponents) &&
- !ValidateFunctions(nNumColorSpaceComponents, 2, 1)) {
- return false;
- }
- break;
+ return ValidateFunctions(1, 2, nNumColorSpaceComponents) ||
+ ValidateFunctions(nNumColorSpaceComponents, 2, 1);
}
case kAxialShading:
case kRadialShading: {
// Either one 1-to-N function or N 1-to-1 functions.
- if (!ValidateFunctions(1, 1, nNumColorSpaceComponents) &&
- !ValidateFunctions(nNumColorSpaceComponents, 1, 1)) {
- return false;
- }
- break;
+ return ValidateFunctions(1, 1, nNumColorSpaceComponents) ||
+ ValidateFunctions(nNumColorSpaceComponents, 1, 1);
}
case kFreeFormGouraudTriangleMeshShading:
case kLatticeFormGouraudTriangleMeshShading:
case kCoonsPatchMeshShading:
case kTensorProductPatchMeshShading: {
// Either no function, one 1-to-N function, or N 1-to-1 functions.
- if (!m_pFunctions.empty() &&
- !ValidateFunctions(1, 1, nNumColorSpaceComponents) &&
- !ValidateFunctions(nNumColorSpaceComponents, 1, 1)) {
- return false;
- }
- break;
- }
- default: {
- NOTREACHED();
- return false;
+ return m_pFunctions.empty() ||
+ ValidateFunctions(1, 1, nNumColorSpaceComponents) ||
+ ValidateFunctions(nNumColorSpaceComponents, 1, 1);
}
+ default:
+ break;
}
- return true;
+ NOTREACHED();
+ return false;
}
bool CPDF_ShadingPattern::ValidateFunctions(
diff --git a/core/fpdfapi/page/cpdf_shadingpattern.h b/core/fpdfapi/page/cpdf_shadingpattern.h
index 17b6e4bb8c..bb633f9a4d 100644
--- a/core/fpdfapi/page/cpdf_shadingpattern.h
+++ b/core/fpdfapi/page/cpdf_shadingpattern.h
@@ -67,8 +67,8 @@ class CPDF_ShadingPattern : public CPDF_Pattern {
uint32_t nExpectedNumInputs,
uint32_t nExpectedNumOutputs) const;
- ShadingType m_ShadingType;
- bool m_bShadingObj;
+ ShadingType m_ShadingType = kInvalidShading;
+ const bool m_bShadingObj;
UnownedPtr<CPDF_Object> m_pShadingObj;
// Still keep |m_pCS| as some CPDF_ColorSpace (name object) are not managed