Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Side by Side Diff: core/src/fpdfdoc/doc_ocg.cpp

Issue 1417893003: Add type cast definitions for CPDF_Array. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfdoc/doc_link.cpp ('k') | core/src/fpdfdoc/doc_tagged.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../include/fpdfdoc/fpdf_doc.h"
8 static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object* pObject, 8 static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object* pObject,
9 const CPDF_Dictionary* pGroupDict) { 9 const CPDF_Dictionary* pGroupDict) {
10 if (pObject == NULL || pGroupDict == NULL) { 10 if (!pObject || !pGroupDict)
11 return -1; 11 return -1;
12 } 12
13 int32_t iType = pObject->GetType(); 13 if (const CPDF_Array* pArray = pObject->AsArray()) {
14 if (iType == PDFOBJ_ARRAY) { 14 FX_DWORD dwCount = pArray->GetCount();
15 FX_DWORD dwCount = ((CPDF_Array*)pObject)->GetCount();
16 for (FX_DWORD i = 0; i < dwCount; i++) { 15 for (FX_DWORD i = 0; i < dwCount; i++) {
17 if (((CPDF_Array*)pObject)->GetDict(i) == pGroupDict) { 16 if (pArray->GetDict(i) == pGroupDict)
18 return i; 17 return i;
19 }
20 } 18 }
21 return -1; 19 return -1;
22 } 20 }
23 if (pObject->GetDict() == pGroupDict) { 21 return pObject->GetDict() == pGroupDict ? 0 : -1;
24 return 0;
25 }
26 return -1;
27 } 22 }
28 static FX_BOOL FPDFDOC_OCG_HasIntent( 23 static FX_BOOL FPDFDOC_OCG_HasIntent(
29 const CPDF_Dictionary* pDict, 24 const CPDF_Dictionary* pDict,
30 const CFX_ByteStringC& csElement, 25 const CFX_ByteStringC& csElement,
31 const CFX_ByteStringC& csDef = FX_BSTRC("")) { 26 const CFX_ByteStringC& csDef = FX_BSTRC("")) {
32 FXSYS_assert(pDict != NULL); 27 FXSYS_assert(pDict != NULL);
33 CPDF_Object* pIntent = pDict->GetElementValue(FX_BSTRC("Intent")); 28 CPDF_Object* pIntent = pDict->GetElementValue(FX_BSTRC("Intent"));
34 if (pIntent == NULL) { 29 if (pIntent == NULL) {
35 return csElement == csDef; 30 return csElement == csDef;
36 } 31 }
37 CFX_ByteString bsIntent; 32 CFX_ByteString bsIntent;
38 if (pIntent->GetType() == PDFOBJ_ARRAY) { 33 if (CPDF_Array* pArray = pIntent->AsArray()) {
39 FX_DWORD dwCount = ((CPDF_Array*)pIntent)->GetCount(); 34 FX_DWORD dwCount = pArray->GetCount();
40 for (FX_DWORD i = 0; i < dwCount; i++) { 35 for (FX_DWORD i = 0; i < dwCount; i++) {
41 bsIntent = ((CPDF_Array*)pIntent)->GetString(i); 36 bsIntent = pArray->GetString(i);
42 if (bsIntent == FX_BSTRC("All") || bsIntent == csElement) { 37 if (bsIntent == FX_BSTRC("All") || bsIntent == csElement)
43 return TRUE; 38 return TRUE;
44 }
45 } 39 }
46 return FALSE; 40 return FALSE;
47 } 41 }
48 bsIntent = pIntent->GetString(); 42 bsIntent = pIntent->GetString();
49 return bsIntent == FX_BSTRC("All") || bsIntent == csElement; 43 return bsIntent == FX_BSTRC("All") || bsIntent == csElement;
50 } 44 }
51 static CPDF_Dictionary* FPDFDOC_OCG_GetConfig(CPDF_Document* pDoc, 45 static CPDF_Dictionary* FPDFDOC_OCG_GetConfig(CPDF_Document* pDoc,
52 const CPDF_Dictionary* pOCGDict, 46 const CPDF_Dictionary* pOCGDict,
53 const CFX_ByteStringC& bsState) { 47 const CFX_ByteStringC& bsState) {
54 FXSYS_assert(pDoc && pOCGDict); 48 FXSYS_assert(pDoc && pOCGDict);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return FALSE; 193 return FALSE;
200 } 194 }
201 if (pExpression == NULL) { 195 if (pExpression == NULL) {
202 return FALSE; 196 return FALSE;
203 } 197 }
204 int32_t iCount = pExpression->GetCount(); 198 int32_t iCount = pExpression->GetCount();
205 CPDF_Object* pOCGObj; 199 CPDF_Object* pOCGObj;
206 CFX_ByteString csOperator = pExpression->GetString(0); 200 CFX_ByteString csOperator = pExpression->GetString(0);
207 if (csOperator == FX_BSTRC("Not")) { 201 if (csOperator == FX_BSTRC("Not")) {
208 pOCGObj = pExpression->GetElementValue(1); 202 pOCGObj = pExpression->GetElementValue(1);
209 if (pOCGObj == NULL) { 203 if (!pOCGObj)
210 return FALSE; 204 return FALSE;
211 } 205 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
212 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) {
213 return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict)); 206 return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict));
214 } 207 if (CPDF_Array* pArray = pOCGObj->AsArray())
215 if (pOCGObj->GetType() == PDFOBJ_ARRAY) { 208 return !GetOCGVE(pArray, bFromConfig, nLevel + 1);
216 return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1);
217 }
218 return FALSE; 209 return FALSE;
219 } 210 }
220 if (csOperator == FX_BSTRC("Or") || csOperator == FX_BSTRC("And")) { 211 if (csOperator == FX_BSTRC("Or") || csOperator == FX_BSTRC("And")) {
221 FX_BOOL bValue = FALSE; 212 FX_BOOL bValue = FALSE;
222 for (int32_t i = 1; i < iCount; i++) { 213 for (int32_t i = 1; i < iCount; i++) {
223 pOCGObj = pExpression->GetElementValue(1); 214 pOCGObj = pExpression->GetElementValue(1);
224 if (pOCGObj == NULL) { 215 if (pOCGObj == NULL) {
225 continue; 216 continue;
226 } 217 }
227 FX_BOOL bItem = FALSE; 218 FX_BOOL bItem = FALSE;
228 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) { 219 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
229 bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); 220 bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict);
230 } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) { 221 else if (CPDF_Array* pArray = pOCGObj->AsArray())
231 bItem = GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1); 222 bItem = GetOCGVE(pArray, bFromConfig, nLevel + 1);
232 } 223
233 if (i == 1) { 224 if (i == 1) {
234 bValue = bItem; 225 bValue = bItem;
235 } else { 226 } else {
236 if (csOperator == FX_BSTRC("Or")) { 227 if (csOperator == FX_BSTRC("Or")) {
237 bValue = bValue || bItem; 228 bValue = bValue || bItem;
238 } else { 229 } else {
239 bValue = bValue && bItem; 230 bValue = bValue && bItem;
240 } 231 }
241 } 232 }
242 } 233 }
243 return bValue; 234 return bValue;
244 } 235 }
245 return FALSE; 236 return FALSE;
246 } 237 }
247 FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict, 238 FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict,
248 FX_BOOL bFromConfig) { 239 FX_BOOL bFromConfig) {
249 FXSYS_assert(pOCMDDict != NULL); 240 FXSYS_assert(pOCMDDict != NULL);
250 CPDF_Array* pVE = pOCMDDict->GetArray(FX_BSTRC("VE")); 241 CPDF_Array* pVE = pOCMDDict->GetArray(FX_BSTRC("VE"));
251 if (pVE != NULL) { 242 if (pVE != NULL) {
252 return GetOCGVE(pVE, bFromConfig); 243 return GetOCGVE(pVE, bFromConfig);
253 } 244 }
254 CFX_ByteString csP = pOCMDDict->GetString(FX_BSTRC("P"), FX_BSTRC("AnyOn")); 245 CFX_ByteString csP = pOCMDDict->GetString(FX_BSTRC("P"), FX_BSTRC("AnyOn"));
255 CPDF_Object* pOCGObj = pOCMDDict->GetElementValue(FX_BSTRC("OCGs")); 246 CPDF_Object* pOCGObj = pOCMDDict->GetElementValue(FX_BSTRC("OCGs"));
256 if (pOCGObj == NULL) { 247 if (!pOCGObj)
257 return TRUE; 248 return TRUE;
258 } 249 if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
259 if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) {
260 return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); 250 return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict);
261 } 251
262 if (pOCGObj->GetType() != PDFOBJ_ARRAY) { 252 CPDF_Array* pArray = pOCGObj->AsArray();
253 if (!pArray)
263 return TRUE; 254 return TRUE;
264 } 255
265 FX_BOOL bState = FALSE; 256 FX_BOOL bState = FALSE;
266 if (csP == FX_BSTRC("AllOn") || csP == FX_BSTRC("AllOff")) { 257 if (csP == FX_BSTRC("AllOn") || csP == FX_BSTRC("AllOff")) {
267 bState = TRUE; 258 bState = TRUE;
268 } 259 }
269 int32_t iCount = ((CPDF_Array*)pOCGObj)->GetCount(); 260 int32_t iCount = pArray->GetCount();
270 for (int32_t i = 0; i < iCount; i++) { 261 for (int32_t i = 0; i < iCount; i++) {
271 FX_BOOL bItem = TRUE; 262 FX_BOOL bItem = TRUE;
272 CPDF_Dictionary* pItemDict = ((CPDF_Array*)pOCGObj)->GetDict(i); 263 CPDF_Dictionary* pItemDict = pArray->GetDict(i);
273 if (pItemDict) { 264 if (pItemDict)
274 bItem = bFromConfig ? LoadOCGState(pItemDict) : GetOCGVisible(pItemDict); 265 bItem = bFromConfig ? LoadOCGState(pItemDict) : GetOCGVisible(pItemDict);
275 } 266
276 if (csP == FX_BSTRC("AnyOn") && bItem) { 267 if ((csP == FX_BSTRC("AnyOn") && bItem) ||
268 (csP == FX_BSTRC("AnyOff") && !bItem))
277 return TRUE; 269 return TRUE;
278 } 270 if ((csP == FX_BSTRC("AllOn") && !bItem) ||
279 if (csP == FX_BSTRC("AnyOff") && !bItem) { 271 (csP == FX_BSTRC("AllOff") && bItem))
280 return TRUE;
281 }
282 if (csP == FX_BSTRC("AllOn") && !bItem) {
283 return FALSE; 272 return FALSE;
284 }
285 if (csP == FX_BSTRC("AllOff") && bItem) {
286 return FALSE;
287 }
288 } 273 }
289 return bState; 274 return bState;
290 } 275 }
291 FX_BOOL CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary* pOCGDict) { 276 FX_BOOL CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary* pOCGDict) {
292 if (!pOCGDict) { 277 if (!pOCGDict) {
293 return TRUE; 278 return TRUE;
294 } 279 }
295 CFX_ByteString csType = 280 CFX_ByteString csType =
296 pOCGDict->GetString(FX_BSTRC("Type"), FX_BSTRC("OCG")); 281 pOCGDict->GetString(FX_BSTRC("Type"), FX_BSTRC("OCG"));
297 if (csType == FX_BSTRC("OCG")) { 282 if (csType == FX_BSTRC("OCG")) {
298 return GetOCGVisible(pOCGDict); 283 return GetOCGVisible(pOCGDict);
299 } 284 }
300 return LoadOCMDState(pOCGDict, FALSE); 285 return LoadOCMDState(pOCGDict, FALSE);
301 } 286 }
302 void CPDF_OCContext::ResetOCContext() { 287 void CPDF_OCContext::ResetOCContext() {
303 m_OCGStates.clear(); 288 m_OCGStates.clear();
304 } 289 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_link.cpp ('k') | core/src/fpdfdoc/doc_tagged.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698