| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 9 #include "core/include/fpdfdoc/fpdf_doc.h" | 9 #include "core/include/fpdfdoc/fpdf_doc.h" |
| 10 | 10 |
| 11 static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object* pObject, | 11 static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object* pObject, |
| 12 const CPDF_Dictionary* pGroupDict) { | 12 const CPDF_Dictionary* pGroupDict) { |
| 13 if (!pObject || !pGroupDict) | 13 if (!pObject || !pGroupDict) |
| 14 return -1; | 14 return -1; |
| 15 | 15 |
| 16 if (const CPDF_Array* pArray = pObject->AsArray()) { | 16 if (const CPDF_Array* pArray = pObject->AsArray()) { |
| 17 uint32_t dwCount = pArray->GetCount(); | 17 uint32_t dwCount = pArray->GetCount(); |
| 18 for (uint32_t i = 0; i < dwCount; i++) { | 18 for (uint32_t i = 0; i < dwCount; i++) { |
| 19 if (pArray->GetDictAt(i) == pGroupDict) | 19 if (pArray->GetDictAt(i) == pGroupDict) |
| 20 return i; | 20 return i; |
| 21 } | 21 } |
| 22 return -1; | 22 return -1; |
| 23 } | 23 } |
| 24 return pObject->GetDict() == pGroupDict ? 0 : -1; | 24 return pObject->GetDict() == pGroupDict ? 0 : -1; |
| 25 } | 25 } |
| 26 static FX_BOOL FPDFDOC_OCG_HasIntent(const CPDF_Dictionary* pDict, | 26 static FX_BOOL FPDFDOC_OCG_HasIntent(const CPDF_Dictionary* pDict, |
| 27 const CFX_ByteStringC& csElement, | 27 const CFX_ByteStringC& csElement, |
| 28 const CFX_ByteStringC& csDef = "") { | 28 const CFX_ByteStringC& csDef = "") { |
| 29 CPDF_Object* pIntent = pDict->GetElementValue("Intent"); | 29 CPDF_Object* pIntent = pDict->GetDirectObjectBy("Intent"); |
| 30 if (!pIntent) { | 30 if (!pIntent) { |
| 31 return csElement == csDef; | 31 return csElement == csDef; |
| 32 } | 32 } |
| 33 CFX_ByteString bsIntent; | 33 CFX_ByteString bsIntent; |
| 34 if (CPDF_Array* pArray = pIntent->AsArray()) { | 34 if (CPDF_Array* pArray = pIntent->AsArray()) { |
| 35 uint32_t dwCount = pArray->GetCount(); | 35 uint32_t dwCount = pArray->GetCount(); |
| 36 for (uint32_t i = 0; i < dwCount; i++) { | 36 for (uint32_t i = 0; i < dwCount; i++) { |
| 37 bsIntent = pArray->GetStringAt(i); | 37 bsIntent = pArray->GetStringAt(i); |
| 38 if (bsIntent == "All" || bsIntent == csElement) | 38 if (bsIntent == "All" || bsIntent == csElement) |
| 39 return TRUE; | 39 return TRUE; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 if (nLevel > 32) { | 191 if (nLevel > 32) { |
| 192 return FALSE; | 192 return FALSE; |
| 193 } | 193 } |
| 194 if (!pExpression) { | 194 if (!pExpression) { |
| 195 return FALSE; | 195 return FALSE; |
| 196 } | 196 } |
| 197 int32_t iCount = pExpression->GetCount(); | 197 int32_t iCount = pExpression->GetCount(); |
| 198 CPDF_Object* pOCGObj; | 198 CPDF_Object* pOCGObj; |
| 199 CFX_ByteString csOperator = pExpression->GetStringAt(0); | 199 CFX_ByteString csOperator = pExpression->GetStringAt(0); |
| 200 if (csOperator == "Not") { | 200 if (csOperator == "Not") { |
| 201 pOCGObj = pExpression->GetElementValue(1); | 201 pOCGObj = pExpression->GetDirectObjectAt(1); |
| 202 if (!pOCGObj) | 202 if (!pOCGObj) |
| 203 return FALSE; | 203 return FALSE; |
| 204 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) | 204 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) |
| 205 return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict)); | 205 return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict)); |
| 206 if (CPDF_Array* pArray = pOCGObj->AsArray()) | 206 if (CPDF_Array* pArray = pOCGObj->AsArray()) |
| 207 return !GetOCGVE(pArray, bFromConfig, nLevel + 1); | 207 return !GetOCGVE(pArray, bFromConfig, nLevel + 1); |
| 208 return FALSE; | 208 return FALSE; |
| 209 } | 209 } |
| 210 if (csOperator == "Or" || csOperator == "And") { | 210 if (csOperator == "Or" || csOperator == "And") { |
| 211 FX_BOOL bValue = FALSE; | 211 FX_BOOL bValue = FALSE; |
| 212 for (int32_t i = 1; i < iCount; i++) { | 212 for (int32_t i = 1; i < iCount; i++) { |
| 213 pOCGObj = pExpression->GetElementValue(1); | 213 pOCGObj = pExpression->GetDirectObjectAt(1); |
| 214 if (!pOCGObj) { | 214 if (!pOCGObj) { |
| 215 continue; | 215 continue; |
| 216 } | 216 } |
| 217 FX_BOOL bItem = FALSE; | 217 FX_BOOL bItem = FALSE; |
| 218 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) | 218 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) |
| 219 bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); | 219 bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); |
| 220 else if (CPDF_Array* pArray = pOCGObj->AsArray()) | 220 else if (CPDF_Array* pArray = pOCGObj->AsArray()) |
| 221 bItem = GetOCGVE(pArray, bFromConfig, nLevel + 1); | 221 bItem = GetOCGVE(pArray, bFromConfig, nLevel + 1); |
| 222 | 222 |
| 223 if (i == 1) { | 223 if (i == 1) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 234 } | 234 } |
| 235 return FALSE; | 235 return FALSE; |
| 236 } | 236 } |
| 237 FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict, | 237 FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict, |
| 238 FX_BOOL bFromConfig) { | 238 FX_BOOL bFromConfig) { |
| 239 CPDF_Array* pVE = pOCMDDict->GetArrayBy("VE"); | 239 CPDF_Array* pVE = pOCMDDict->GetArrayBy("VE"); |
| 240 if (pVE) { | 240 if (pVE) { |
| 241 return GetOCGVE(pVE, bFromConfig); | 241 return GetOCGVE(pVE, bFromConfig); |
| 242 } | 242 } |
| 243 CFX_ByteString csP = pOCMDDict->GetStringBy("P", "AnyOn"); | 243 CFX_ByteString csP = pOCMDDict->GetStringBy("P", "AnyOn"); |
| 244 CPDF_Object* pOCGObj = pOCMDDict->GetElementValue("OCGs"); | 244 CPDF_Object* pOCGObj = pOCMDDict->GetDirectObjectBy("OCGs"); |
| 245 if (!pOCGObj) | 245 if (!pOCGObj) |
| 246 return TRUE; | 246 return TRUE; |
| 247 if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) | 247 if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) |
| 248 return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); | 248 return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); |
| 249 | 249 |
| 250 CPDF_Array* pArray = pOCGObj->AsArray(); | 250 CPDF_Array* pArray = pOCGObj->AsArray(); |
| 251 if (!pArray) | 251 if (!pArray) |
| 252 return TRUE; | 252 return TRUE; |
| 253 | 253 |
| 254 FX_BOOL bState = FALSE; | 254 FX_BOOL bState = FALSE; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 275 } | 275 } |
| 276 CFX_ByteString csType = pOCGDict->GetStringBy("Type", "OCG"); | 276 CFX_ByteString csType = pOCGDict->GetStringBy("Type", "OCG"); |
| 277 if (csType == "OCG") { | 277 if (csType == "OCG") { |
| 278 return GetOCGVisible(pOCGDict); | 278 return GetOCGVisible(pOCGDict); |
| 279 } | 279 } |
| 280 return LoadOCMDState(pOCGDict, FALSE); | 280 return LoadOCMDState(pOCGDict, FALSE); |
| 281 } | 281 } |
| 282 void CPDF_OCContext::ResetOCContext() { | 282 void CPDF_OCContext::ResetOCContext() { |
| 283 m_OCGStates.clear(); | 283 m_OCGStates.clear(); |
| 284 } | 284 } |
| OLD | NEW |