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/include/fpdfdoc/fpdf_doc.h" | 7 #include "core/include/fpdfdoc/fpdf_doc.h" |
8 | 8 |
9 static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object* pObject, | 9 static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object* pObject, |
10 const CPDF_Dictionary* pGroupDict) { | 10 const CPDF_Dictionary* pGroupDict) { |
11 if (!pObject || !pGroupDict) | 11 if (!pObject || !pGroupDict) |
12 return -1; | 12 return -1; |
13 | 13 |
14 if (const CPDF_Array* pArray = pObject->AsArray()) { | 14 if (const CPDF_Array* pArray = pObject->AsArray()) { |
15 FX_DWORD dwCount = pArray->GetCount(); | 15 FX_DWORD dwCount = pArray->GetCount(); |
16 for (FX_DWORD i = 0; i < dwCount; i++) { | 16 for (FX_DWORD i = 0; i < dwCount; i++) { |
17 if (pArray->GetDict(i) == pGroupDict) | 17 if (pArray->GetDict(i) == pGroupDict) |
18 return i; | 18 return i; |
19 } | 19 } |
20 return -1; | 20 return -1; |
21 } | 21 } |
22 return pObject->GetDict() == pGroupDict ? 0 : -1; | 22 return pObject->GetDict() == pGroupDict ? 0 : -1; |
23 } | 23 } |
24 static FX_BOOL FPDFDOC_OCG_HasIntent(const CPDF_Dictionary* pDict, | 24 static FX_BOOL FPDFDOC_OCG_HasIntent(const CPDF_Dictionary* pDict, |
25 const CFX_ByteStringC& csElement, | 25 const CFX_ByteStringC& csElement, |
26 const CFX_ByteStringC& csDef = "") { | 26 const CFX_ByteStringC& csDef = "") { |
27 FXSYS_assert(pDict); | 27 FXSYS_assert(pDict); |
28 CPDF_Object* pIntent = pDict->GetElementValue("Intent"); | 28 CPDF_Object* pIntent = pDict->GetElementValue("Intent"); |
29 if (pIntent == NULL) { | 29 if (!pIntent) { |
30 return csElement == csDef; | 30 return csElement == csDef; |
31 } | 31 } |
32 CFX_ByteString bsIntent; | 32 CFX_ByteString bsIntent; |
33 if (CPDF_Array* pArray = pIntent->AsArray()) { | 33 if (CPDF_Array* pArray = pIntent->AsArray()) { |
34 FX_DWORD dwCount = pArray->GetCount(); | 34 FX_DWORD dwCount = pArray->GetCount(); |
35 for (FX_DWORD i = 0; i < dwCount; i++) { | 35 for (FX_DWORD i = 0; i < dwCount; i++) { |
36 bsIntent = pArray->GetString(i); | 36 bsIntent = pArray->GetString(i); |
37 if (bsIntent == "All" || bsIntent == csElement) | 37 if (bsIntent == "All" || bsIntent == csElement) |
38 return TRUE; | 38 return TRUE; |
39 } | 39 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 m_OCGStates[pOCGDict] = bState; | 183 m_OCGStates[pOCGDict] = bState; |
184 return bState; | 184 return bState; |
185 } | 185 } |
186 | 186 |
187 FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression, | 187 FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression, |
188 FX_BOOL bFromConfig, | 188 FX_BOOL bFromConfig, |
189 int nLevel) { | 189 int nLevel) { |
190 if (nLevel > 32) { | 190 if (nLevel > 32) { |
191 return FALSE; | 191 return FALSE; |
192 } | 192 } |
193 if (pExpression == NULL) { | 193 if (!pExpression) { |
194 return FALSE; | 194 return FALSE; |
195 } | 195 } |
196 int32_t iCount = pExpression->GetCount(); | 196 int32_t iCount = pExpression->GetCount(); |
197 CPDF_Object* pOCGObj; | 197 CPDF_Object* pOCGObj; |
198 CFX_ByteString csOperator = pExpression->GetString(0); | 198 CFX_ByteString csOperator = pExpression->GetString(0); |
199 if (csOperator == "Not") { | 199 if (csOperator == "Not") { |
200 pOCGObj = pExpression->GetElementValue(1); | 200 pOCGObj = pExpression->GetElementValue(1); |
201 if (!pOCGObj) | 201 if (!pOCGObj) |
202 return FALSE; | 202 return FALSE; |
203 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) | 203 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) |
204 return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict)); | 204 return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict)); |
205 if (CPDF_Array* pArray = pOCGObj->AsArray()) | 205 if (CPDF_Array* pArray = pOCGObj->AsArray()) |
206 return !GetOCGVE(pArray, bFromConfig, nLevel + 1); | 206 return !GetOCGVE(pArray, bFromConfig, nLevel + 1); |
207 return FALSE; | 207 return FALSE; |
208 } | 208 } |
209 if (csOperator == "Or" || csOperator == "And") { | 209 if (csOperator == "Or" || csOperator == "And") { |
210 FX_BOOL bValue = FALSE; | 210 FX_BOOL bValue = FALSE; |
211 for (int32_t i = 1; i < iCount; i++) { | 211 for (int32_t i = 1; i < iCount; i++) { |
212 pOCGObj = pExpression->GetElementValue(1); | 212 pOCGObj = pExpression->GetElementValue(1); |
213 if (pOCGObj == NULL) { | 213 if (!pOCGObj) { |
214 continue; | 214 continue; |
215 } | 215 } |
216 FX_BOOL bItem = FALSE; | 216 FX_BOOL bItem = FALSE; |
217 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) | 217 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) |
218 bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); | 218 bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); |
219 else if (CPDF_Array* pArray = pOCGObj->AsArray()) | 219 else if (CPDF_Array* pArray = pOCGObj->AsArray()) |
220 bItem = GetOCGVE(pArray, bFromConfig, nLevel + 1); | 220 bItem = GetOCGVE(pArray, bFromConfig, nLevel + 1); |
221 | 221 |
222 if (i == 1) { | 222 if (i == 1) { |
223 bValue = bItem; | 223 bValue = bItem; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 275 } |
276 CFX_ByteString csType = pOCGDict->GetString("Type", "OCG"); | 276 CFX_ByteString csType = pOCGDict->GetString("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 |