summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-22 20:30:39 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-22 20:30:39 +0000
commit0fe8910834a14fd79593dc4726e282d284417221 (patch)
tree9decc7996d77643438d84ec4de9cc1223e6418f9 /core/fpdfapi/page
parent7f472cd8abe48ffc59dee2a7e37f72e469ddfd7e (diff)
downloadpdfium-0fe8910834a14fd79593dc4726e282d284417221.tar.xz
Simplify CPDF_ShadingPattern::Validate().
Fix some nits in CPDF_ShadingPattern as well. Change-Id: I6b4b73f99031733a113fe2ad1bdc1d1e565b7a7d Reviewed-on: https://pdfium-review.googlesource.com/32738 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/page')
-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