diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-10-22 15:02:06 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-10-22 15:02:06 -0400 |
commit | 2b11dc1220746d2f6f97a940fc9e4235c8ed4975 (patch) | |
tree | e25b2ba13112f4ead789260ee57fe5b40c13b83e /core/src/fpdfdoc/doc_ocg.cpp | |
parent | bc6c6723c37772b02de9e6e43fa0fd9439874905 (diff) | |
download | pdfium-2b11dc1220746d2f6f97a940fc9e4235c8ed4975.tar.xz |
Merge to XFA: Add type cast definitions for CPDF_Array.
This Cl adds ToArray, CPDF_Object::AsArray and CPDF_Object::IsArray and
updates the src to use them as needed.
BUG=pdfium:201
R=thestig@chromium.org, tsepez@chromium.org
Review URL: https://codereview.chromium.org/1417893003 .
(cherry picked from commit c2bfc000e502c42c9a3017038fd9104c7997d126)
Review URL: https://codereview.chromium.org/1419643005 .
Diffstat (limited to 'core/src/fpdfdoc/doc_ocg.cpp')
-rw-r--r-- | core/src/fpdfdoc/doc_ocg.cpp | 79 |
1 files changed, 32 insertions, 47 deletions
diff --git a/core/src/fpdfdoc/doc_ocg.cpp b/core/src/fpdfdoc/doc_ocg.cpp index e66b04489f..b252456df6 100644 --- a/core/src/fpdfdoc/doc_ocg.cpp +++ b/core/src/fpdfdoc/doc_ocg.cpp @@ -7,23 +7,18 @@ #include "../../include/fpdfdoc/fpdf_doc.h" static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object* pObject, const CPDF_Dictionary* pGroupDict) { - if (pObject == NULL || pGroupDict == NULL) { + if (!pObject || !pGroupDict) return -1; - } - int32_t iType = pObject->GetType(); - if (iType == PDFOBJ_ARRAY) { - FX_DWORD dwCount = ((CPDF_Array*)pObject)->GetCount(); + + if (const CPDF_Array* pArray = pObject->AsArray()) { + FX_DWORD dwCount = pArray->GetCount(); for (FX_DWORD i = 0; i < dwCount; i++) { - if (((CPDF_Array*)pObject)->GetDict(i) == pGroupDict) { + if (pArray->GetDict(i) == pGroupDict) return i; - } } return -1; } - if (pObject->GetDict() == pGroupDict) { - return 0; - } - return -1; + return pObject->GetDict() == pGroupDict ? 0 : -1; } static FX_BOOL FPDFDOC_OCG_HasIntent( const CPDF_Dictionary* pDict, @@ -35,13 +30,12 @@ static FX_BOOL FPDFDOC_OCG_HasIntent( return csElement == csDef; } CFX_ByteString bsIntent; - if (pIntent->GetType() == PDFOBJ_ARRAY) { - FX_DWORD dwCount = ((CPDF_Array*)pIntent)->GetCount(); + if (CPDF_Array* pArray = pIntent->AsArray()) { + FX_DWORD dwCount = pArray->GetCount(); for (FX_DWORD i = 0; i < dwCount; i++) { - bsIntent = ((CPDF_Array*)pIntent)->GetString(i); - if (bsIntent == FX_BSTRC("All") || bsIntent == csElement) { + bsIntent = pArray->GetString(i); + if (bsIntent == FX_BSTRC("All") || bsIntent == csElement) return TRUE; - } } return FALSE; } @@ -206,15 +200,12 @@ FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression, CFX_ByteString csOperator = pExpression->GetString(0); if (csOperator == FX_BSTRC("Not")) { pOCGObj = pExpression->GetElementValue(1); - if (pOCGObj == NULL) { + if (!pOCGObj) return FALSE; - } - if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) { + if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict)); - } - if (pOCGObj->GetType() == PDFOBJ_ARRAY) { - return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1); - } + if (CPDF_Array* pArray = pOCGObj->AsArray()) + return !GetOCGVE(pArray, bFromConfig, nLevel + 1); return FALSE; } if (csOperator == FX_BSTRC("Or") || csOperator == FX_BSTRC("And")) { @@ -225,11 +216,11 @@ FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression, continue; } FX_BOOL bItem = FALSE; - if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) { + if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); - } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) { - bItem = GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1); - } + else if (CPDF_Array* pArray = pOCGObj->AsArray()) + bItem = GetOCGVE(pArray, bFromConfig, nLevel + 1); + if (i == 1) { bValue = bItem; } else { @@ -253,38 +244,32 @@ FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict, } CFX_ByteString csP = pOCMDDict->GetString(FX_BSTRC("P"), FX_BSTRC("AnyOn")); CPDF_Object* pOCGObj = pOCMDDict->GetElementValue(FX_BSTRC("OCGs")); - if (pOCGObj == NULL) { + if (!pOCGObj) return TRUE; - } - if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) { + if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); - } - if (pOCGObj->GetType() != PDFOBJ_ARRAY) { + + CPDF_Array* pArray = pOCGObj->AsArray(); + if (!pArray) return TRUE; - } + FX_BOOL bState = FALSE; if (csP == FX_BSTRC("AllOn") || csP == FX_BSTRC("AllOff")) { bState = TRUE; } - int32_t iCount = ((CPDF_Array*)pOCGObj)->GetCount(); + int32_t iCount = pArray->GetCount(); for (int32_t i = 0; i < iCount; i++) { FX_BOOL bItem = TRUE; - CPDF_Dictionary* pItemDict = ((CPDF_Array*)pOCGObj)->GetDict(i); - if (pItemDict) { + CPDF_Dictionary* pItemDict = pArray->GetDict(i); + if (pItemDict) bItem = bFromConfig ? LoadOCGState(pItemDict) : GetOCGVisible(pItemDict); - } - if (csP == FX_BSTRC("AnyOn") && bItem) { - return TRUE; - } - if (csP == FX_BSTRC("AnyOff") && !bItem) { + + if ((csP == FX_BSTRC("AnyOn") && bItem) || + (csP == FX_BSTRC("AnyOff") && !bItem)) return TRUE; - } - if (csP == FX_BSTRC("AllOn") && !bItem) { + if ((csP == FX_BSTRC("AllOn") && !bItem) || + (csP == FX_BSTRC("AllOff") && bItem)) return FALSE; - } - if (csP == FX_BSTRC("AllOff") && bItem) { - return FALSE; - } } return bState; } |